Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

729 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1994 - 1998
  3. All rights reserved.
  4. Module Name:
  5. GenWin.cxx
  6. Abstract:
  7. Generic window handler
  8. Author:
  9. Albert Ting (AlbertT) 21-May-1994
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. /********************************************************************
  15. Generic window
  16. ********************************************************************/
  17. MGenericWin::
  18. MGenericWin(
  19. VOID
  20. )
  21. {
  22. }
  23. MGenericWin::
  24. ~MGenericWin(
  25. VOID
  26. )
  27. {
  28. }
  29. LRESULT
  30. MGenericWin::
  31. nHandleMessage(
  32. IN UINT uMsg,
  33. IN WPARAM wParam,
  34. IN LPARAM lParam
  35. )
  36. /*++
  37. Routine Description:
  38. Handles wndproc processing before the dlg is setup, and after
  39. it has been torn down.
  40. Arguments:
  41. Standard window parameters.
  42. Return Value:
  43. LResult
  44. --*/
  45. {
  46. switch( uMsg ){
  47. case WM_DESTROY:
  48. break;
  49. default:
  50. return DefWindowProc( hwnd(), uMsg, wParam, lParam );
  51. }
  52. return 0;
  53. }
  54. LPARAM APIENTRY
  55. MGenericWin::
  56. SetupWndProc(
  57. IN HWND hwnd,
  58. IN UINT uMsg,
  59. IN WPARAM wParam,
  60. IN LPARAM lParam
  61. )
  62. /*++
  63. Routine Description:
  64. Setup the wndproc and initialize GWL_USERDATA.
  65. Arguments:
  66. Standard wndproc parms.
  67. Return Value:
  68. --*/
  69. {
  70. MGenericWin* pGenericWin;
  71. if( WM_NCCREATE == uMsg ){
  72. pGenericWin = (MGenericWin*)((LPCREATESTRUCT)lParam)->lpCreateParams;
  73. pGenericWin->_hwnd = hwnd;
  74. SetWindowLongPtr( hwnd,
  75. GWLP_USERDATA,
  76. (LONG_PTR)pGenericWin );
  77. SetWindowLongPtr( hwnd,
  78. GWLP_WNDPROC,
  79. (LONG_PTR)&MGenericWin::ThunkWndProc );
  80. return pGenericWin->nHandleMessage( uMsg,
  81. wParam,
  82. lParam );
  83. }
  84. return DefWindowProc( hwnd, uMsg, wParam, lParam );
  85. }
  86. LPARAM APIENTRY
  87. MGenericWin::
  88. ThunkWndProc(
  89. HWND hwnd,
  90. UINT uMsg,
  91. WPARAM wParam,
  92. LPARAM lParam
  93. )
  94. /*++
  95. Routine Description:
  96. Generic thunk from wndproc style parm passing to object passing.
  97. Arguments:
  98. Standard wndproc parms.
  99. Return Value:
  100. --*/
  101. {
  102. MGenericWin* pGenericWin;
  103. pGenericWin = (MGenericWin*)GetWindowLongPtr( hwnd, GWLP_USERDATA );
  104. if( WM_NCDESTROY == uMsg ){
  105. LRESULT lResult = pGenericWin->nHandleMessage( uMsg,
  106. wParam,
  107. lParam );
  108. SetWindowLongPtr( hwnd, GWLP_USERDATA, 0 );
  109. SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)&MGenericWin::SetupWndProc );
  110. return lResult;
  111. }
  112. SPLASSERT( pGenericWin );
  113. return pGenericWin->nHandleMessage( uMsg,
  114. wParam,
  115. lParam );
  116. }
  117. BOOL
  118. MGenericWin::
  119. bSetText(
  120. LPCTSTR pszTitle
  121. )
  122. {
  123. return SetWindowText( _hwnd, pszTitle );
  124. }
  125. VOID
  126. MGenericWin::
  127. vForceCleanup(
  128. VOID
  129. )
  130. {
  131. SetWindowLongPtr( _hwnd, GWLP_USERDATA, 0L );
  132. }
  133. /********************************************************************
  134. Property Sheet procs
  135. ********************************************************************/
  136. MGenericProp::
  137. MGenericProp(
  138. VOID
  139. )
  140. {
  141. }
  142. MGenericProp::
  143. ~MGenericProp(
  144. VOID
  145. )
  146. {
  147. }
  148. BOOL
  149. MGenericProp::
  150. bHandleMessage(
  151. IN UINT uMsg,
  152. IN WPARAM wParam,
  153. IN LPARAM lParam
  154. )
  155. /*++
  156. Routine Description:
  157. Handles Propproc processing before the window is setup and after
  158. it is torn down.
  159. Arguments:
  160. Standard window parameters.
  161. Return Value:
  162. TRUE/FALSE
  163. --*/
  164. {
  165. UNREFERENCED_PARAMETER( uMsg );
  166. UNREFERENCED_PARAMETER( wParam );
  167. UNREFERENCED_PARAMETER( lParam );
  168. return FALSE;
  169. }
  170. BOOL
  171. MGenericProp::
  172. bCreate(
  173. VOID
  174. )
  175. /*++
  176. Routine Description:
  177. This function specifies an application-defined callback function that
  178. a property sheet calls when a page is created and when it is about to
  179. be destroyed. An application can use this function to perform
  180. initialization and cleanup operations for the page.
  181. Called when a PSPCB_CREATE message is sent.
  182. Arguments:
  183. None.
  184. Return Value:
  185. A page is being created. Return nonzero to allow the page to
  186. be created or zero to prevent it.
  187. --*/
  188. {
  189. return TRUE;
  190. }
  191. VOID
  192. MGenericProp::
  193. vDestroy(
  194. VOID
  195. )
  196. /*++
  197. Routine Description:
  198. This function specifies an application-defined callback function that
  199. a property sheet calls when a page is created and when it is about to
  200. be destroyed. An application can use this function to perform
  201. initialization and cleanup operations for the page.
  202. Called when a PSPCB_RELEASE message is sent.
  203. Arguments:
  204. None.
  205. Return Value:
  206. A page is being destroyed. The return value is ignored.
  207. --*/
  208. {
  209. }
  210. INT_PTR APIENTRY
  211. MGenericProp::
  212. SetupDlgProc(
  213. IN HWND hDlg,
  214. IN UINT uMsg,
  215. IN WPARAM wParam,
  216. IN LPARAM lParam
  217. )
  218. /*++
  219. Routine Description:
  220. Setup the wndproc and initialize GWL_USERDATA.
  221. Arguments:
  222. Standard wndproc parms.
  223. Return Value:
  224. History:
  225. Lazar Ivanov (LazarI) - Aug-2000 (redesign)
  226. --*/
  227. {
  228. BOOL bRet = FALSE;
  229. MGenericProp* pThis = NULL;
  230. if( WM_INITDIALOG == uMsg )
  231. {
  232. pThis = reinterpret_cast<MGenericProp*>(reinterpret_cast<LPPROPSHEETPAGE>(lParam)->lParam);
  233. if( pThis )
  234. {
  235. pThis->_hDlg = hDlg;
  236. SetWindowLongPtr(hDlg, DWLP_USER, reinterpret_cast<LONG_PTR>(pThis));
  237. bRet = pThis->bHandleMessage(uMsg, wParam, lParam);
  238. }
  239. }
  240. else
  241. {
  242. pThis = reinterpret_cast<MGenericProp*>(GetWindowLongPtr(hDlg, DWLP_USER));
  243. if( pThis )
  244. {
  245. bRet = pThis->bHandleMessage(uMsg, wParam, lParam);
  246. if( WM_DESTROY == uMsg )
  247. {
  248. // our window is about to go away, so we need to cleanup DWLP_USER here
  249. SetWindowLongPtr(hDlg, DWLP_USER, 0);
  250. }
  251. }
  252. }
  253. return bRet;
  254. }
  255. UINT CALLBACK
  256. MGenericProp::
  257. CallbackProc(
  258. HWND hDlg,
  259. UINT uMsg,
  260. LPPROPSHEETPAGE ppsp
  261. )
  262. /*++
  263. Routine Description:
  264. This function specifies an application-defined callback function that
  265. a property sheet calls when a page is created and when it is about to
  266. be destroyed. An application can use this function to perform
  267. initialization and cleanup operations for the page.
  268. PSPCB_CREATE - A page is being created. Return nonzero to allow
  269. the page to be created or zero to prevent it.
  270. PSPCB_RELEASE - A page is being destroyed. The return value is ignored.
  271. Arguments:
  272. None.
  273. Return Value:
  274. A page is being destroyed. The return value is ignored.
  275. --*/
  276. {
  277. BOOL bStatus;
  278. MGenericProp* pGenericProp;
  279. pGenericProp = (MGenericProp*)ppsp->lParam;
  280. SPLASSERT( pGenericProp );
  281. switch( uMsg ){
  282. case PSPCB_CREATE:
  283. bStatus = pGenericProp->bCreate();
  284. break;
  285. case PSPCB_RELEASE:
  286. pGenericProp->vDestroy();
  287. bStatus = FALSE;
  288. break;
  289. default:
  290. bStatus = FALSE;
  291. }
  292. return bStatus;
  293. }
  294. BOOL
  295. MGenericProp::
  296. bSetText(
  297. LPCTSTR pszTitle
  298. )
  299. {
  300. return SetWindowText( _hDlg, pszTitle );
  301. }
  302. VOID
  303. MGenericProp::
  304. vForceCleanup(
  305. VOID
  306. )
  307. {
  308. SetWindowLongPtr( _hDlg, DWLP_USER, 0L );
  309. }
  310. VOID
  311. MGenericProp::
  312. vSetDlgMsgResult(
  313. LONG_PTR lResult
  314. )
  315. {
  316. SetWindowLongPtr( _hDlg, DWLP_MSGRESULT, (LPARAM)lResult );
  317. }
  318. VOID
  319. MGenericProp::
  320. vSetParentDlgMsgResult(
  321. LRESULT lResult
  322. )
  323. {
  324. SetWindowLongPtr( GetParent( _hDlg ), DWLP_MSGRESULT, (LPARAM)lResult );
  325. }
  326. /********************************************************************
  327. Dialog procs
  328. ********************************************************************/
  329. MGenericDialog::
  330. MGenericDialog(
  331. VOID
  332. )
  333. {
  334. }
  335. MGenericDialog::
  336. ~MGenericDialog(
  337. VOID
  338. )
  339. {
  340. }
  341. BOOL
  342. MGenericDialog::
  343. bHandleMessage(
  344. IN UINT uMsg,
  345. IN WPARAM wParam,
  346. IN LPARAM lParam
  347. )
  348. /*++
  349. Routine Description:
  350. Handles dialog proc processing before the window is setup and after
  351. it is torn down.
  352. Arguments:
  353. Standard window parameters.
  354. Return Value:
  355. TRUE/FALSE
  356. --*/
  357. {
  358. UNREFERENCED_PARAMETER( uMsg );
  359. UNREFERENCED_PARAMETER( wParam );
  360. UNREFERENCED_PARAMETER( lParam );
  361. return FALSE;
  362. }
  363. INT_PTR APIENTRY
  364. MGenericDialog::
  365. SetupDlgProc(
  366. IN HWND hDlg,
  367. IN UINT uMsg,
  368. IN WPARAM wParam,
  369. IN LPARAM lParam
  370. )
  371. /*++
  372. Routine Description:
  373. Setup the wndproc and initialize GWL_USERDATA.
  374. Arguments:
  375. Standard wndproc parms.
  376. Return Value:
  377. History:
  378. Lazar Ivanov (LazarI) - Aug-2000 (redesign)
  379. --*/
  380. {
  381. BOOL bRet = FALSE;
  382. MGenericDialog *pThis = NULL;
  383. if( WM_INITDIALOG == uMsg )
  384. {
  385. pThis = reinterpret_cast<MGenericDialog*>(lParam);
  386. if( pThis )
  387. {
  388. pThis->_hDlg = hDlg;
  389. SetWindowLongPtr(hDlg, DWLP_USER, reinterpret_cast<LONG_PTR>(pThis));
  390. bRet = pThis->bHandleMessage(uMsg, wParam, lParam);
  391. }
  392. }
  393. else
  394. {
  395. pThis = reinterpret_cast<MGenericDialog*>(GetWindowLongPtr(hDlg, DWLP_USER));
  396. if( pThis )
  397. {
  398. bRet = pThis->bHandleMessage(uMsg, wParam, lParam);
  399. if( WM_DESTROY == uMsg )
  400. {
  401. // our window is about to go away, so we need to cleanup DWLP_USER here
  402. SetWindowLongPtr(hDlg, DWLP_USER, 0);
  403. }
  404. }
  405. }
  406. return bRet;
  407. }
  408. BOOL
  409. MGenericDialog::
  410. bSetText(
  411. LPCTSTR pszTitle
  412. )
  413. {
  414. return SetWindowText( _hDlg, pszTitle );
  415. }
  416. VOID
  417. MGenericDialog::
  418. vForceCleanup(
  419. VOID
  420. )
  421. {
  422. SetWindowLongPtr( _hDlg, DWLP_USER, 0L );
  423. }
  424. VOID
  425. MGenericDialog::
  426. vSetDlgMsgResult(
  427. LONG_PTR lResult
  428. )
  429. {
  430. SetWindowLongPtr( _hDlg, DWLP_MSGRESULT, (LPARAM)lResult );
  431. }
  432. VOID
  433. MGenericDialog::
  434. vSetParentDlgMsgResult(
  435. LRESULT lResult
  436. )
  437. {
  438. SetWindowLongPtr( GetParent( _hDlg ), DWLP_MSGRESULT, (LPARAM)lResult );
  439. }
  440. /********************************************************************
  441. Singleton window mixin.
  442. ********************************************************************/
  443. MSingletonWin::
  444. MSingletonWin(
  445. LPCTSTR pszPrinterName,
  446. HWND hwnd,
  447. BOOL bModal
  448. ) : _hwnd( hwnd ),
  449. _strPrinterName( pszPrinterName ),
  450. _hClassPidl( NULL ),
  451. _bModal( bModal )
  452. {
  453. }
  454. MSingletonWin::
  455. ~MSingletonWin(
  456. VOID
  457. )
  458. {
  459. //
  460. // hClassPidl is used to prevent multiple instances of the same
  461. // property sheet. When we destroy the object, unregister the
  462. // window.
  463. //
  464. if( _hClassPidl ){
  465. SPLASSERT( _hwnd );
  466. Printers_UnregisterWindow( _hClassPidl, _hwnd );
  467. }
  468. }
  469. BOOL
  470. MSingletonWin::
  471. bRegisterWindow(
  472. DWORD dwType
  473. )
  474. /*++
  475. Routine Description:
  476. Registers a window type with the shell based on the _strPrinterName
  477. and type. If there already is a printer window of this name and
  478. type, then return it.
  479. Clients can use this to prevent duplicate dialogs from coming up.
  480. Arguments:
  481. dwType - Type of dialog.
  482. Return Value:
  483. TRUE - success, either a new window or one already exists.
  484. If _hwnd is not then it is a new window. If one window
  485. already exists, then _hwnd is set to NULL.
  486. FALSE - call failed.
  487. --*/
  488. {
  489. SPLASSERT( !_hClassPidl );
  490. if( !_bModal ){
  491. if( !Printers_RegisterWindow( _strPrinterName,
  492. dwType,
  493. &_hClassPidl,
  494. &_hwnd )){
  495. SPLASSERT( !_hClassPidl );
  496. SPLASSERT( !_hwnd );
  497. return FALSE;
  498. }
  499. }
  500. return TRUE;
  501. }
  502. BOOL
  503. MSingletonWin::
  504. bValid(
  505. VOID
  506. )
  507. {
  508. return _strPrinterName.bValid();
  509. }
  510. BOOL
  511. MSingletonWin::
  512. bIsWindowPresent(
  513. VOID
  514. )
  515. {
  516. BOOL bReturn = FALSE;
  517. //
  518. // If the dialog is modal we allow duplicates.
  519. //
  520. if( _bModal )
  521. {
  522. bReturn = FALSE;
  523. }
  524. //
  525. // If a not modal and we have a null window
  526. // handle then this window is already present.
  527. //
  528. if( !_hwnd && !_bModal )
  529. {
  530. bReturn = TRUE;
  531. }
  532. return bReturn;
  533. }