home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / framctl1.zip / FRAMECTL.C < prev    next >
Text File  |  1996-07-30  |  19KB  |  358 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /* Program name:   FrameCtl.C                                           */
  4. /* Title:          A Picture Perfect Control                            */
  5. /*                 OS/2 Magazine - GUI Corner                           */
  6. /*                 October 1996 issue                                   */
  7. /*                                                                      */
  8. /* Author:         Mark Benge   IBM Corp.                               */
  9. /*                 Matt Smith   Prominare Inc.                          */
  10. /*                                                                      */
  11. /* Description:    Illustrates how to add frame control extensions.     */
  12. /*                                                                      */
  13. /* DISCLAIMER OF WARRANTIES:                                            */
  14. /* -------------------------                                            */
  15. /* The following [enclosed] code is sample code created by IBM          */
  16. /* Corporation and Prominare Inc.  This sample code is not part of any  */
  17. /* standard IBM product and is provided to you solely for the purpose   */
  18. /* of assisting you in the development of your applications.  The code  */
  19. /* is provided "AS IS", without warranty of any kind.  Neither IBM nor  */
  20. /* Prominare shall be liable for any damages arising out of your        */
  21. /* use of the sample code, even if they have been advised of the        */
  22. /* possibility of such damages.                                         */
  23. /************************************************************************/
  24.  
  25. #define INCL_DOS                   /* Include OS/2 DOS Kernal           */
  26. #define INCL_GPI                   /* Include OS/2 PM GPI Interface     */
  27. #define INCL_WIN                   /* Include OS/2 PM Windows Interface */
  28.  
  29. #include <os2.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32.  
  33. #include "framectl.h"
  34.  
  35. /************************************************************************/
  36. /* This module contains example installable control that can be used    */
  37. /* by any OS/2 2.x and Warp Presentation Manager application.  The      */
  38. /* sample demonstrates the principles of adding frame control           */
  39. /* extensions such that other extensions can be added using this as     */
  40. /* a model.                                                             */
  41. /*                                                                      */
  42. /* Filename : FrameCtl.C                                                */
  43. /* Version  : 1.00                                                      */
  44. /* Created  : 1996-06-07                                                */
  45. /* Revised  :                                                           */
  46. /* Released :                                                           */
  47. /*                                                                      */
  48. /* Routines:  MRESULT EXPENTRY FrameWndProc( HWND hWnd, ULONG msg,      */
  49. /*                                           MPARAM mp1, MPARAM mp2 )   */
  50. /*            int main(int argc, char* argv[] )                         */
  51. /*                                                                      */
  52. /* Copyright ╕ International Business Machines Corp., 1991,1992,1993.   */
  53. /* Copyright ╕ 1989-1993  Prominare Inc.  All Rights Reserved.          */
  54. /*                                                                      */
  55. /************************************************************************/
  56.  
  57. HWND hwndHelpBtn;                  /* Help Button Handle                */
  58. HWND hwndCloseBtn;                 /* Close Button Handle               */
  59. PFNWP DefFrameWndProc;             /* Frame Control Subclass Procedure  */
  60.  
  61. /************************************************************************/
  62. /* Prototypes                                                           */
  63. /************************************************************************/
  64. int main( int, char* [] );
  65. MRESULT EXPENTRY FrameWndProc( HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  66.  
  67. /* --- FrameWndProc ----------------------------------- [ Private ] --- */
  68. /*                                                                      */
  69. /*     This function is used to process the messages for the frame      */
  70. /*     control window.                                                  */
  71. /*                                                                      */
  72. /*     Upon Entry:                                                      */
  73. /*                                                                      */
  74. /*     HWND   hWnd; = Window Handle                                     */
  75. /*     ULONG  msg;  = PM Message                                        */
  76. /*     MPARAM mp1;  = Message Parameter 1                               */
  77. /*     MPARAM mp2;  = Message Parameter 2                               */
  78. /*                                                                      */
  79. /*     Upon Exit:                                                       */
  80. /*                                                                      */
  81. /* -------------------------------------------------------------------- */
  82. MRESULT EXPENTRY FrameWndProc( HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  83. {
  84.   switch ( msg )
  85.   {
  86.     case WM_FORMATFRAME :
  87.     {
  88.       /******************************************************************/
  89.       /* Query the number of standard frame controls                    */
  90.       /******************************************************************/
  91.       ULONG ulStdCtlCount = (ULONG)DefFrameWndProc( hWnd, msg, mp1, mp2 );
  92.       ULONG ulIdx = ulStdCtlCount;
  93.  
  94.       /******************************************************************/
  95.       /* Access the SWP array that is passed to us                      */
  96.       /******************************************************************/
  97.       ULONG i;
  98.       PSWP swpArr = (PSWP)mp1;
  99.  
  100.       for (i=0; i < ulStdCtlCount; i++)
  101.       {
  102.         if ( WinQueryWindowUShort( swpArr[i].hwnd, QWS_ID ) == FID_TITLEBAR )
  103.         {
  104.           /**************************************************************/
  105.           /* Initialize the SWPs for our graphic button controls.       */
  106.           /* Since the SWP array for the std frame controls is 0-based  */
  107.           /* and occupy indexes 0 thru n-1 (where n is the total        */
  108.           /* count), we start with index n for our graphic button       */
  109.           /* controls.                                                  */
  110.           /**************************************************************/
  111.           /**************************************************************/
  112.           /* These values are the same for both controls, so we init    */
  113.           /* them all at once.  Please note that the width and height   */
  114.           /* of our buttons is the same as the height of the title bar. */
  115.           /**************************************************************/
  116.           swpArr[ulIdx+1].fl = swpArr[ulIdx].fl =
  117.                                SWP_MOVE | SWP_SIZE | SWP_NOADJUST;
  118.           swpArr[ulIdx+1].cy = swpArr[ulIdx].cy = swpArr[i].cy;
  119.           swpArr[ulIdx+1].cx = swpArr[ulIdx].cx = swpArr[i].cy;
  120.           swpArr[ulIdx+1].y  = swpArr[ulIdx].y  = swpArr[i].y;
  121.           swpArr[ulIdx+1].hwndInsertBehind = swpArr[ulIdx].hwndInsertBehind =
  122.                                              HWND_TOP;
  123.  
  124.           /**************************************************************/
  125.           /* Set the x-position for the close graphic button, and set   */
  126.           /* its window handle.                                         */
  127.           /**************************************************************/
  128.           swpArr[ulIdx].x = swpArr[i].x;
  129.           swpArr[ulIdx].hwnd = hwndCloseBtn;
  130.  
  131.           /**************************************************************/
  132.           /* Calculate the x-position for the help graphic button, and  */
  133.           /* set its window handle.                                     */
  134.           /**************************************************************/
  135.           swpArr[ulIdx+1].x = swpArr[i].x + swpArr[i].cx - swpArr[ulIdx+1].cx;
  136.           swpArr[ulIdx+1].hwnd = hwndHelpBtn;
  137.  
  138.           /**************************************************************/
  139.           /* Adjust the x-position and width of the title bar to        */
  140.           /* accomodate our graphic button controls.                    */
  141.           /**************************************************************/
  142.           swpArr[i].x  += swpArr[i].cy;
  143.           swpArr[i].cx -= (swpArr[ulIdx].cx * 2);
  144.           break;
  145.         }
  146.       }
  147.  
  148.       /******************************************************************/
  149.       /* Increment the number of frame controls to include our graphic  */
  150.       /* button control.                                                */
  151.       /******************************************************************/
  152.       return( (MRESULT)(ulIdx + 2) );
  153.     }
  154.  
  155.     case WM_QUERYFRAMECTLCOUNT :
  156.       /******************************************************************/
  157.       /* Query the standard frame controls count and increment to       */
  158.       /* include our graphic button controls.                           */
  159.       /******************************************************************/
  160.       return( (MRESULT)((ULONG)DefFrameWndProc( hWnd, msg, mp1, mp2 ) + 2) );
  161.  
  162.  
  163.     case WM_SYSCOMMAND :
  164.       /******************************************************************/
  165.       /* Process a click on the close graphic button.                   */
  166.       /******************************************************************/
  167.       if ( ((USHORT)mp1 == CLOSE_BUTTON_ID) &&
  168.            (SHORT1FROMMP(mp2) == CMDSRC_PUSHBUTTON) )
  169.       {
  170.         /****************************************************************/
  171.         /* Close the frame extensions sample application.               */
  172.         /****************************************************************/
  173.         WinPostMsg( hWnd, WM_CLOSE, 0, 0 );
  174.       }
  175.       else
  176.       {
  177.         return( DefFrameWndProc( hWnd, msg, mp1, mp2 ) );
  178.       }
  179.       break;
  180.  
  181.     case WM_HELP :
  182.       /******************************************************************/
  183.       /* Process a click on the help graphic button.                    */
  184.       /******************************************************************/
  185.       if ( (USHORT)mp1 == HELP_BUTTON_ID )
  186.       {
  187.         /****************************************************************/
  188.         /* Invalidate the min/max control to repaint the area that the  */
  189.         /* help button clips when you click on it.                      */
  190.         /****************************************************************/
  191.         WinInvalidateRect( WinWindowFromID( hWnd, FID_MINMAX ), NULL, FALSE );
  192.  
  193.         /****************************************************************/
  194.         /* Display the help panel for this sample.                      */
  195.         /****************************************************************/
  196.         return( WinSendMsg( WinQueryHelpInstance( hWnd ),
  197.                             HM_DISPLAY_HELP,
  198.                             mp1,
  199.                             HM_RESOURCEID ) );
  200.       }
  201.  
  202.     default:
  203.       return( DefFrameWndProc( hWnd, msg, mp1, mp2 ) );
  204.   }
  205.  
  206.   return( (MRESULT)FALSE );
  207. }
  208.  
  209.  
  210. /* --- main ----------------------------------------------------------- */
  211. /*     Main function.                                                   */
  212. /* -------------------------------------------------------------------- */
  213. int main( int argc, char* argv[] )
  214. {
  215.   HAB      hAB;                    /* Anchor Block Handle               */
  216.   HMQ      hMQ;                    /* Message Queue Handle              */
  217.   HWND     hwndClient;             /* Client Handle                     */
  218.   HWND     hwndFrame;              /* Frame Handle                      */
  219.   QMSG     qmsg;                   /* PM Message Queue Holder           */
  220.   ULONG    flCreateFlags;          /* Window Creation Flags             */
  221.   LONG     lClr;                   /* Colour Holder                     */
  222.   HWND     hwndHelp;               /* Help Instance Handle              */
  223.   HELPINIT helpInit;               /* Help Instance Structure           */
  224.  
  225.   /**********************************************************************/
  226.   /* Initialize the program for PM, create the message queue, and set   */
  227.   /* the codepage.                                                      */
  228.   /**********************************************************************/
  229.   hAB = WinInitialize( 0 );
  230.   hMQ = WinCreateMsgQueue( hAB, 0 );
  231.   WinSetCp( hMQ, 850 );
  232.  
  233.   /**********************************************************************/
  234.   /* Create a standard frame window, specifying a static text control   */
  235.   /* for the client area.                                               */
  236.   /**********************************************************************/
  237.   flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU | FCF_SIZEBORDER |
  238.                   FCF_MINMAX | FCF_VERTSCROLL | FCF_HORZSCROLL |
  239.                   FCF_SHELLPOSITION | FCF_TASKLIST;
  240.  
  241.   hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
  242.                                   0,
  243.                                   &flCreateFlags,
  244.                                   WC_STATIC,
  245.                                   "Frame Extensions",
  246.                                   (WS_VISIBLE | SS_TEXT | DT_CENTER |
  247.                                    DT_VCENTER),
  248.                                   (HMODULE)0L,
  249.                                   FRAME_WND_ID,
  250.                                   &hwndClient );
  251.   if ( !hwndFrame )
  252.     return( TRUE );
  253.  
  254.   /**********************************************************************/
  255.   /* Set the text for the static text control as well as the            */
  256.   /* background color of the control.                                   */
  257.   /**********************************************************************/
  258.   lClr = SYSCLR_DIALOGBACKGROUND;
  259.   WinSetPresParam(hwndClient, PP_BACKGROUNDCOLORINDEX, 4UL, &lClr);
  260.  
  261.   WinSetWindowText( hwndClient, "Frame Extensions Test" );
  262.  
  263.   /**********************************************************************/
  264.   /* Create and associate the help instance.                            */
  265.   /**********************************************************************/
  266.   helpInit.cb                       = sizeof(HELPINIT);
  267.   helpInit.ulReturnCode             = 0;
  268.   helpInit.pszTutorialName          = 0;
  269.   helpInit.phtHelpTable             = (PHELPTABLE)MAKELONG(0, 0xffff);
  270.   helpInit.hmodHelpTableModule      = 0;
  271.   helpInit.hmodAccelActionBarModule = 0;
  272.   helpInit.idAccelTable             = 0;
  273.   helpInit.idActionBar              = 0;
  274.   helpInit.pszHelpWindowTitle       = "Frame Extensions Sample";
  275.   helpInit.fShowPanelId             = CMIC_HIDE_PANEL_ID;
  276.   helpInit.pszHelpLibraryName       = "framectl.hlp";
  277.  
  278.   hwndHelp = WinCreateHelpInstance( hAB, &helpInit );
  279.   if ( !hwndHelp )
  280.     return( TRUE );
  281.  
  282.   if ( !WinAssociateHelpInstance( hwndHelp, hwndFrame ) )
  283.     return( TRUE );
  284.  
  285.   /**********************************************************************/
  286.   /* Create the close graphic button which we will use as a frame       */
  287.   /* extension.                                                         */
  288.   /**********************************************************************/
  289.   hwndCloseBtn = WinCreateWindow( hwndFrame,
  290.                                   WC_BUTTON,
  291.                                   "#200",
  292.                                   (BS_BITMAP | BS_PUSHBUTTON | BS_NOBORDER |
  293.                                    BS_NOPOINTERFOCUS | BS_AUTOSIZE |
  294.                                    BS_SYSCOMMAND | WS_VISIBLE),
  295.                                   0L, 0L, -1L, -1L,
  296.                                   hwndFrame,
  297.                                   HWND_TOP,
  298.                                   CLOSE_BUTTON_ID,
  299.                                   (PVOID)NULL,
  300.                                   (PVOID)NULL );
  301.   if ( !hwndCloseBtn )
  302.     return( TRUE );
  303.  
  304.   /**********************************************************************/
  305.   /* Create the help graphic button which we will use as a frame        */
  306.   /* extension.                                                         */
  307.   /**********************************************************************/
  308.   hwndHelpBtn = WinCreateWindow( hwndFrame,
  309.                                  WC_BUTTON,
  310.                                  "#300",
  311.                                  (BS_BITMAP | BS_PUSHBUTTON | BS_NOBORDER |
  312.                                   BS_NOPOINTERFOCUS | BS_AUTOSIZE |
  313.                                   BS_HELP | WS_VISIBLE),
  314.                                  0L, 0L, -1L, -1L,
  315.                                  hwndFrame,
  316.                                  HWND_TOP,
  317.                                  HELP_BUTTON_ID,
  318.                                  (PVOID)NULL,
  319.                                  (PVOID)NULL );
  320.   if ( !hwndHelpBtn )
  321.     return( TRUE );
  322.  
  323.   /**********************************************************************/
  324.   /* Subclass the frame control.  The subclass procedure is where we    */
  325.   /* will add the frame extensions during processing of WM_FORMATFRAME. */
  326.   /**********************************************************************/
  327.   DefFrameWndProc = WinSubclassWindow( hwndFrame, (PFNWP)FrameWndProc );
  328.  
  329.   if ( !DefFrameWndProc )
  330.     return( TRUE );
  331.  
  332.   /**********************************************************************/
  333.   /* Indicate to PM that the frame needs updating.                      */
  334.   /**********************************************************************/
  335.   WinSendMsg( hwndFrame, WM_UPDATEFRAME, (MPARAM)~0, NULL );
  336.  
  337.   /**********************************************************************/
  338.   /* Show the frame since we have finished formatting it.               */
  339.   /**********************************************************************/
  340.   WinShowWindow( hwndFrame, TRUE );
  341.  
  342.   /**********************************************************************/
  343.   /* Message dispatch loop.                                             */
  344.   /**********************************************************************/
  345.   while ( WinGetMsg( hAB, &qmsg, (HWND)NULL, 0, 0 ) )
  346.     WinDispatchMsg( hAB, &qmsg );
  347.  
  348.   /**********************************************************************/
  349.   /* Termination processing                                             */
  350.   /**********************************************************************/
  351.   WinDestroyHelpInstance( hwndHelp );
  352.   WinDestroyWindow( hwndFrame );
  353.   WinDestroyMsgQueue( hMQ );
  354.   WinTerminate( hAB );
  355.   return( FALSE );
  356. }
  357.  
  358.