home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / win / cdialog.cpp next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  5.4 KB  |  260 lines

  1. // -------------------------------
  2. //  Name:           CDialog.cpp
  3. //  Author:         J.R.Shannon
  4. //  Language:       C++
  5. //  Date:           6/11/92
  6. //  Revison:        2.1
  7. //  Last revision:  9/7/93
  8. //  Licence:        Public Domain
  9. //  Purpose:        Basic dialog window handling.
  10. // -------------------------------
  11.  
  12. #ifdef __OS2__
  13.  
  14. #define INCL_WIN
  15. #include <os2.h>
  16.  
  17. #include "CAssert.h"
  18. #include "win\CDialog.h"
  19.  
  20.  
  21. // This dialog window procedure discards window
  22. // messages until WM_INITDLG is received.  This
  23. // message contains information about the object
  24. // which is to supply the ProcessMsg method for
  25. // future message processing.
  26.  
  27. MRESULT EXPENTRY CDialogInitialDialogWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  28. {
  29.   switch (msg)
  30.     {
  31.     case WM_INITDLG:
  32.       {
  33.         // Ensure valid object pointer passed
  34.         CAssert(mp2);
  35.         // Set user area in window words.
  36.         WinSetWindowULong(hwnd, QWL_USER, (ULONG)mp2);
  37.         // Set new window procedure to one that knows
  38.         // about objects.
  39.         WinSubclassWindow(hwnd, (PFNWP)CDialogDialogWindowProc);
  40.         // Call the object's ProcessMsg for the
  41.         // WM_INITDLG message.
  42.         CDialog* real = (CDialog*)mp2;
  43.         real->HWindow = hwnd;
  44.         real->MsgSpec = (PVOID)((PBYTE)&msg + sizeof(MPARAM));
  45.         real->SetupWindow();
  46.         return real->ProcessMsg(hwnd, msg, mp1, mp2);
  47.       }
  48.     }
  49.   return WinDefDlgProc(hwnd, msg, mp1, mp2);
  50. }
  51.  
  52. // This dialog window procedure dispatches received
  53. // messages to the object's ProcessMsg method.
  54.  
  55. MRESULT EXPENTRY CDialogDialogWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  56. {
  57.   CDialog* real = (CDialog*)WinQueryWindowULong(hwnd, QWL_USER);
  58.   real->MsgSpec = (PVOID)((PBYTE)&msg + sizeof(MPARAM));
  59.   return real->ProcessMsg(hwnd, msg, mp1, mp2);
  60. }
  61.  
  62. // Override this virtual method to provide your own
  63. // message processing.
  64.  
  65. MRESULT CDialog::ProcessMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  66. {
  67.   return WinDefDlgProc(hwnd, msg, mp1, mp2);
  68. }
  69.  
  70. // Set up CDialog ready for the open().
  71.  
  72. CDialog::CDialog(HWND _owner, ULONG _resID,
  73.                  BOOL _modeless, HWND _parent,
  74.                  HMODULE _module)
  75.   : owner(_owner), resID(_resID), modeless(_modeless),
  76.     parent(_parent), hwndDialog(0), module(_module)
  77. {
  78. }
  79.  
  80. // Open the dialog window, and run it if it's modal.
  81.  
  82. void CDialog::Create(void)
  83. {
  84.   if (modeless == TRUE)
  85.     {
  86.       hwndDialog = WinLoadDlg(parent,
  87.                               owner,
  88.                               (PFNWP)CDialogInitialDialogWindowProc,
  89.                               module,
  90.                               resID,
  91.                               (PVOID)this);
  92.       CAssert(hwndDialog);
  93.     }
  94.   else
  95.     {
  96.       WinDlgBox(parent,
  97.                 owner,
  98.                 (PFNWP)CDialogInitialDialogWindowProc,
  99.                 module,
  100.                 resID,
  101.                 (PVOID)this);
  102.     }
  103. }
  104.  
  105. void
  106. CDialog::SetupWindow(void)
  107. {
  108. }
  109.  
  110. HAB
  111. CDialog::QueryHAB(void)
  112. {
  113.   return WinQueryAnchorBlock(HWindow);
  114. }
  115.  
  116. CDialog::~CDialog()
  117. {
  118.   Destroy();
  119. }
  120.  
  121. HWND CDialog::hwnd(void)
  122. {
  123.   return hwndDialog;
  124. }
  125.  
  126. void CDialog::show(BOOL _show)
  127. {
  128.   WinShowWindow(hwndDialog, _show);
  129. }
  130.  
  131. void CDialog::Destroy(void)
  132. {
  133.   if (hwndDialog)
  134.     {
  135.       WinDestroyWindow(hwndDialog);
  136.       hwndDialog = 0;
  137.     }
  138. }
  139.  
  140.  
  141. #else
  142.  
  143. // $Source: C:\logical\store\classes/RCS/CDIALOG.CPP,v $
  144. // $Revision: 1.7 $
  145. // $Date: 1994/02/15 11:14:41 $
  146. //
  147. // Information window implementation file - J.R.Shannon
  148. // (c) 1993 Logical Water.
  149.  
  150. #include <windows.h>
  151.  
  152. #define C_NO_IOSTREAM
  153. #include <CDList.h>
  154. #include <CStrng.h>
  155.  
  156. #include "cdialog.h"
  157.  
  158. // ---------------------------------------------------------------------------------------
  159.  
  160. CDialog::CDialog(HWND _owner, HINSTANCE _hInst, char* _resID, BOOL _modal)
  161. : owner(_owner),
  162.   hInst(_hInst),
  163.   resID(_resID),
  164.   modal(_modal)
  165. {
  166.   hwnd = 0;
  167.   proc = (DLGPROC)MakeProcInstance((FARPROC)DialogProc, hInst);
  168. }
  169.  
  170. CDialog::~CDialog()
  171. {
  172.   Close();
  173.   if (proc)
  174.     {
  175.       FreeProcInstance((FARPROC)DialogProc);
  176.       proc = 0;
  177.     }
  178. }
  179.  
  180. void
  181. CDialog::Create(void)
  182. {
  183.   if (modal == TRUE)
  184.     DialogBoxParam(hInst, (LPCSTR)resID, owner, proc, (LPARAM)this);
  185.   else
  186.     CreateDialogParam(hInst, (LPCSTR)resID, owner, proc, (LPARAM)this);
  187. }
  188.  
  189. void
  190. CDialog::Show(void)
  191. {
  192.   if (hwnd)
  193.     ShowWindow(hwnd, SW_SHOW);
  194. }
  195.  
  196. void
  197. CDialog::Hide(void)
  198. {
  199.   if (hwnd)
  200.     ShowWindow(hwnd, SW_HIDE);
  201. }
  202.  
  203. void
  204. CDialog::BringToTop(void)
  205. {
  206.   if (hwnd)
  207.     BringWindowToTop(hwnd);
  208. }
  209.  
  210. void
  211. CDialog::Move(int _x, int _y)
  212. {
  213.   SetWindowPos(hwnd, 0, _x, _y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  214. }
  215.  
  216. void
  217. CDialog::Close(void)
  218. {
  219.   if (hwnd)
  220.     {
  221.       if (modal)
  222.         EndDialog(hwnd, 1);
  223.       else
  224.         DestroyWindow(hwnd);
  225.  
  226.       hwnd = 0;
  227.     }
  228. }
  229.  
  230. LRESULT CALLBACK
  231. CDialog::DialogProc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
  232. {
  233.   if (msg == WM_INITDIALOG)
  234.     {
  235.       ((CDialog*)mp2)->HWindow = hwnd;
  236.       SetWindowLong(hwnd, DWL_USER, mp2);
  237.       return ((CDialog*)mp2)->RealProc(hwnd, msg, mp1, mp2);
  238.     }
  239.   else
  240.     {
  241.       CDialog* dialog = (CDialog*)GetWindowLong(hwnd, DWL_USER);
  242.       if (dialog)
  243.         return dialog->RealProc(hwnd, msg, mp1, mp2);
  244.     }
  245.   return 0;
  246. }
  247.  
  248. LRESULT
  249. CDialog::RealProc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
  250. {
  251.   hwnd;
  252.   msg;
  253.   mp1;
  254.   mp2;
  255.   return 0;
  256. }
  257.  
  258. #endif
  259.  
  260.