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

  1. #define INCL_WIN
  2. #include <os2.h>
  3.  
  4. #include "win\cwindow.h"
  5.  
  6. // **********************************************
  7.  
  8. CApplication::CApplication(void)
  9. {
  10.   hab = WinInitialize(0);
  11.   if (hab)
  12.     hmq = WinCreateMsgQueue(hab, 0);
  13.   else
  14.     hmq = 0;
  15.  
  16.   if (hab == 0 || hmq == 0)
  17.     exit(EXIT_FAILURE);
  18. }
  19.  
  20. CApplication::~CApplication()
  21. {
  22.   if (hmq)
  23.     {
  24.       WinDestroyMsgQueue(hmq);
  25.       hmq = 0;
  26.     }
  27.   if (hab)
  28.     {
  29.       WinTerminate(hab);
  30.       hab = 0;
  31.     }
  32. }
  33.  
  34. void
  35. CApplication::Run(void)
  36. {
  37.  QMSG qmsg;
  38.  
  39.  while (WinGetMsg(hab, &qmsg, 0, 0, 0))
  40.    WinDispatchMsg(hab, &qmsg);
  41. }
  42.  
  43. // **********************************************
  44.  
  45. void
  46. CWinFrame::Create(void)
  47. {
  48.   FRAMECDATA fcdata;
  49.   fcdata.cb            = sizeof(fcdata);
  50.   fcdata.flCreateFlags = flags;
  51.   fcdata.hmodResources = 0;
  52.   fcdata.idResources   = 0;
  53.  
  54.   hwnd = WinCreateWindow(parent,
  55.                          WC_FRAME,
  56.                          0,
  57.                          visible == TRUE ? WS_VISIBLE : 0,
  58.                          x, y, w, h,
  59.                          owner,
  60.                          HWND_TOP,
  61.                          fid,
  62.                          &fcdata,
  63.                          0);
  64. }
  65.  
  66. // **********************************************
  67.  
  68. void
  69. CWinClient::Create(void)
  70. {
  71.   if (hab == 0)
  72.     hab = WinQueryAnchorBlock(owner);
  73.  
  74.   if (hab)
  75.     {
  76.       BOOL success = WinRegisterClass(hab,
  77.                                       (PSZ)(char*)className,
  78.                                       (PFNWP)CWinClientWindowProc,
  79.                                       clStyle,
  80.                                       sizeof(CWinClient*));
  81.  
  82.       if (success == FALSE)
  83.         exit(EXIT_FAILURE);
  84.     }
  85.  
  86.  
  87.  
  88.   HWindow = WinCreateWindow(parent,
  89.                             (PSZ)(char*)className,
  90.                             (PSZ)"",
  91.                             wnStyle,
  92.                             x, y, w, h,
  93.                             owner,
  94.                             HWND_TOP,
  95.                             winID,
  96.                             (PVOID)this,
  97.                             0);
  98.   if (HWindow == 0)
  99.     exit(EXIT_FAILURE);
  100. }
  101.  
  102. MRESULT EXPENTRY
  103. CWinClientWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  104. {
  105.   CWinClient* object = 0;
  106.  
  107.   if (msg == WM_CREATE)
  108.     {
  109.       object = (CWinClient*)mp1;
  110.       WinSetWindowPtr(hwnd, QWL_USER, (PVOID)object);
  111.       object->HWindow = hwnd;
  112.       object->SetupWindow();
  113.     }
  114.   else
  115.     object = (CWinClient*)WinQueryWindowPtr(hwnd, QWL_USER);
  116.  
  117.   object->MsgSpec = (PVOID)((PBYTE)&msg + sizeof(MPARAM));
  118.  
  119.   return object->ProcessMsg(hwnd, msg, mp1, mp2);
  120. }
  121.  
  122.  
  123. CWinFrame::CWinFrame(HWND  _parent,
  124.                      HWND  _owner,
  125.                      HAB   _hab,
  126.                      ULONG _flags,
  127.                      BOOL  _visible,
  128.                      ULONG _fid,
  129.                      LONG  _x,
  130.                      LONG  _y,
  131.                      LONG  _w,
  132.                      LONG  _h)
  133. : parent(_parent),
  134.   owner(_owner),
  135.   hab(_hab),
  136.   flags(_flags),
  137.   visible(_visible),
  138.   fid(_fid),
  139.   x(_x),
  140.   y(_y),
  141.   w(_w),
  142.   h(_h),
  143.   hwnd(0)
  144. {
  145.   Create();
  146. }
  147.  
  148.  
  149. CWinFrame::~CWinFrame()
  150. {
  151.   Destroy();
  152. }
  153.  
  154.  
  155. void
  156. CWinFrame::Destroy(void)
  157. {
  158.   if (hwnd)
  159.     {
  160.       WinDestroyWindow(hwnd);
  161.       hwnd = 0;
  162.     }
  163. }
  164.  
  165.  
  166. void
  167. CWinFrame::title(const char* _title)
  168. {
  169.   WinSetWindowText(hwnd, (PSZ)_title);
  170. }
  171.  
  172.  
  173. void
  174. CWinFrame::move(LONG _x, LONG _y)
  175. {
  176.   WinSetWindowPos(hwnd, 0, _x, _y, 0, 0, SWP_MOVE);
  177. }
  178.  
  179.  
  180. void
  181. CWinFrame::move(LONG _x, LONG _y, LONG _w, LONG _h)
  182. {
  183.   WinSetWindowPos(hwnd, 0, _x, _y, _w, _h, SWP_MOVE | SWP_SIZE);
  184. }
  185.  
  186.  
  187. void
  188. CWinFrame::size(LONG _w, LONG _h)
  189. {
  190.   WinSetWindowPos(hwnd, 0, 0, 0, _w, _h, SWP_SIZE);
  191. }
  192.  
  193.  
  194. void
  195. CWinFrame::show(BOOL _visible)
  196. {
  197.   WinShowWindow(hwnd, _visible);
  198. }
  199.  
  200.  
  201. void
  202. CWinFrame::front(void)
  203. {
  204.   WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
  205. }
  206.  
  207.  
  208. void
  209. CWinFrame::back(void)
  210. {
  211.   WinSetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
  212. }
  213.  
  214. // **********************************************
  215.  
  216.  
  217. CWinClient::CWinClient(HWND  _parent,
  218.                        HWND  _owner,
  219.                        HAB   _hab,
  220.                        ULONG _clStyle,
  221.                        ULONG _wnStyle,
  222.                        ULONG _id,
  223.                        const char* _class)
  224. : parent(_parent),
  225.   owner(_owner),
  226.   hab(_hab),
  227.   clStyle(_clStyle),
  228.   wnStyle(_wnStyle),
  229.   winID(_id),
  230.   className(_class),
  231.   HWindow(0),
  232.   x(0), y(0), w(0), h(0)
  233. {
  234. }
  235.  
  236.  
  237.  
  238. CWinClient::~CWinClient()
  239. {
  240.   Destroy();
  241. }
  242.  
  243.  
  244. void
  245. CWinClient::Destroy(void)
  246. {
  247.   if (HWindow)
  248.     {
  249.       WinDestroyWindow(HWindow);
  250.       HWindow = 0;
  251.     }
  252. }
  253.  
  254.  
  255. MRESULT
  256. CWinClient::ProcessMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  257. {
  258.   return WinDefWindowProc(hwnd, msg, mp1, mp2);
  259. }
  260.  
  261.  
  262. void
  263. CWinClient::SetupWindow(void)
  264. {
  265. }
  266.  
  267.  
  268. void
  269. CWinClient::move(LONG _x, LONG _y)
  270. {
  271.   WinSetWindowPos(HWindow, 0, _x, _y, 0, 0, SWP_MOVE);
  272. }
  273.  
  274.  
  275. void
  276. CWinClient::move(LONG _x, LONG _y, LONG _w, LONG _h)
  277. {
  278.   WinSetWindowPos(HWindow, 0, _x, _y, _w, _h, SWP_MOVE | SWP_SIZE);
  279. }
  280.  
  281.  
  282. void
  283. CWinClient::size(LONG _w, LONG _h)
  284. {
  285.   WinSetWindowPos(HWindow, 0, 0, 0, _w, _h, SWP_SIZE);
  286. }
  287.  
  288.  
  289. void
  290. CWinClient::show(BOOL _visible)
  291. {
  292.   WinShowWindow(HWindow, _visible);
  293. }
  294.  
  295.  
  296. void
  297. CWinClient::front(void)
  298. {
  299.   WinSetWindowPos(HWindow, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
  300. }
  301.  
  302.  
  303. void
  304. CWinClient::back(void)
  305. {
  306.   WinSetWindowPos(HWindow, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
  307. }
  308.  
  309.  
  310. void
  311. CWinClient::SetStyle(ULONG _style)
  312. {
  313.   wnStyle = _style;
  314. }
  315.  
  316.  
  317. void
  318. CWinClient::SetSize(LONG _x, LONG _y, LONG _w, LONG _h)
  319. {
  320.   x = _x;
  321.   y = _y;
  322.   w = _w;
  323.   h = _h;
  324. }
  325.  
  326.  
  327. HAB
  328. CWinClient::QueryHAB(void)
  329. {
  330.   return hab;
  331. }
  332.  
  333. // **********************************************
  334.  
  335.  
  336. CWinFramedClient::CWinFramedClient(HWND  _parent,
  337.                                    HWND  _owner,
  338.                                    HAB   _hab,
  339.                                    ULONG _fcFlags,
  340.                                    BOOL  _visible,
  341.                                    ULONG _clStyle,
  342.                                    ULONG _wnStyle,
  343.                                    LONG  _x,
  344.                                    LONG  _y,
  345.                                    LONG  _w,
  346.                                    LONG  _h,
  347.                                    ULONG _id,
  348.                                    ULONG _fid,
  349.                                    const char* _class)
  350. : CWinFrame(_parent, _owner, _hab, _fcFlags, _visible, _fid, _x, _y, _w, _h),
  351.   CWinClient(hwndFrame(), hwndFrame(), _hab, _clStyle, _wnStyle, _id, _class)
  352. {
  353. }
  354.  
  355.  
  356. CWinFramedClient::~CWinFramedClient()
  357. {
  358.   Destroy();
  359. }
  360.  
  361.  
  362. void
  363. CWinFramedClient::Destroy(void)
  364. {
  365.   CWinClient::Destroy();
  366.   CWinFrame::Destroy();
  367. }
  368.  
  369.  
  370. void
  371. CWinFramedClient::Create(void)
  372. {
  373.   CWinClient::Create();
  374. }
  375.  
  376.  
  377. MRESULT
  378. CWinFramedClient::ProcessMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  379. {
  380.   return CWinClient::ProcessMsg(hwnd, msg, mp1, mp2);
  381. }
  382.  
  383.  
  384. void
  385. CWinFramedClient::SetupWindow(void)
  386. {
  387.   CWinClient::SetupWindow();
  388. }
  389.  
  390.  
  391. void
  392. CWinFramedClient::move(LONG _x, LONG _y)
  393. {
  394.   CWinFrame::move(_x, _y);
  395. }
  396.  
  397.  
  398. void
  399. CWinFramedClient::move(LONG _x, LONG _y, LONG _w, LONG _h)
  400. {
  401.   CWinFrame::move(_x, _y, _w, _h);
  402. }
  403.  
  404.  
  405. void
  406. CWinFramedClient::size(LONG _w, LONG _h)
  407. {
  408.   CWinFrame::size(_w, _h);
  409. }
  410.  
  411.  
  412. void
  413. CWinFramedClient::show(BOOL _visible)
  414. {
  415.   CWinFrame::show(_visible);
  416. }
  417.  
  418.  
  419. void
  420. CWinFramedClient::front(void)
  421. {
  422.   CWinFrame::front();
  423. }
  424.  
  425.  
  426. void
  427. CWinFramedClient::back(void)
  428. {
  429.   CWinFrame::back();
  430. }
  431.  
  432.  
  433. HWND
  434. CWinFramedClient::hwndClient(void)
  435. {
  436.   return CWinClient::HWindow;
  437. }
  438.  
  439.  
  440. HWND
  441. CWinFramedClient::hwndFrame(void)
  442. {
  443.   return CWinFrame::hwnd;
  444. }
  445.  
  446.  
  447. void
  448. CWinFramedClient::title(const char* _title)
  449. {
  450.   CWinFrame::title(_title);
  451. }
  452.  
  453. // **************************************************
  454.  
  455. #ifdef RECT_DEFINED
  456.  
  457.  
  458. void
  459. GetClientRect(HWND hwnd, RECT* _rect)
  460. {
  461.   WinQueryWindowRect(hwnd, (PRECTL)_rect);
  462. }
  463.  
  464. #endif
  465.  
  466.