home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cntrldes.zip / DRIVER.C < prev    next >
C/C++ Source or Header  |  1993-04-20  |  7KB  |  190 lines

  1.  
  2. /* Program name:   Controls.C  Title: Designing    Custom Controls        */
  3. /* OS/2    Developer Magazine, Issue:  Spring '93, page 72                 */
  4. /* Author:  Mark Benge     IBM Corp.                    */
  5. /*        Matt Smith     Prominare Inc.                    */
  6. /* Description:     Custom    controls demystified.  Sample image button    */
  7. /*         with text.  Can be used as the    basis for other        */
  8. /*         custom    controls.                    */
  9. /* Program Requirements:  OS/2 2.0, IBM    C Set/2    or WATCOM C 386/9.0    */
  10. /*              OS/2 Toolkit                    */
  11.  
  12. /* DISCLAIMER OF WARRANTIES:                        */
  13. /* -------------------------                        */
  14. /* The following [enclosed] code is sample code    created    by IBM        */
  15. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  16. /* standard IBM    product    and is provided    to you solely for the purpose    */
  17. /* of assisting    you in the development of your applications.  The code    */
  18. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  19. /* Prominare shall be liable for any damages arising out of your    */
  20. /* use of the sample code, even    if they    have been advised of the    */
  21. /* possibility of such damages.                        */
  22.  
  23. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  24. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  25. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  26.  
  27. #include <os2.h>
  28. #include <string.h>
  29.  
  30. #include "controls.h"
  31.  
  32. /* This    module contains    an example installable control that can    be used    */
  33. /* by any OS/2 2.x Presentation    Manager    application.  The control    */
  34. /* demonstrates    the principles of creating a custom control such    */
  35. /* that    new custom controls can    be created using this as a model.    */
  36. /*                                    */
  37. /* The control can be compiled using the IBM C Set/2 Version 1.0 with    */
  38. /* the following:                            */
  39. /*                                    */
  40. /*   Icc -G3 -O+ -Rn -W3 -C -FoDriver.Obj Driver.C            */
  41. /*                                    */
  42. /* The control can be compiled using the WATCOM    C 386 Version 9.0 with    */
  43. /* the following:                            */
  44. /*                                    */
  45. /*   Wcl386 -ms    -3s -bd    -s -ox -zp4 -w3    -c -fo=Driver.Obj Driver.C    */
  46.  
  47. /* Filename:   Driver.C                            */
  48.  
  49. /*  Version:   1.00                            */
  50. /*  Created:   1992-09-02                        */
  51. /*  Revised:   1992-12-30                        */
  52. /* Released:   1993-04-22                        */
  53.  
  54. /* Routines:   MRESULT EXPENTRY    DriverWndProc(HWND hWnd, ULONG msg,    */
  55. /*                          MPARAM mp1, MPARAM mp2);    */
  56. /*           INT main(INT argc, CHAR *argv[ ]);            */
  57.  
  58.  
  59. /* Copyright ╕ International Business Machines Corp., 1991,1992,1993.    */
  60. /* Copyright ╕ 1989-1993  Prominare Inc.  All Rights Reserved.        */
  61.  
  62. /* --------------------------------------------------------------------    */
  63.  
  64. INT main(INT, CHAR *[ ]);
  65. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2);
  66.  
  67. extern ULONG EXPENTRY InitControls(HAB hAB);
  68.  
  69. #pragma    subtitle("   Test Driver Window - Client Window Procedure")
  70. #pragma    page( )
  71.  
  72. /* --- DriverWndProc ----------------------------------    [ Private ] ---    */
  73. /*                                    */
  74. /*     This function is    used to    process    the messages for the main    */
  75. /*     Client Window.                            */
  76. /*                                    */
  77. /*     Upon Entry:                            */
  78. /*                                    */
  79. /*     HWND   hWnd; = Window Handle                    */
  80. /*     ULONG  msg;  = PM Message                    */
  81. /*     MPARAM mp1;  = Message Parameter    1                */
  82. /*     MPARAM mp2;  = Message Parameter    2                */
  83. /*                                    */
  84. /*     Upon Exit:                            */
  85. /*                                    */
  86. /*     EditWndProc = Message Handling Result                */
  87. /*                                    */
  88. /* --------------------------------------------------------------------    */
  89.  
  90. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2)
  91.  
  92. {
  93. HPS   hPS;               /* Presentation Space Handle        */
  94. RECTL rcl;               /* Client Window Rectangle        */
  95. LONG  lClr;               /* Colour Holder            */
  96.  
  97. switch ( msg )
  98.    {
  99.                /* Perform window initialization            */
  100.    case    WM_CREATE :
  101.        lClr = SYSCLR_DIALOGBACKGROUND;
  102.        WinSetPresParam(hWnd, PP_BACKGROUNDCOLORINDEX, 4UL, &lClr);
  103.  
  104.        WinCreateWindow(hWnd, "3DFrame",    "", WS_VISIBLE,    10L, 10L, 100L,    100L,
  105.                hWnd, HWND_TOP, 1024, (PVOID)NULL, (PVOID)NULL);
  106.  
  107.        WinCreateWindow(hWnd, "Patterns", "", WS_VISIBLE    | PATSYM_DIAG4,    150L, 10L, 100L, 100L,
  108.                hWnd, HWND_TOP, 1025, (PVOID)NULL, (PVOID)NULL);
  109.  
  110.        WinCreateWindow(hWnd, "3DLine", "", WS_VISIBLE |    LNS_HORIZONTAL,    10L, 200L, 100L, 10L,
  111.                hWnd, HWND_TOP, 1026, (PVOID)NULL, (PVOID)NULL);
  112.  
  113.        WinCreateWindow(hWnd, "3DText", "3D Text", WS_VISIBLE | DS_RAISED | DT_CENTER | DT_VCENTER,
  114.                10L, 125L, 100L,    30L,
  115.                hWnd, HWND_TOP, 1027, (PVOID)NULL, (PVOID)NULL);
  116.        break;
  117.                /* Erase    background                */
  118.  
  119.    case    WM_ERASEBACKGROUND :
  120.        WinQueryWindowRect(hWnd,    &rcl);
  121.        WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND);
  122.        break;
  123.                /* Paint    the main client    window            */
  124.    case    WM_PAINT :
  125.  
  126.        WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL,    &rcl), &rcl, SYSCLR_DIALOGBACKGROUND);
  127.        WinEndPaint(hPS);
  128.        break;
  129.                /* Close    Down                    */
  130.    case    WM_CLOSE :
  131.  
  132.        WinPostMsg(hWnd,    WM_QUIT, 0L, 0L);
  133.        break;
  134.                /* Default message processing            */
  135.    default:
  136.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  137.    }
  138. return(0L);
  139. }
  140. #pragma    subtitle("   Program Controller")
  141. #pragma    page( )
  142.  
  143. /* --- Main Program Controller ----------------------------------------    */
  144.  
  145. INT main(INT argc, CHAR    *argv[ ])
  146.  
  147. {
  148. HAB   hAB;               /* Anchor Block Handle        */
  149. HMQ   hmqDriver;           /* Message Queue Handle        */
  150. HWND  hwndDriver;           /* Driver Client Handle        */
  151. HWND  hwndDriverFrame;           /* Driver Frame Handle        */
  152. QMSG  qmsg;               /* PM Message Queue Holder        */
  153. ULONG flCreateFlags;           /* Window Creation Flags        */
  154.  
  155.                /* Initialize the program for PM    and create the    */
  156.                /* message queue                    */
  157.  
  158. WinSetCp(hmqDriver = WinCreateMsgQueue(hAB = WinInitialize(0), 0), 850);
  159.  
  160.                /* Register the main program window class    */
  161.  
  162. if ( !WinRegisterClass(hAB, "Driver", (PFNWP)DriverWndProc,
  163.                CS_CLIPCHILDREN | CS_SYNCPAINT |    CS_SIZEREDRAW, 0) )
  164.    return(1);
  165.                /* Initialize the custom    controls        */
  166. InitControls(hAB);
  167.                /* Create the main program window but do    not    */
  168.                /* show it yet                    */
  169.  
  170. flCreateFlags =    FCF_TITLEBAR | FCF_NOBYTEALIGN | FCF_SYSMENU | FCF_SIZEBORDER |    FCF_SHELLPOSITION;
  171. if ( !(hwndDriverFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
  172.                         &flCreateFlags, "Driver", "Control Driver",    0L,
  173.                         (HMODULE)0L, 0L, &hwndDriver)) )
  174.    return(1);
  175.                /* Retrieve and then dispatch messages        */
  176.  
  177. while (    WinGetMsg(hAB, &qmsg, (HWND)NULL, 0, 0)    )
  178.    WinDispatchMsg(hAB, &qmsg);
  179.  
  180. WinDestroyWindow(hwndDriverFrame);
  181.  
  182. WinDestroyMsgQueue(hmqDriver);
  183.  
  184.                /* Notify PM that main program thread not needed    */
  185.                /* any longer                    */
  186. WinTerminate(hAB);
  187.  
  188. return(0);
  189. }
  190.