home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / CWINAPP.CPP < prev    next >
C/C++ Source or Header  |  1996-08-10  |  4KB  |  163 lines

  1.  
  2. // ----------------------------------------------------------------------
  3. // Common Presentation Classes - Version 1.00.1
  4. // Copyright (c) 1996 by Marco Maccaferri. All rights reserved.
  5. //
  6. // History:
  7. //    10/08/96 - Initial coding.
  8. // ----------------------------------------------------------------------
  9.  
  10. #include "_ldefs.h"
  11. #include "cpc.h"
  12.  
  13. #if defined(__OS2__)
  14. MRESULT EXPENTRY CWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  15. #elif defined(__NT__)
  16. LRESULT CALLBACK CWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  17. #endif
  18. {
  19.    int i;
  20.    class CWnd *wndClass;
  21.    CPC_MSGMAP_ENTRY *msgMap = NULL;
  22.  
  23. #if defined(__OS2__)
  24.    wndClass = (class CWnd *)WinQueryWindowULong (hwnd, QWL_USER);
  25. #elif defined(__NT__)
  26.    wndClass = (class CWnd *)GetWindowLong (hwnd, GWL_USERDATA);
  27. #endif
  28.  
  29.    if (wndClass != NULL)
  30.       msgMap = wndClass->GetMessageMap ();
  31.  
  32.    switch (msg) {
  33.       case WM_CREATE:
  34.          break;
  35.  
  36. #if defined(__OS2__)
  37.       case WM_ERASEBACKGROUND:
  38.          return ((MRESULT)TRUE);
  39. #endif
  40.  
  41.       case WM_COMMAND:
  42.          for (i = 0; msgMap[i].pfn != NULL; i++) {
  43. #if defined(__OS2__)
  44.             if (msgMap[i].nMessage == msg) {
  45.                if (msgMap[i].nID >= SHORT1FROMMP (mp1) && msgMap[i].nLastID <= SHORT1FROMMP (mp1)) {
  46. #elif defined(__NT__)
  47.             if (msgMap[i].nMessage == msg && msgMap[i].nCode == HIWORD (wParam)) {
  48.                if (msgMap[i].nID >= LOWORD (wParam) && msgMap[i].nLastID <= LOWORD (wParam)) {
  49. #endif
  50.                   (wndClass->*msgMap[i].pfnw) ();
  51.                   break;
  52.                }
  53.             }
  54.          }
  55.          return (0);
  56.    }
  57.  
  58. #if defined(__OS2__)
  59.    return (WinDefWindowProc (hwnd, msg, mp1, mp2));
  60. #elif defined(__NT__)
  61.    return (DefWindowProc (hwnd, msg, wParam, lParam));
  62. #endif
  63. }
  64.  
  65. BEGIN_MESSAGE_MAP (CWnd, CWnd)
  66. END_MESSAGE_MAP ()
  67.  
  68. CWnd::CWnd (void)
  69. {
  70. }
  71.  
  72. CWnd::~CWnd (void)
  73. {
  74. }
  75.  
  76. USHORT CWnd::OnCreate (VOID)
  77. {
  78.    return (TRUE);
  79. }
  80.  
  81. // ----------------------------------------------------------------------
  82.  
  83. CFrameWnd::CFrameWnd (void)
  84. {
  85.    int x, y, dx, dy;
  86.    ULONG flFrame;
  87.  
  88. #if defined(__OS2__)
  89.    dy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) / 2;
  90.    dx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) / 2;
  91.    y = (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - dy) / 2;
  92.    x = (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - dx) / 2;
  93. #elif defined(__NT__)
  94.    dy = GetSystemMetrics (SM_CYSCREEN) / 2;
  95.    dx = GetSystemMetrics (SM_CXSCREEN) / 2;
  96.    y = (GetSystemMetrics (SM_CYSCREEN) - dy) / 2;
  97.    x = (GetSystemMetrics (SM_CXSCREEN) - dx) / 2;
  98. #endif
  99.  
  100.    cWnd.cbSize = sizeof (CWND_DATA);
  101.    cWnd.Wnd = this;
  102.  
  103.    flFrame = (FCF_TASKLIST|FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX|FCF_SIZEBORDER|FCF_NOBYTEALIGN);
  104.    if ((hwndMainFrame = WinCreateStdWindow (HWND_DESKTOP, 0, &flFrame, "CWINAPP_WINDOW", NULL, 0, NULLHANDLE, 256, &hwndMainClient)) != NULLHANDLE) {
  105.       WinSetWindowULong (hwndMainClient, QWL_USER, (ULONG)this);
  106.  
  107.       WinSetWindowText (hwndMainFrame, "Common Presentation Classes Window");
  108.  
  109.       if (OnCreate () == TRUE)
  110.          WinSetWindowPos (hwndMainFrame, NULLHANDLE, x, y, dx, dy, SWP_SIZE|SWP_MOVE|SWP_SHOW|SWP_ACTIVATE);
  111.       else {
  112.          WinDestroyWindow (hwndMainFrame);
  113.          hwndMainFrame = NULL;
  114.       }
  115.    }
  116. }
  117.  
  118. CFrameWnd::~CFrameWnd (void)
  119. {
  120.    if (hwndMainFrame != NULLHANDLE)
  121.       WinDestroyWindow (hwndMainFrame);
  122. }
  123.  
  124. // ----------------------------------------------------------------------
  125.  
  126. CWinApp::CWinApp (void)
  127. {
  128.    m_pMainWnd = NULL;
  129.  
  130.    if ((hab = WinInitialize (0)) != 0) {
  131.       if ((hmq = WinCreateMsgQueue (hab, 0)) != 0)
  132.          WinRegisterClass (hab, "CWINAPP_WINDOW", CWndProc, CS_CLIPCHILDREN|CS_SIZEREDRAW|CS_MOVENOTIFY, 0);
  133.    }
  134. }
  135.  
  136. CWinApp::~CWinApp (void)
  137. {
  138.    if (m_pMainWnd != NULL)
  139.       delete m_pMainWnd;
  140.  
  141.    if (hab != 0) {
  142.       if (hmq != 0)
  143.          WinDestroyMsgQueue (hmq);
  144.       WinTerminate (hab);
  145.    }
  146. }
  147.  
  148. USHORT CWinApp::InitInstance (VOID)
  149. {
  150.    m_pMainWnd = new CFrameWnd;
  151.  
  152.    return (TRUE);
  153. }
  154.  
  155. VOID CWinApp::Run (VOID)
  156. {
  157.    InitInstance ();
  158.  
  159.    while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
  160.       WinDispatchMsg (hab, &qmsg);
  161. }
  162.  
  163.