首页 > 代码库 > 9th 学习博客:使用Codebloks实现C++的图形化界面

9th 学习博客:使用Codebloks实现C++的图形化界面

main.cpp

 1 #include <windows.h>
 2 #include <commctrl.h>
 3 #include <stdio.h>
 4 #include "resource.h"
 5 
 6 HINSTANCE hInst;
 7 HWND button1;
 8 
 9 BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
10 {
11     switch(uMsg)
12     {
13     case WM_INITDIALOG:
14     {
15 
16     }
17     return TRUE;
18 
19     case WM_CLOSE:
20     {
21         if(MessageBox(hwndDlg,"Close the dialog?","Prompt",MB_YESNO) == IDYES)
22         {
23             EndDialog(hwndDlg, 0);
24         }
25     }
26     return TRUE;
27 
28     case WM_COMMAND:
29     {
30         switch(LOWORD(wParam))
31         {
32         case IDC_BUTTON1:
33             printf("the button1 is clicked!\n");
34             SetWindowText(button1,TEXT("my button"));
35             break;
36         }
37     }
38     return TRUE;
39     }
40     return FALSE;
41 }
42 
43 
44 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
45 {
46     hInst=hInstance;
47     InitCommonControls();
48     return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
49 }

resource.h

1 #ifndef IDC_STATIC
2 #define IDC_STATIC (-1)
3 #endif
4 
5 #define DLG_MAIN                                100
6 #define IDC_BUTTON1                             40000

执行效果图

技术分享

 

9th 学习博客:使用Codebloks实现C++的图形化界面