MAIN extern int WINAPI _tWinMain HINSTANCE hInstance HINSTANCE hPrevIn

  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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//MAIN
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
{
CSimpleDialog2 *wndMain;
MSG msg;
wndMain = new CSimpleDialog2;
// Create our main window
wndMain->Create(NULL,0);
wndMain->ShowWindow(SW_SHOW);
while ( GetMessage ( &msg, NULL, 0, 0 ) > 0 )
{
if(IsDialogMessage(wndMain->m_hWnd,&msg))
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
}
delete wndMain;
return msg.wParam;
}
//описание классов диалогов
#ifndef MYWINDOW_H_INCLUDED
#define MYWINDOW_H_INCLUDED
template <class T, COLORREF t_crBrushColor>
class CPaintBkgnd
{
public:
CPaintBkgnd() { m_hbrBkgnd = CreateSolidBrush(t_crBrushColor); }
~CPaintBkgnd() { DeleteObject ( m_hbrBkgnd ); }
BEGIN_MSG_MAP(CPaintBkgnd)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
END_MSG_MAP()
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
HDC dc = (HDC) wParam;
RECT rcClient;
pT->GetClientRect ( &rcClient );
FillRect ( dc, &rcClient, m_hbrBkgnd );
return 1; // we painted the background
}
protected:
HBRUSH m_hbrBkgnd;
};
//secondary window
class CSimpleDialog3 : public CDialogImpl<CSimpleDialog3>//,
// public CPaintBkgnd<CSimpleDialog3, RGB(10,154,245)>
{
private:
typedef CPaintBkgnd<CSimpleDialog3, RGB(10,154,245)> CPaintBkgndBase;
public:
enum { IDD = ID_OTHERDIA };
BEGIN_MSG_MAP(CSimpleDialog3)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
COMMAND_ID_HANDLER(IDMYOK, OnOKPressed)
// COMMAND_ID_HANDLER(IDC_ABOUT, OnAbout)
// CHAIN_MSG_MAP(CPaintBkgndBase)
END_MSG_MAP()
LRESULT OnOKPressed(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(IDMYOK);
return 0;
}
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// DestroyWindow();
EndDialog(IDCANCEL);
return 0;
}
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
return 0;
}
};
//main window
class CSimpleDialog2 : public CDialogImpl<CSimpleDialog2>,
public CPaintBkgnd<CSimpleDialog2, RGB(10,154,245)>
{
private:
typedef CPaintBkgnd<CSimpleDialog2, RGB(10,154,245)> CPaintBkgndBase;
public:
enum { IDD = IDD_DIA1 };
// DECLARE_WND_CLASS(_T("My Window Class"))
BEGIN_MSG_MAP(CSimpleDialog2)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
COMMAND_ID_HANDLER(IDOK55, OnMyOK)
COMMAND_ID_HANDLER(IDC_SHOWDLG,OnShowOtherDialog)
// COMMAND_ID_HANDLER(IDC_ABOUT, OnAbout)
CHAIN_MSG_MAP(CPaintBkgndBase)
END_MSG_MAP()
LRESULT OnShowOtherDialog(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CSimpleDialog3 wndOther;
MSG msg;
//wndOther = new CSimpleDialog3;
if (IDMYOK == wndOther.DoModal())
{
::MessageBox(NULL,_T("quit with OK"), _T("quit with OK"),0);
}
else
{
::MessageBox(NULL,_T("quit with NOT OK"), _T("quit with NOT OK"),0);
}
return 0;
}
LRESULT OnMyOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
//::MessageBox(NULL,_T("OK pressed"),_T("OK"),0);
//EndDialog(IDOK55);
//wndOther->DestroyWindow();
return 0;
}
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
DestroyWindow();
return 0;
}
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
return 0;
}
LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
//CAboutDlg dlg;
// dlg.DoModal();
return 0;
}
};
#endif // ndef MYWINDOW_H_INCLUDED