Leaked source code of windows server 2003
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.

105 lines
3.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: dialog.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes: CHlprDialog
  11. //
  12. // Functions: DialogProc
  13. //
  14. // History: 4-12-94 stevebl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include "cdialog.h"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CHlprDialog::ShowDialog
  22. //
  23. // Synopsis: Creates the dialog so that it's DialogProc member function can
  24. // be invoked.
  25. //
  26. // Arguments: [hinst] - handle of the application instance
  27. // [lpszTemplate] - identifies the dialog box template
  28. // [hwndOwner] - handle of the owner window
  29. //
  30. // Returns: return value from the dialog box
  31. //
  32. // History: 4-12-94 stevebl Created
  33. //
  34. // Notes: The dialog box object exists until deleted by the caller.
  35. // It can be shown any number of times.
  36. //
  37. // This function is analgous to Windows' DialogBox function. The
  38. // main difference being that you don't specify a DialogProc;
  39. // you override the pure virtal function CHlprDialog::DialogProc.
  40. //
  41. //----------------------------------------------------------------------------
  42. int CHlprDialog::ShowDialog(HINSTANCE hinst, LPCTSTR lpszTemplate, HWND hwndOwner)
  43. {
  44. _hInstance = hinst;
  45. return(DialogBoxParam(hinst, lpszTemplate, hwndOwner, ::DialogProc, (long)this));
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: DialogProc
  50. //
  51. // Synopsis: Common DialogProc used by all CHlprDialog class objects.
  52. //
  53. // Arguments: [hwndDlg] - handle of dialog box
  54. // [uMsg] - message
  55. // [wParam] - first message parameter
  56. // [lParam] - second message parameter
  57. //
  58. // Returns: response from the CHlprDialog::DialogProc method
  59. //
  60. // History: 4-12-94 stevebl Created
  61. //
  62. // Notes: This procedure is the DialogProc registered for all dialogs
  63. // created with the CHlprDialog class. It uses the parameter
  64. // passed with the WM_INITDIALOG message to identify the dialog
  65. // classes' "this" pointer which it then stores in the window
  66. // structure's GWL_USERDATA field. All subsequent messages
  67. // can then be forwarded on to the correct dialog class's
  68. // DialogProc method by using the pointer stored in the
  69. // GWL_USERDATA field.
  70. //
  71. //----------------------------------------------------------------------------
  72. INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  73. {
  74. CHlprDialog * pdlg;
  75. switch (uMsg)
  76. {
  77. case WM_INITDIALOG:
  78. // This message is how we identify the dialog object.
  79. // get a pointer to the window class object
  80. pdlg = (CHlprDialog *) lParam;
  81. // set its USERDATA word to point to the class object
  82. SetWindowLong(hwndDlg, GWL_USERDATA, (long) pdlg);
  83. break;
  84. default:
  85. // get a pointer to the window class object
  86. pdlg = (CHlprDialog *) GetWindowLong(hwndDlg, GWL_USERDATA);
  87. break;
  88. }
  89. // and call its message proc method
  90. if (pdlg != (CHlprDialog *) 0)
  91. {
  92. return(pdlg->DialogProc(hwndDlg, uMsg, wParam, lParam));
  93. }
  94. else
  95. {
  96. return(FALSE);
  97. }
  98. }