home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / clrwhl11.zip / exesrc / test.c next >
C/C++ Source or Header  |  1998-01-28  |  3KB  |  91 lines

  1. //=========================================================================\
  2. // test.c: tests the "edit color" dialog. As soon as the user click with   |
  3. //         any mouse button on the client window, the "edit color" dialog  |
  4. //         pops up and the client window background color is updated       |
  5. //         accordingly with the selected color                             |
  6. //=========================================================================/
  7.  
  8. #define SZ_CLIENTCLASS         "testclient"
  9. #define SZ_TESTTITLE           "\"Edit color\" test"
  10. #define TID_TITLE              100
  11.  
  12. #pragma strings(readonly)
  13.  
  14. #define INCL_WIN
  15. #define INCL_GPI
  16. #include <os2.h>
  17. #include <stdio.h>
  18. #include "editcol.h"
  19.  
  20. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  21.  
  22. int main(void) {
  23.    ULONG flFrame = FCF_STANDARD & ~(FCF_ACCELTABLE | FCF_MENU);
  24.    HWND hFrame, hClient;
  25.    QMSG qmsg;
  26.    HAB hab = WinInitialize(0);
  27.    HMQ hmq = WinCreateMsgQueue(hab, 0);
  28.  
  29.    WinRegisterClass(hab, SZ_CLIENTCLASS, ClientWndProc, CS_SIZEREDRAW, 0) ;                // Extra bytes to reserve
  30.    if (NULLHANDLE != (hFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,   
  31.                                                   &flFrame, SZ_CLIENTCLASS,
  32.                                                   SZ_TESTTITLE, 0L, NULLHANDLE,
  33.                                                   1, &hClient))) {
  34.       while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
  35.          WinDispatchMsg(hab, &qmsg);
  36.    } // end if
  37.    WinDestroyWindow(hFrame);
  38.    WinDestroyMsgQueue(hmq);
  39.    WinTerminate(hab);
  40.    return 0;
  41. }
  42.  
  43. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) {
  44.    static CLR clr;
  45.    CLR clrRet;
  46.    HPS hps;
  47.    RECTL rcl;
  48.    char achTxt[64];
  49.  
  50.    switch (msg) {
  51.       case WM_CREATE:
  52.          clr.rgb.red = 204;
  53.          clr.rgb.grn = 204;
  54.          clr.rgb.blu = 204;
  55.          break;
  56.       case WM_COLORWHEELCHANGED:
  57.       case WM_COLORWHEELCHANGED3:
  58.          clr.lClr = (LONG)mp1;
  59.          WinInvalidateRect(hwnd, NULL, FALSE);
  60.          sprintf(achTxt, "Color (RGB): %d - % d - %d",
  61.                  clr.rgb.red, clr.rgb.grn, clr.rgb.blu);
  62.          WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), achTxt);
  63.          break;
  64.       case WM_BUTTON1CLICK:
  65.       case WM_BUTTON2CLICK:
  66.       case WM_BUTTON3CLICK:
  67.          clr.lClr = WinEditColorDlg(HWND_DESKTOP, hwnd,
  68.                                     (COLOR)clr.lClr, NULL);
  69.          WinInvalidateRect(hwnd, NULL, FALSE);
  70.          sprintf(achTxt, "Returned color (RGB): %d - % d - %d",
  71.                  clr.rgb.red, clr.rgb.grn, clr.rgb.blu);
  72.          WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), achTxt);
  73.          WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, TID_TITLE, 5000);
  74.          return (MRESULT)TRUE;
  75.       case WM_TIMER:
  76.          if ((USHORT)mp1 == TID_TITLE)
  77.             WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), SZ_TESTTITLE);
  78.             WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, TID_TITLE);
  79.          break;
  80.       case WM_PAINT:
  81.          hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
  82.          GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
  83.          WinFillRect(hps, &rcl, clr.lClr);
  84.          WinEndPaint(hps);
  85.          break;
  86.       default: 
  87.          return WinDefWindowProc(hwnd, msg, mp1, mp2);
  88.    } // end switch
  89.    return (MRESULT)FALSE;
  90. }
  91.