標籤:
建立基於對話方塊的Win32應用程式(一) —— 建立表單
1、建立一個Visual C++的Empty Project。
2、在Solution Explorer中右鍵Add New Item,添加 .cpp 檔案,並提供Win32應用程式的進入點函數。
3、在Solution Explorer或 Resources View 中右鍵Add Resource,選擇Dialog。並在修改相關內容。
4、切換到 .cpp檔案中,建立回呼函數(Dlg_Proc),並在進入點函數中調用DialogBoxParam。
1 #include <Windows.h> 2 #include <tchar.h> 3 #include "Resource.h" 4 5 INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 6 switch (uMsg) 7 { 8 case WM_CLOSE: 9 EndDialog(hwnd, 0);10 break;11 }12 13 return(FALSE);14 }15 16 int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {17 DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_DIALOG),18 NULL, Dlg_Proc, _ttoi(pszCmdLine));19 return(0);20 }Win32WindowsApplication.cpp
5、此時按下F5 Start Debugging,可以看到剛才建立的對話方塊。
————————————————
本文為本人原創,轉載請註明出處。
Creating Dialogbased Win32 Application (1) / 建立基於對話方塊的Win32應用程式(一)建立表單 / Win32, VC++, Windows