1515// along with this program; if not, write to the Free Software
1616// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1717
18+ #include < stdio.h>
1819#include " StaticDialog.h"
1920
2021void StaticDialog::goToCenter ()
2122{
22- RECT rc;
23- ::GetClientRect (_hParent, &rc);
24- POINT center;
25- center.x = rc.left + (rc.right - rc.left )/2 ;
26- center.y = rc.top + (rc.bottom - rc.top )/2 ;
27- ::ClientToScreen (_hParent, ¢er);
23+ RECT rc;
24+ ::GetClientRect (_hParent, &rc);
25+ POINT center;
26+ center.x = rc.left + (rc.right - rc.left )/2 ;
27+ center.y = rc.top + (rc.bottom - rc.top )/2 ;
28+ ::ClientToScreen (_hParent, ¢er);
2829
2930 int x = center.x - (_rc.right - _rc.left )/2 ;
3031 int y = center.y - (_rc.bottom - _rc.top )/2 ;
@@ -36,17 +37,25 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat
3637{
3738 // Get Dlg Template resource
3839 HRSRC hDialogRC = ::FindResource (_hInst, MAKEINTRESOURCE (dialogID), RT_DIALOG);
40+ if (!hDialogRC)
41+ return NULL ;
42+
3943 HGLOBAL hDlgTemplate = ::LoadResource (_hInst, hDialogRC);
40- DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE *)::LockResource (hDlgTemplate);
41-
44+ if (!hDlgTemplate)
45+ return NULL ;
46+
47+ DLGTEMPLATE *pDlgTemplate = reinterpret_cast <DLGTEMPLATE *>(::LockResource (hDlgTemplate));
48+ if (!pDlgTemplate)
49+ return NULL ;
50+
4251 // Duplicate Dlg Template resource
4352 unsigned long sizeDlg = ::SizeofResource (_hInst, hDialogRC);
4453 HGLOBAL hMyDlgTemplate = ::GlobalAlloc (GPTR, sizeDlg);
45- *ppMyDlgTemplate = ( DLGTEMPLATE *) ::GlobalLock (hMyDlgTemplate);
54+ *ppMyDlgTemplate = reinterpret_cast < DLGTEMPLATE *>( ::GlobalLock (hMyDlgTemplate) );
4655
4756 ::memcpy (*ppMyDlgTemplate, pDlgTemplate, sizeDlg);
48-
49- DLGTEMPLATEEX *pMyDlgTemplateEx = ( DLGTEMPLATEEX *) *ppMyDlgTemplate;
57+
58+ DLGTEMPLATEEX *pMyDlgTemplateEx = reinterpret_cast < DLGTEMPLATEEX *>( *ppMyDlgTemplate) ;
5059 if (pMyDlgTemplateEx->signature == 0xFFFF )
5160 pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL;
5261 else
@@ -61,38 +70,43 @@ void StaticDialog::create(int dialogID, bool isRTL)
6170 {
6271 DLGTEMPLATE *pMyDlgTemplate = NULL ;
6372 HGLOBAL hMyDlgTemplate = makeRTLResource (dialogID, &pMyDlgTemplate);
64- _hSelf = ::CreateDialogIndirectParam (_hInst, pMyDlgTemplate, _hParent, (DLGPROC) dlgProc, ( LPARAM) this );
73+ _hSelf = ::CreateDialogIndirectParam (_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast < LPARAM>( this ) );
6574 ::GlobalFree (hMyDlgTemplate);
6675 }
6776 else
68- _hSelf = ::CreateDialogParam (_hInst, MAKEINTRESOURCE (dialogID), _hParent, (DLGPROC) dlgProc, ( LPARAM) this );
77+ _hSelf = ::CreateDialogParam (_hInst, MAKEINTRESOURCE (dialogID), _hParent, dlgProc, reinterpret_cast < LPARAM>( this ) );
6978
7079 if (!_hSelf)
7180 {
81+ DWORD err = ::GetLastError ();
82+ char errMsg[256 ];
83+ sprintf (errMsg, " CreateDialogParam() return NULL.\r GetLastError() == %u" , err);
84+ ::MessageBoxA (NULL , errMsg, " In StaticDialog::create()" , MB_OK);
7285 return ;
7386 }
7487
75- ::SendMessage (_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);
88+ // if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent
89+ ::SendMessage (_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast <WPARAM>(_hSelf));
7690}
7791
78- BOOL CALLBACK StaticDialog::dlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
92+ INT_PTR CALLBACK StaticDialog::dlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7993{
80- switch (message)
94+ switch (message)
8195 {
82- case WM_INITDIALOG :
96+ case WM_INITDIALOG:
8397 {
84- StaticDialog *pStaticDlg = ( StaticDialog *) (lParam);
98+ StaticDialog *pStaticDlg = reinterpret_cast < StaticDialog *> (lParam);
8599 pStaticDlg->_hSelf = hwnd;
86- ::SetWindowLongPtr (hwnd, GWL_USERDATA, ( long ) lParam);
100+ ::SetWindowLongPtr (hwnd, GWLP_USERDATA, static_cast <LONG_PTR>( lParam) );
87101 ::GetWindowRect (hwnd, &(pStaticDlg->_rc));
88- pStaticDlg->run_dlgProc (message, wParam, lParam);
89-
102+ pStaticDlg->run_dlgProc (message, wParam, lParam);
103+
90104 return TRUE ;
91105 }
92106
93- default :
107+ default :
94108 {
95- StaticDialog *pStaticDlg = ( StaticDialog *) (::GetWindowLongPtr (hwnd, GWL_USERDATA ));
109+ StaticDialog *pStaticDlg = reinterpret_cast < StaticDialog *> (::GetWindowLongPtr (hwnd, GWLP_USERDATA ));
96110 if (!pStaticDlg)
97111 return FALSE ;
98112 return pStaticDlg->run_dlgProc (message, wParam, lParam);
@@ -102,34 +116,40 @@ BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPAR
102116
103117void StaticDialog::alignWith (HWND handle, HWND handle2Align, PosAlign pos, POINT & point)
104118{
105- RECT rc, rc2;
106- ::GetWindowRect (handle, &rc);
107-
108- point.x = rc.left ;
109- point.y = rc.top ;
110-
111- switch (pos)
112- {
113- case ALIGNPOS_LEFT :
114- ::GetWindowRect (handle2Align, &rc2);
115- point.x -= rc2.right - rc2.left ;
116- break ;
117-
118- case ALIGNPOS_RIGHT :
119- ::GetWindowRect (handle, &rc2);
120- point.x += rc2.right - rc2.left ;
121- break ;
122-
123- case ALIGNPOS_TOP :
124- ::GetWindowRect (handle2Align, &rc2);
125- point.y -= rc2.bottom - rc2.top ;
126- break ;
127-
128- default : // ALIGNPOS_BOTTOM
129- ::GetWindowRect (handle, &rc2);
130- point.y += rc2.bottom - rc2.top ;
131- break ;
132- }
133-
134- ::ScreenToClient (_hSelf, &point);
119+ RECT rc, rc2;
120+ ::GetWindowRect (handle, &rc);
121+
122+ point.x = rc.left ;
123+ point.y = rc.top ;
124+
125+ switch (pos)
126+ {
127+ case PosAlign::left:
128+ {
129+ ::GetWindowRect (handle2Align, &rc2);
130+ point.x -= rc2.right - rc2.left ;
131+ break ;
132+ }
133+ case PosAlign::right:
134+ {
135+ ::GetWindowRect (handle, &rc2);
136+ point.x += rc2.right - rc2.left ;
137+ break ;
138+ }
139+ case PosAlign::top:
140+ {
141+ ::GetWindowRect (handle2Align, &rc2);
142+ point.y -= rc2.bottom - rc2.top ;
143+ break ;
144+ }
145+ case PosAlign::bottom:
146+ {
147+ ::GetWindowRect (handle, &rc2);
148+ point.y += rc2.bottom - rc2.top ;
149+ break ;
150+ }
151+ }
152+
153+ ::ScreenToClient (_hSelf, &point);
135154}
155+
0 commit comments