home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / anbt2.zip / TOOLBAR.C < prev    next >
C/C++ Source or Header  |  1993-10-08  |  20KB  |  430 lines

  1. /*______________________________________________________________________
  2. | ToolBar    05-15-93 Greg Ratajik                                      |
  3. |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
  4. | This program shows how to use the AniButtn DLL calls to use           |
  5. | animated pushbuttons.  This version is for SVGS mode.                 |
  6. | See ANIBUTTN.DOC for more information. This is the OS/2 2.0 Version   |
  7. |                                                                       |
  8. |_____________________________________________________________________*/
  9. #define INCL_PM
  10. #define INCL_WINSWITCHLIST
  11.  
  12. /*______________________________________________________________________
  13. |                                                                       |
  14. |                         System Includes                               |
  15. |_____________________________________________________________________*/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include <os2.h>
  21.  
  22. /*______________________________________________________________________
  23. |                                                                       |
  24. |             Application Specific Includes & Defines                   |
  25. |_____________________________________________________________________*/
  26. #include "toolbar.rch"
  27. #include "AniButtn.h"
  28.  
  29. /*______________________________________________________________________
  30. |                                                                       |
  31. |  Gobal Local Variables                        |
  32. |_____________________________________________________________________*/
  33. HSWITCH  hSwitch;          /* Task switch                          */
  34. SWCNTRL  Swctl;            /* Task switch                          */
  35. CHAR     szAppName[20];    /* Window creation                      */
  36. HAB      hAB;              /* Handle to anchor block               */
  37. HMQ      hMQ;              /* Handle to message Queue              */
  38. HWND     hWndFrame;        /* Handle to main shell's frame         */
  39. HWND     hWndClient;       /* Handle to main shell's client area   */
  40.  
  41. /*____________________________________________________________________
  42. |                                      |
  43. |  Function Prototypes.                           |
  44. |____________________________________________________________________*/
  45. MRESULT EXPENTRY WndProc        ( HWND, ULONG, MPARAM, MPARAM );
  46. MRESULT EXPENTRY ToolBar        ( HWND, ULONG, MPARAM, MPARAM );
  47. MRESULT EXPENTRY SENDChatter    ( HWND, ULONG, MPARAM, MPARAM );
  48.  
  49. HWND CreateWindow(HWND,ULONG,PCH,PCH,USHORT,INT,INT,INT,INT,PHWND,ULONG,USHORT );
  50.  
  51. /*___________________________________________________________________________
  52. |                                                                            |
  53. |    Function: Main                                 |
  54. |                                                                            |
  55. |      Return:    SHORT                                 |
  56. |                                                                            |
  57. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  58. |                 C H A N G E    L O G                 |
  59. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  60. |                                                                            |
  61. |  INT.     DATE      DESCRIPTION                                            |
  62. |  ----  ----------   ---------------------------------------------------    |
  63. |  GWR   05-15-1993   Initial Developement                                   |
  64. |___________________________________________________________________________*/
  65. main(int argc, char *argv[])
  66. {
  67. static CHAR   szTitle[13];
  68.        QMSG   qmsg;
  69.        ULONG  flCreate = FCF_TITLEBAR     |
  70.                          FCF_SYSMENU      ;
  71.        SEL    sel;
  72.        TID    tid;
  73.  
  74.  argc = argc;
  75.  argv = argv;
  76.  
  77.  if((hAB = WinInitialize(0)) == 0)
  78.     return(FALSE);
  79.   
  80.  if((hMQ = WinCreateMsgQueue(hAB, 0)) == 0)
  81.     return(FALSE);
  82.  
  83.  if(!RegisterClass())
  84.     return(FALSE);
  85.  
  86.  WinLoadString(hAB, 0, IDS_TITLE, 13, szTitle);
  87.  hWndFrame = WinCreateStdWindow(HWND_DESKTOP,
  88.                                 WS_VISIBLE | WS_MAXIMIZED,
  89.                                 &flCreate,
  90.                                 "ToolBar",
  91.                                 "ToolBar",
  92.                                 WS_MAXIMIZED,
  93.                                 (HMODULE)NULL,
  94.                                 ID_CHATTER,
  95.                                 &hWndClient);
  96.  
  97.  /*___________________________________
  98.  |                      |
  99.  | Provide switch info so          |
  100.  | ChangeTaskList will work          |
  101.  |___________________________________*/
  102.  {
  103.   PSWCNTRL psw;
  104.   PHSWITCH phsw;
  105.   PID       pid;
  106.   SWCNTRL  swctlSwitchList[10];
  107.   HSWITCH  hswSwitch;
  108.   CHAR     szSwitchTitle[50];
  109.  
  110.   psw =  &swctlSwitchList[0];
  111.   phsw = &hswSwitch;
  112.  
  113.   WinQueryWindowProcess(hWndFrame, &pid, NULL);
  114.  
  115.   strcpy(szSwitchTitle, "ToolBar");
  116.   strcpy(swctlSwitchList[0].szSwtitle, szSwitchTitle);
  117.  
  118.  WinQueryWindowProcess(hWndFrame, &pid, &tid);
  119.  Swctl.hwnd = hWndFrame;                         /* Frame window handle    */
  120.  Swctl.idProcess = pid;                          /* Process identifier     */
  121.  Swctl.uchVisibility = SWL_VISIBLE;              /* visibility             */
  122.  Swctl.fbJump = SWL_JUMPABLE;                    /* Jump indicator         */
  123.  strcpy(Swctl.szSwtitle, szTitle);               /* Frame window title     */
  124.  hSwitch = WinAddSwitchEntry(&Swctl);
  125.  
  126.  hswSwitch = WinAddSwitchEntry(&swctlSwitchList[0]);
  127.  }
  128.  
  129.  /* The following is the message loop for the application.                 */
  130.  while(WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  131.        WinDispatchMsg(hAB,(PQMSG)&qmsg);
  132.  
  133.  WinDestroyWindow(hWndFrame); /* Destroy the frame window                  */
  134.  
  135.  WinDestroyMsgQueue(hMQ);     /* Destroy this application's message queue  */
  136.  WinTerminate(hAB);           /* Terminate this application's use of the   */
  137.                               /* Presentation Manager resources            */
  138. } /* end of main */
  139.  
  140. /*___________________________________________________________________________
  141. |                                                                            |
  142. |    Function: WndProc                                                       |
  143. |                                                                            |
  144. | Description: Main window proc for Toolbar Example                          |
  145. |                                         |
  146. |      Return:    SHORT                                 |
  147. |                                                                            |
  148. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  149. |                 C H A N G E    L O G                 |
  150. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  151. |                                                                            |
  152. |  INT.     DATE      DESCRIPTION                                            |
  153. |  ----  ----------   ---------------------------------------------------    |
  154. |  GWR   05-15-1993   Initial Developement                                   |
  155. |___________________________________________________________________________*/
  156. MRESULT EXPENTRY WndProc(HWND hWnd, ULONG message, MPARAM mp1, MPARAM mp2)
  157. {
  158.    HPS    hPS;          /* Handle for the Presentation Space              */
  159.    RECTL  rClient;      /* Handle to rectangle formed by client area      */
  160.    USHORT rc;
  161.  
  162.    switch(message)
  163.      {
  164.       case WM_COMMAND:
  165.            switch(SHORT1FROMMP(mp1))
  166.             {
  167.             }
  168.            break; /* End of WM_COMMAND */
  169.  
  170.       case WM_CREATE:
  171.            /*_____________________________________
  172.            |                                      |
  173.            | Start the main dialog box off.       |
  174.            |                                      |
  175.            |_____________________________________*/
  176.            rc = (USHORT) WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, (PFNWP)ToolBar,
  177.                                     0, DLG_TOOLBAR, NULL);
  178.  
  179.            WinPostMsg(hWndClient, WM_QUIT,0L,0L);
  180.            return(0);
  181.  
  182.            break; /* End of WM_CREATE */
  183.  
  184.       case WM_MOUSEMOVE:
  185.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  186.            break;
  187.  
  188.       case WM_PAINT:    /* code for the window's client area               */
  189.            /* Obtain a handle to a cache presentation space                */
  190.            hPS = WinBeginPaint(hWnd, 0, 0);
  191.  
  192.            /* Determine the size of the client area                        */
  193.            WinQueryWindowRect(hWnd, &rClient);
  194.  
  195.            /* Fill the background with the default background color        */
  196.            WinFillRect(hPS, &rClient, CLR_BACKGROUND);
  197.  
  198.            /* return presentation space to state before WinBeginPaint      */
  199.            WinEndPaint(hPS);
  200.            break; /* End of WM_PAINT */
  201.  
  202.  
  203.       case WM_CLOSE:  /* close the window                                  */
  204.            WinPostMsg(hWndClient, WM_QUIT,0L,0L);
  205.            if(hWnd != hWndClient)
  206.              break;
  207.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  208.    }
  209.    return(0L);
  210. } /* End of WndProc */
  211.  
  212. /*___________________________________________________________________________
  213. |                                                                            |
  214. |    Function: ToolBar                                                       |
  215. |                                                                            |
  216. | Description: Toolbar DLG Message proc.                                     |
  217. |                                         |
  218. |                                         |
  219. |      Return: VOID                                 |
  220. |                                                                            |
  221. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  222. |                 C H A N G E    L O G                 |
  223. | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  |
  224. |                                                                            |
  225. |  INT.     DATE      DESCRIPTION                                            |
  226. |  ----  ----------   ---------------------------------------------------    |
  227. |  GWR   11-02-1993   Initial Developement                                   |
  228. |___________________________________________________________________________*/
  229. MRESULT EXPENTRY ToolBar(HWND hWndDlg,
  230.                          ULONG message,
  231.                          MPARAM mp1,
  232.                          MPARAM mp2)
  233. {
  234.  static HWND   hWndParent;
  235.  
  236.  switch(message)
  237.    {
  238.     case WM_INITDLG:
  239.          hWndParent = (HWND)mp2;
  240.  
  241.          /*___________________________________
  242.          |                                    |
  243.          | Create the Animated pushbuttons.   |
  244.          |                                    |
  245.          |___________________________________*/
  246.          AniCreateButton(hWndDlg,                   /* Handle of Dialog    */
  247.                          TBB_FILE,                  /* ID of control       */
  248.                          ID_INFO1,                  /* ID of UP bitmap     */
  249.                          ID_INFO2,                  /* ID of DOWN bitmap   */
  250.                          68,                        /* X Size of bitmaps   */
  251.                          31,                        /* Y Size of bitmaps   */
  252.                          "This is the ABOUT Button",/* Status bar text     */
  253.                          TX_TBB_HELP);              /* ID of status bar    */
  254.  
  255.          AniCreateButton(hWndDlg, TBB_NEXT, ID_NEXT1, ID_NEXT2,  68, 31, "This is the NEXT Button.", TX_TBB_HELP);
  256.          AniCreateButton(hWndDlg, TBB_LAST, ID_LAST1, ID_LAST2,  68, 31, "This is the LAST Button.", TX_TBB_HELP);
  257.          AniCreateButton(hWndDlg, TBB_NEW , ID_EYE1 , ID_EYE2 ,  68, 31, "This is the INFORMATION Button.", TX_TBB_HELP);
  258.          AniCreateButton(hWndDlg, TBB_EXIT, ID_EXIT1, ID_EXIT2,  68, 31, "This is the EXIT Button.", TX_TBB_HELP);
  259.          AniCreateButton(hWndDlg, TBB_NA1,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  260.          AniCreateButton(hWndDlg, TBB_NA2,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  261.          AniCreateButton(hWndDlg, TBB_NA3,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  262.          AniCreateButton(hWndDlg, TBB_NA4,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  263.          AniCreateButton(hWndDlg, TBB_NA5,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  264.          AniCreateButton(hWndDlg, TBB_NA6,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  265.          AniCreateButton(hWndDlg, TBB_NA7,  ID_NA1,   ID_NA2 ,   68, 31, "This button is not Currently used.  Try clicking on one of the other buttons.  Click the EXIT button to stop the test.", TX_TBB_HELP);
  266.  
  267.          break; /* End of WM_INITDLG */
  268.    
  269.     case WM_CONTROL:
  270.          switch(SHORT1FROMMP(mp1))
  271.            {
  272.            }
  273.          break; /* End of WM_CONTROL */
  274.  
  275.     case WM_COMMAND:
  276.          switch(SHORT1FROMMP(mp1))
  277.            {
  278.             /*___________________________________
  279.             |                                    |
  280.             | The following messages are just    |
  281.             | so we can verify the button is     |
  282.             | working correctly.                 |
  283.             |___________________________________*/
  284.             case TBB_FILE:
  285.                   WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
  286.                                    "ToolBar Button Pressed.",
  287.                                    "This is Greg Ratajiks nifty Toolbar test! (10/8/93)",
  288.                                    0, MB_NOICON | MB_OK );
  289.  
  290.                   break;
  291.  
  292.             case TBB_NEXT:
  293.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NEXT Toolbutton", 0, MB_NOICON | MB_OK );
  294.                   break;
  295.  
  296.             case TBB_LAST:
  297.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the LAST Toolbutton", 0, MB_NOICON | MB_OK );
  298.                   break;
  299.  
  300.             case TBB_NEW :
  301.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the INFORMATION Toolbutton", 0, MB_NOICON | MB_OK );
  302.                   break;
  303.  
  304.             case TBB_EXIT:
  305.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed", "You Have pressed the EXIT Toolbutton", 0, MB_NOICON | MB_OK );
  306.                   WinDismissDlg(hWndDlg, FALSE);
  307.                   break;
  308.  
  309.             case TBB_NA1 :
  310.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA1  Toolbutton", 0, MB_NOICON | MB_OK );
  311.                   break;
  312.  
  313.             case TBB_NA2 :
  314.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA2  Toolbutton", 0, MB_NOICON | MB_OK );
  315.                   break;
  316.  
  317.             case TBB_NA3 :
  318.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA3  Toolbutton", 0, MB_NOICON | MB_OK );
  319.                   break;
  320.  
  321.             case TBB_NA4 :
  322.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA4  Toolbutton", 0, MB_NOICON | MB_OK );
  323.                   break;
  324.  
  325.             case TBB_NA5 :
  326.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA5  Toolbutton", 0, MB_NOICON | MB_OK );
  327.                   break;
  328.  
  329.             case TBB_NA6 :
  330.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA6  Toolbutton", 0, MB_NOICON | MB_OK );
  331.                   break;
  332.  
  333.             case TBB_NA7 :
  334.                   WinMessageBox(HWND_DESKTOP, hWndDlg, "ToolBar Button Pressed.", "You Have pressed the NA7  Toolbutton", 0, MB_NOICON | MB_OK );
  335.                   break;
  336.  
  337.            }
  338.          break; /* End of WM_COMMAND */
  339.  
  340.     case WM_CLOSE:
  341.          /*___________________________________
  342.          |                                    |
  343.          | AniButtn uses a linked list to keep|
  344.          | track of everything.  This API will|
  345.          | delete the node for this button.   |
  346.          |___________________________________*/
  347.          AniDeleteButton(hWndDlg, TBB_NEXT);
  348.          AniDeleteButton(hWndDlg, TBB_LAST);
  349.          AniDeleteButton(hWndDlg, TBB_NEW );
  350.          AniDeleteButton(hWndDlg, TBB_EXIT);
  351.          AniDeleteButton(hWndDlg, TBB_NA1 );
  352.          AniDeleteButton(hWndDlg, TBB_NA2 );
  353.          AniDeleteButton(hWndDlg, TBB_NA3 );
  354.          AniDeleteButton(hWndDlg, TBB_NA4 );
  355.          AniDeleteButton(hWndDlg, TBB_NA5 );
  356.          AniDeleteButton(hWndDlg, TBB_NA6 );
  357.          AniDeleteButton(hWndDlg, TBB_NA7 );
  358.  
  359.          WinDismissDlg(hWndDlg, FALSE);
  360.          break; /* End of WM_CLOSE */
  361.            
  362.     default:
  363.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  364.          break;
  365.    }
  366.  return FALSE;
  367. } /* End of CHATTERBox */
  368.  
  369.  
  370. /*___________________________________________________________________________
  371. |                                                                            |
  372. |    Function: CreateWindow                                                  |
  373. |___________________________________________________________________________*/
  374. HWND CreateWindow(HWND   hWndParent,
  375.                   ULONG  ctldata,
  376.                   PCH    appname,
  377.                   PCH    title,
  378.                   USHORT ResID,
  379.                   INT    x,
  380.                   INT    y,
  381.                   INT    cx,
  382.                   INT    cy,
  383.                   PHWND  hWndClient,
  384.                   ULONG  lfStyle,
  385.                   USHORT uSizeStyle)
  386.  
  387. {
  388.    HWND   hWndFrame;
  389.  
  390.    hWndFrame = WinCreateStdWindow(hWndParent,
  391.                                   lfStyle,
  392.                                   &ctldata,
  393.                                   appname,
  394.                                   title,
  395.                                   WS_MAXIMIZED,
  396.                                   0,
  397.                                   ResID,
  398.                                   (HWND FAR *)hWndClient);
  399.  
  400.    if(hWndFrame == 0)
  401.      {
  402.       WinMessageBox(HWND_DESKTOP, hWndParent, "Error Creating Window!",
  403.                     0, 0, MB_OK|MB_ICONEXCLAMATION);
  404.       return((HWND)0);
  405.      }
  406.  
  407.    return(hWndFrame);
  408. }  /* End of CreateWindow */
  409.  
  410. /*___________________________________________________________________________
  411. |                                                                            |
  412. |    Function: RegisterClass                                                 |
  413. |___________________________________________________________________________*/
  414. INT RegisterClass(VOID)
  415. {
  416.  INT rc;
  417.  
  418.  WinLoadString(hAB, 0, IDS_APP_NAME, 80, szAppName);
  419.  rc = WinRegisterClass(hAB,
  420.               (PCH)"ToolBar",
  421.                       (PFNWP)WndProc,
  422.                       CS_SIZEREDRAW ,
  423.                       0);
  424.  if (rc == FALSE)
  425.    return(FALSE);
  426.  
  427.  
  428.  return(TRUE);
  429. } /* End of RegisterClass */
  430.