Windows应用程序基本结构

来源:互联网 发布:c 从入门到精通 源码 编辑:程序博客网 时间:2024/05/17 23:40

源程序组成结构

WinMain函数

  • 窗口类的定义
//----WinMain函数,是所有Windows窗口的入口---int WinMain(    HINSTANCE hThisInst,    HINSTANCE hPrevInst,    LPSTR     lpszCmdLine,    INT       nCmdShow);
  • 窗口类的注册
//---以下进行窗口类的注册---WNDCLASSEX wcex;if(!RegisterClassEx(&wcex)){    return FALSE;}
  • 窗口创建
//----以下创建窗口----CreateWindow(    LPCTSTR   lpszClassName,    LPCTSTR   lpszTitle,    DWORD     dwStyle,    int       x,    int       y,    int       nWidth,    int       nHeight,    HWND      hwndParent,    HMENU     hMenu,    HINSTANCE hInstance,    LPVOID    lpParam);
  • 窗口显示
//---显示窗口---BOOL ShowWindow(    HWND hwnd,    int  nCmdShow);//---更新窗口---UpdateWindow(HWND hwnd);
  • 消息循环
//---消息循环写法---MSG msg;while(GetMessage(&msg,NULL,0,0)){    TranslateMessage(&msg);   //将虚拟码翻译为字符消息    DispatchMessage(&msg);    //传递消息到指定的窗口函数}

窗口函数

窗口函数的一般形式如下:

LRESULT CALLBACK WndProc(HWND   hwnd,  UINT   message,                         WPARAM wParam,LPARAM lParam){    switch(message)    {        case ...:        .        .        .        break;        case WM_DESTROY:        PostQuitMessage(0);        default:        return DefWindowProc(hwnd,message,wParam,lParam);    }}
0 0
原创粉丝点击