码迷,mamicode.com
首页 > Windows程序 > 详细

Win32_Window(day02)

时间:2017-10-27 19:52:19      阅读:231      评论:0      收藏:0      [点我收藏+]

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

#include <Windows.h>
//窗口处理函数 
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!