Win32_Window(day02)

2021-05-03 18:26

阅读:677

标签:sgi   callback   mds   main   关闭   code   while   cal   line   

#include //窗口处理函数 
HINSTANCE g_hIns;

LRESULT CALLBACK WndProc(HWND hWnd,UINT msgID,
    WPARAM wParam,LPARAM IParam)
{
    switch (msgID)
    {
    case WM_DESTROY:
        PostQuitMessage(0);//消息窗口关闭按钮点击后,退出程序
        break;
    }
    return DefWindowProc(hWnd,msgID,wParam,IParam);
    //给各种消息做默认处理
}

//注册窗口
void Register(LPSTR IpClassName,WNDPROC wndProc)
{
    WNDCLASSEX wce = {0};
    wce.cbSize = sizeof(wce);
    wce.cbClsExtra = 0;
    wce.cbWndExtra = 0;
    wce.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wce.hCursor = NULL;
    wce.hIcon = NULL;
    wce.hIconSm = NULL;
    wce.hInstance = g_hIns;
    wce.lpfnWndProc = wndProc;
    wce.lpszClassName = IpClassName;
    wce.lpszMenuName = NULL ;
    wce.style = CS_HREDRAW|CS_VREDRAW;
    RegisterClassEx(&wce);
}

//创建窗口
HWND CreateMain(LPSTR IpClassName,LPSTR IpWndName)
{
    HWND hWnd = CreateWindowEx(0,IpClassName,IpWndName,WS_OVERLAPPEDWINDOW,
        100,100,700,500,NULL,NULL,g_hIns,NULL);
    return hWnd;
}

//显示窗口
void Display(HWND hWnd)
{
    ShowWindow(hWnd,SW_SHOW);
    UpdateWindow(hWnd); //重绘窗口
}

//消息循环
void  Message()
{
    MSG nMsg = {0};
    while(GetMessage(&nMsg,NULL,0,0))
    {
        TranslateMessage(&nMsg);//翻译消息
        DispatchMessage(&nMsg);//派送消息
    }
}

int CALLBACK WinMain(HINSTANCE hIns,HINSTANCE hPreIns,LPSTR IpCmdline,int nCmdShow)
{
    g_hIns = hIns;
    //注册窗口类
    Register("Main",WndProc);
    //创建窗口
    HWND hWnd = CreateMain("Main","Window");
    //显示窗口
    Display(hWnd);
    //消息循环
    Message();
    return 0;
}

 

Win32_Window(day02)

标签:sgi   callback   mds   main   关闭   code   while   cal   line   

原文地址:http://www.cnblogs.com/Kernel001/p/7744819.html


评论


亲,登录后才可以留言!