首页
学习
活动
专区
圈层
工具
发布

C编程HWND
EN

Stack Overflow用户
提问于 2017-06-11 06:05:40
回答 0查看 456关注 0票数 0

当我编译我的代码时,应该打开一个窗口,但它没有。我已经创建了一个类、HWND和应用程序处理程序;仍然一无所获。

我是个新手,很抱歉这个问题。

应用程序运行正常,没有错误,但窗口似乎没有出现。

代码语言:javascript
复制
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>


LRESULT CALLBACK myCallBack(HWND regularWnd, UINT message, WPARAM wparam, LPARAM lparam){
    switch(message){
    case 0x0201:
    printf("left Click");
    MessageBox(regularWnd, "Left Click", "event handler", MB_OK);
    break;
    case WM_CLOSE: 
    DestroyWindow(regularWnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    DefWindowProc(regularWnd, message, wparam, lparam);
    break;
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE newHInstance, HINSTANCE prevHINSTANCE, LPSTR lpCmdLine, int cmdShow){

    WNDCLASSEX regularWndClass;

    regularWndClass.cbSize = sizeof(WNDCLASSEX);
    regularWndClass.cbWndExtra = 0;
    regularWndClass.cbClsExtra = 0;
    regularWndClass.style = 0;
    regularWndClass.lpszClassName = "regularWindowClass";
    regularWndClass.lpszMenuName = NULL;
    regularWndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
    regularWndClass.lpfnWndProc = myCallBack;
    regularWndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    regularWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    regularWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    regularWndClass.hInstance = newHInstance;

    if(!RegisterClassEx(&regularWndClass) < 0){
        perror("Error Wnd class: ");
        exit(0);
    }

    HWND regularWnd;

    regularWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "regularWindowClass", "The title of my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, NULL, NULL, newHInstance, NULL);

    if(regularWnd < 0){
        perror("window error : ");
        exit(0);
    }

    ShowWindow(regularWnd, cmdShow);
    UpdateWindow(regularWnd);

    MSG message;
    while(GetMessage(&message, NULL, 0, 0) > 0){
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
    return message.wParam;
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44478514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档