Win32 SDK(二)创建对话框模板的窗口程序

 

#include <windows.h>

#include "resource.h"

 

//回调函数声明

INT_PTR CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

 

 

//主函数WinMain()

int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,

    _In_ LPSTR lpCmdLine, _In_ int nShowCmd)

{

    //创建以资源模板中的对话框

    HWND hWnd = ::CreateDialog(

         hInstance,                         //实例句柄

         MAKEINTRESOURCE(IDD_DIALOG1),  //对话框模板ID号

         NULL,                              //父窗口句柄

         DialogProc                         //消息回调函数

    );

   

    if (!hWnd)

         return 1;

 

    //显示,更新窗口

    ShowWindow(hWnd, SW_SHOW);

    UpdateWindow(hWnd);

 

    //消息循环

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0))

    {

         TranslateMessage(&msg);

         DispatchMessage(&msg);

    }

 

 

    return 0;

}

 

INT_PTR CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

    switch (uMsg)

    {

         case WM_CLOSE:            //关闭窗口消息

             DestroyWindow(hWnd);

             break;

 

         case WM_DESTROY:      //销毁窗口消息

             PostQuitMessage(0);

             break;

         case WM_COMMAND:      //命令消息

         {

             switch (LOWORD(wParam))   //wParam低字节为控件ID

             {

                  case IDOK:

                      break;

                  case IDCANCEL:

                      break;

             }

             break;

         }

         default:

             break;

    }

   

    return 0;

}

 

编译运行如下:

 

 

posted @ 2021-02-08 23:12  初吻给了烟灬  阅读(248)  评论(0)    收藏  举报