home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / CWND.CPP < prev    next >
C/C++ Source or Header  |  1998-05-12  |  7KB  |  237 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "_ldefs.h"
  20. #include "cpc.h"
  21.  
  22. #if defined(__NT__)
  23. extern HINSTANCE hinst;
  24. #endif
  25.  
  26. typedef struct {
  27.    USHORT cbSize;
  28.    class CWnd *Wnd;
  29. } CWND_DATA;
  30.  
  31. // ----------------------------------------------------------------------
  32. // Frame window procedure
  33. // ----------------------------------------------------------------------
  34.  
  35. #if defined(__OS2__)
  36. MRESULT EXPENTRY CFrameWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  37. #elif defined(__NT__)
  38. LRESULT CALLBACK CFrameWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  39. #endif
  40. {
  41.    int i;
  42.    class CWnd *wndClass;
  43.    CPC_MSGMAP_ENTRY *msgMap = NULL;
  44.  
  45. #if defined(__OS2__)
  46.    wndClass = (class CWnd *)WinQueryWindowULong (hwnd, QWL_USER);
  47. #elif defined(__NT__)
  48.    wndClass = (class CWnd *)GetWindowLong (hwnd, GWL_USERDATA);
  49. #endif
  50.  
  51.    if (wndClass != NULL) {
  52.       wndClass->m_msg = msg;
  53. #if defined(__OS2__)
  54.       wndClass->m_mp1 = mp1;
  55.       wndClass->m_mp2 = mp2;
  56. #elif defined(__NT__)
  57.       wndClass->m_wParam = wParam;
  58.       wndClass->m_lParam = lParam;
  59. #endif
  60.  
  61.       msgMap = wndClass->GetMessageMap ();
  62.    }
  63.  
  64.    switch (msg) {
  65.       case WM_CREATE: {
  66. #if defined(__OS2__)
  67.          CWND_DATA *cData = (CWND_DATA *)mp2;
  68. #elif defined(__NT__)
  69.          CWND_DATA *cData = (CWND_DATA *)lParam;
  70. #endif
  71.  
  72.          wndClass = cData->Wnd;
  73.          wndClass->m_hWnd = hwnd;
  74. #if defined(__OS2__)
  75.          WinSetWindowULong (hwnd, QWL_USER, (ULONG)wndClass);
  76. #elif defined(__NT__)
  77.          SetWindowLong (hwnd, GWL_USERDATA, (LONG)wndClass);
  78. #endif
  79.  
  80.          wndClass->OnCreate ();
  81. #if defined(__OS2__)
  82.          break;
  83. #elif defined(__NT__)
  84.          return ((BOOL)TRUE);
  85. #endif
  86.       }
  87.  
  88. #if defined(__OS2__)
  89.       case WM_CONTROL:
  90.          for (i = 0; msgMap[i].pfn != NULL; i++) {
  91.             if (msgMap[i].nMessage == msg) {
  92.                if (msgMap[i].nID >= SHORT1FROMMP (mp1) && msgMap[i].nLastID <= SHORT1FROMMP (mp1)) {
  93.                   if (msgMap[i].nCode == SHORT2FROMMP (mp1)) {
  94.                      (wndClass->*msgMap[i].pfn) ();
  95.                      break;
  96.                   }
  97.                }
  98.             }
  99.          }
  100.          return (0);
  101. #endif
  102.  
  103. #if defined(__NT__)
  104.       case WM_NOTIFY: {
  105.          LPNMHDR pnmh = (LPNMHDR)lParam;
  106.  
  107.          for (i = 0; msgMap[i].pfn != NULL; i++) {
  108.             if (msgMap[i].nMessage == msg && msgMap[i].nCode == pnmh->code) {
  109.                if (msgMap[i].nID >= pnmh->idFrom && msgMap[i].nLastID <= pnmh->idFrom) {
  110.                   (wndClass->*msgMap[i].pfn) ();
  111.                   break;
  112.                }
  113.             }
  114.          }
  115.          return (0);
  116.       }
  117. #endif
  118.  
  119.       case WM_COMMAND:
  120.          for (i = 0; msgMap[i].pfn != NULL; i++) {
  121. #if defined(__OS2__)
  122.             if (msgMap[i].nMessage == msg) {
  123.                if (msgMap[i].nID >= SHORT1FROMMP (mp1) && msgMap[i].nLastID <= SHORT1FROMMP (mp1)) {
  124. #elif defined(__NT__)
  125.             if (msgMap[i].nMessage == msg && msgMap[i].nCode == HIWORD (wParam)) {
  126.                if (msgMap[i].nID >= LOWORD (wParam) && msgMap[i].nLastID <= LOWORD (wParam)) {
  127. #endif
  128.                   (wndClass->*msgMap[i].pfn) ();
  129.                   break;
  130.                }
  131.             }
  132.          }
  133.          return (0);
  134.  
  135. #if defined(__NT__)
  136.       case WM_CLOSE:
  137.          EndDialog (hwnd, FALSE);
  138.          break;
  139. #endif
  140.  
  141.       default:
  142.          if (msgMap != NULL) {
  143.             for (i = 0; msgMap[i].pfn != NULL; i++) {
  144.                if (msgMap[i].nMessage == msg) {
  145.                   (wndClass->*msgMap[i].pfn) ();
  146.                   return (0);
  147.                }
  148.             }
  149.          }
  150.          break;
  151.    }
  152.  
  153. #if defined(__OS2__)
  154.    return (WinDefWindowProc (hwnd, msg, mp1, mp2));
  155. #elif defined(__NT__)
  156.    return (DefWindowProc (hwnd, msg, wParam, lParam));
  157. #endif
  158. }
  159.  
  160. USHORT CWnd::OnCreate (VOID)
  161. {
  162.    return (TRUE);
  163. }
  164.  
  165. // ----------------------------------------------------------------------
  166. // Windowing API replacement
  167. // ----------------------------------------------------------------------
  168.  
  169. USHORT CWnd::Create (int x, int y, int dx, int dy, PSZ title)
  170. {
  171.    USHORT RetVal = FALSE;
  172.    CWND_DATA cWnd;
  173. #if defined(__OS2__)
  174.    FRAMECDATA fd;
  175.    HWND hwndFrame;
  176. #endif
  177.  
  178.    if (title == NULL)
  179.       title = "CPC Main Window";
  180.  
  181.    cWnd.cbSize = sizeof (CWND_DATA);
  182.    cWnd.Wnd = this;
  183.  
  184. #if defined(__OS2__)
  185.    fd.cb = sizeof (fd);
  186.    fd.flCreateFlags = FCF_TASKLIST|FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX|FCF_SIZEBORDER|FCF_NOBYTEALIGN;
  187.    fd.hmodResources = NULL;
  188.    fd.idResources = 256;
  189.  
  190.    if ((hwndFrame = WinCreateWindow (HWND_DESKTOP, WC_FRAME, NULL, 0, 0, 0, 0, 0, NULL, HWND_TOP, fd.idResources, &fd, NULL)) != NULLHANDLE) {
  191.       if ((m_hWnd = WinCreateWindow (hwndFrame, "CPC_MAIN_WINDOW", title, 0, 0, 0, 10, 10, hwndFrame, HWND_BOTTOM, FID_CLIENT, NULL, NULL)) != NULL) {
  192.          WinSetWindowPos (hwndFrame, NULLHANDLE, x, y, dx, dy, SWP_SIZE|SWP_MOVE|SWP_SHOW|SWP_ACTIVATE);
  193.          RetVal = TRUE;
  194.       }
  195.    }
  196.    if ((m_hWnd = WinCreateWindow (HWND_DESKTOP, WC_FRAME, title, WS_VISIBLE, x, y, dx, dy, NULL, HWND_TOP, 1001, NULL, NULL)) != NULL)
  197.       RetVal = TRUE;
  198. #elif defined(__NT__)
  199.    if ((m_hWnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, "CPC_MAIN_WINDOW", title, WS_OVERLAPPEDWINDOW, x, y, dx, dy, NULL, NULL, hinst, &cWnd)) != NULL)
  200.       RetVal = TRUE;
  201. #endif
  202.  
  203.    return (RetVal);
  204. }
  205.  
  206. int CWnd::MessageBox (PSZ text, PSZ caption, int button)
  207. {
  208. #if defined(__OS2__)
  209.    return ((int)WinMessageBox (HWND_DESKTOP, m_hWnd, text, caption, 0, button|MB_MOVEABLE));
  210. #elif defined(__NT__)
  211.    return (::MessageBox (m_hWnd, text, caption, button));
  212. #endif
  213. }
  214.  
  215. VOID CWnd::SetWindowTitle (PSZ title)
  216. {
  217. #if defined(__OS2__)
  218.    WinSetWindowText (m_hWnd, title);
  219. #elif defined(__NT__)
  220.    ::SetWindowText (m_hWnd, title);
  221. #endif
  222. }
  223.  
  224. VOID CWnd::ShowWindow (int nCmdShow)
  225. {
  226. #if defined(__OS2__)
  227.    WinSetWindowPos (m_hWnd, NULLHANDLE, 0, 0, 0, 0, SWP_SHOW|SWP_ACTIVATE);
  228.    nCmdShow = nCmdShow;
  229. #elif defined(__NT__)
  230.    ::ShowWindow (m_hWnd, nCmdShow);
  231. #endif
  232. }
  233.  
  234. BEGIN_MESSAGE_MAP (CWnd, CWnd)
  235. END_MESSAGE_MAP ()
  236.  
  237.