1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include "resource.h"
#include "tlib.h"
/*----------------------------------------------------------------------
| TMainWin
+---------------------------------------------------------------------*/
class TMainWin : public TDlg {
public:
TMainWin(TWin *_parent = NULL);
virtual ~TMainWin() override;
TMainWin(const TMainWin &) = delete;
TMainWin &operator=(const TMainWin &) = delete;
virtual BOOL EvCommand(WORD wNotifyCode, WORD wID,
LPARAM hwndCtl) override final;
virtual BOOL EvCreate(LPARAM lParam) override final;
virtual void Destroy(void) override final;
virtual BOOL EvClose(void) override final;
private:
HWND btn1Wnd;
HWND btn2Wnd;
HWND btn3Wnd;
};
TMainWin::TMainWin(TWin *_parent)
: TDlg(IDD_DIALOG1, _parent) {
hAccel = ::LoadAccelerators(TApp::GetInstance(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
}
TMainWin::~TMainWin() {
}
BOOL TMainWin::EvCreate(LPARAM lParam) {
btn1Wnd = GetDlgItem(IDM_OK);
btn2Wnd = GetDlgItem(IDM_CANCEL);
btn3Wnd = GetDlgItem(IDM_EXIT);
return TRUE;
}
BOOL TMainWin::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) {
int wmId = LOWORD(wID);
switch (wmId) {
case IDM_OK:
::MessageBox(NULL, "你按下了确认键", "提示", MB_OK);
break;
case IDM_CANCEL:
::MessageBox(NULL, "你按下了取消键", "提示", MB_OK);
break;
case IDM_EXIT:
::MessageBox(NULL, "关闭界面", "提示", MB_OK);
DestroyWindow(hWnd);
break;
default:
return FALSE;
}
return TRUE;
}
void TMainWin::Destroy(void) { PostQuitMessage(0); }
BOOL TMainWin::EvClose(void) {
EndDialog(0);
PostQuitMessage(0);
return TRUE;
}
/*----------------------------------------------------------------------
| SimpleUIApp
+---------------------------------------------------------------------*/
class SimpleUIApp : public TApp {
public:
explicit SimpleUIApp(HINSTANCE _hI);
virtual ~SimpleUIApp() override;
SimpleUIApp(const SimpleUIApp &) = delete;
SimpleUIApp &operator=(const SimpleUIApp &) = delete;
virtual void InitWindow(void) override final;
};
SimpleUIApp::SimpleUIApp(HINSTANCE _hI)
: TApp(_hI) {
}
SimpleUIApp::~SimpleUIApp() {
}
void SimpleUIApp::InitWindow(void) {
mainWnd = new TMainWin();
mainWnd->Create();
mainWnd->Show();
}
auto main(int argc, char **argv) -> int {
HINSTANCE hInstance = GetModuleHandle(NULL);
SimpleUIApp app(hInstance);
return app.Run();;
}
|