home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mclb.zip / lb.pak / SAMPLES / SAMP6 / samp6.C < prev    next >
Text File  |  1995-10-29  |  14KB  |  261 lines

  1. /***************************************************************************/
  2. /***************************************************************************/
  3. /*                        DISCLAIMER OF WARRANTIES.                        */
  4. /***************************************************************************/
  5. /***************************************************************************/
  6. /*                                                                         */
  7. /*  Copyright (C) 1995 IBM Corporation                                     */
  8. /*                                                                         */
  9. /*      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        */
  10. /*      sample code created by IBM Corporation. This sample code is not    */
  11. /*      part of any standard or IBM product and is provided to you solely  */
  12. /*      for  the purpose of assisting you in the development of your       */
  13. /*      applications.  The code is provided "AS IS", without               */
  14. /*      warranty of any kind.  IBM shall not be liable for any damages     */
  15. /*      arising out of your use of the sample code, even if they have been */
  16. /*      advised of the possibility of such damages.                        */
  17. /***************************************************************************/
  18. /*                                                                         */
  19. /* Author:         Mark McMillan                                           */
  20. /*                 IBM Corporation                                         */
  21. /*                                                                         */
  22. /***************************************************************************/
  23.  
  24. /*---------------------------------------------------------------------------
  25.                              Sample #6
  26.  
  27.   This is just a basic sample that shows a non-sizable MCLB using some
  28.   different fonts and colors.
  29.  
  30. ---------------------------------------------------------------------------*/
  31.  
  32.  
  33. #define  INCL_BASE        
  34. #define  INCL_WIN         
  35. #define  INCL_DOS         
  36. #define  INCL_WINSTDSPIN  
  37.                           
  38. #include <os2.h>          
  39. #include <string.h>       
  40. #include <stdio.h>        
  41. #include <stdlib.h>       
  42.  
  43. #include "mclb.h"               // MCLB definitions
  44.                           
  45. #include "DIALOG.H"       
  46.  
  47. #define  ID_MCLB   500          // ID of MCLB control
  48.                           
  49. /* General Dialog Helper Macros */    
  50. #define CONTROLID               SHORT1FROMMP(mp1)                                                  
  51. #define CONTROLCODE             SHORT2FROMMP(mp1)                                                  
  52. #define CONTROLHWND(ID)         WinWindowFromID(hwnd,ID)                                           
  53.  
  54. HAB hab;                        // Application anchor block
  55. HMQ MyQ;                        // Application message queue
  56. HWND MCLBHwnd;                  // Handle of MCLB control
  57. char Buff[100];                 // Msg buffer
  58. SHORT Item;                     // Item index
  59.  
  60. MRESULT EXPENTRY ID_MAINDLG_Proc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  61.  
  62. /*----------------------------------------------------------------------------*/
  63. MRESULT EXPENTRY ID_MAINDLG_Proc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 
  64. /*----------------------------------------------------------------------------*/
  65. /* Dialog procedure for main window dialog.                                   */
  66. /*----------------------------------------------------------------------------*/
  67. {                                                                               
  68.                                                                                 
  69.   switch (msg) {                                                                
  70.                                                                                 
  71.     case WM_INITDLG: {
  72.       /* Create the MCLB before the dialog window is displayed.  We don't */
  73.       /* have to worry about sizing it now since we will get and process  */
  74.       /* a WM_WINDOWPOSCHANGED message before the window becomes visible. */
  75.  
  76.       MCLBINFO InitData;
  77.       LONG InitSizeList[3]= {3L, 1L};  // Make col 1 twice as big as 2 and 3
  78.  
  79.       /* Initialize MCLB create data structure */
  80.  
  81.       memset(&InitData, 0x00, sizeof(MCLBINFO));
  82.       // These are the only required initialization values:
  83.       InitData.Size = sizeof(MCLBINFO);
  84.       InitData.Cols = 2;
  85.       InitData.TabChar = '!';
  86.       InitData.Titles = "Component!Installed";
  87.       InitData.InitSizes= InitSizeList;  // Initial sizes (proportions)
  88.  
  89.       InitData.TitleBColor = 0x00FFFF00;     
  90.       InitData.TitleFColor = 0x00000000;
  91.       InitData.ListBColor = 0x0080FFFF;
  92.       InitData.ListFColor = 0x00000000;
  93.       strcpy(InitData.ListFont, "8.Helv");
  94.       strcpy(InitData.TitleFont, "10.Helvetica Bold Italic");
  95.  
  96.       /* Now create the MCLB.  The dialog window is the parent (so it */
  97.       /* draws on the dialog), and owner (so this dialog proc will    */
  98.       /* get messages from it).                                       */
  99.  
  100.       MCLBHwnd = MCLBCreateWindow(
  101.                  hwnd,                    // Parent window
  102.                  hwnd,                    // Owner to recv messages
  103.                  WS_VISIBLE|              // Styles: Make it visible
  104.                    WS_TABSTOP|              // Let user TAB to it
  105.                    MCLBS_SIZEMETHOD_PROP|   // Proportional sizing when window is sized
  106.                    MCLBS_NOCOLRESIZE,       // Give each column a horizontal scroll bar
  107.                  0,0,100,100,             // Will set size later, but must have large horz size now
  108.                  HWND_TOP,                // Put on top of any sibling windows
  109.                  ID_MCLB,                 // Window ID
  110.                  &InitData);              // MCLB create structure
  111.  
  112.       /* Insert data into the MCLB.  Each LM_INSERTITEM inserts a single */
  113.       /* row.  Columns are separated with the TabChar supplied above     */
  114.       /* (an "!" for our sample here).                                   */
  115.  
  116.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Comm Subsystem!Yes"));
  117.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("User Interface!Yes"));
  118.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Utilites!No"));
  119.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Import/Export!No"));
  120.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("XIO Support!Yes"));
  121.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("System Links!No"));
  122.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Online Help!Yes"));
  123.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Publications!Yes"));
  124.       WinSendMsg(MCLBHwnd, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP("Tutorial!No"));
  125.  
  126.       return FALSE;                                                             
  127.       } // end of WM_INITDLG
  128.                                                                                 
  129.     case WM_COMMAND:
  130.       switch (SHORT1FROMMP(mp1)) {                                              
  131.         case DID_OK: /*----------~OK (PUSHBUTTON)----------*/                   
  132.           /* Since our main window is a dialog, don't let default dialog */
  133.           /* proc dismiss us or focus will not always return to the      */
  134.           /* proper application.  Instead, destroy ourselves.  This is   */
  135.           /* a trick to properly using a dialog for a main window.       */
  136.           WinDestroyWindow(hwnd);
  137.           return 0;
  138.       }                                                                         
  139.       break;                                                                    
  140.                                                                                 
  141.     case WM_CONTROL:                                                            
  142.       switch SHORT1FROMMP(mp1) {                                                
  143.         case ID_MCLB: 
  144.  
  145.           /* Process control messages from the MCLB.  Most of them are */
  146.           /* standard listbox messages with the same meaning as usual. */
  147.           /* There are also a few MCLB-specific control messages.      */
  148.  
  149.           switch SHORT2FROMMP(mp1) {
  150.             case LN_SELECT:
  151.  
  152.               /* User selected or unselected an entry in the MCLB.  Our   */
  153.               /* sample uses a single-select listbox.                     */
  154.  
  155.               Item = SHORT1FROMMR(WinSendMsg(MCLBHwnd, LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPVOID));
  156.               if (Item >= 0)
  157.                 sprintf(Buff, "Item %i selected", Item);
  158.               else
  159.                 strcpy(Buff, "Unable to query selection.");
  160.               WinSetDlgItemText(hwnd, ID_MSG, Buff);
  161.               return 0;
  162.  
  163.             case LN_ENTER:
  164.  
  165.               /* User double-clicked or pressed ENTER in the MCLB. */
  166.  
  167.               Item = SHORT1FROMMR(WinSendMsg(MCLBHwnd, LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPVOID));
  168.               if (Item >= 0)
  169.                 sprintf(Buff, "Item %i entered", Item);
  170.               else
  171.                 strcpy(Buff, "Unable to query selection.");
  172.               WinSetDlgItemText(hwnd, ID_MSG, Buff);
  173.               return 0;
  174.  
  175.             case MCLBN_COLSIZED: {
  176.  
  177.               /* The user has changed the relative column sizings using one */
  178.               /* of the split bars.  Note we do not get this message when   */
  179.               /* the entire MCLB is resized with the window, only when the  */
  180.               /* user moves a splitbar.                                     */
  181.  
  182.               LONG SizeList[3];
  183.               WinSendMsg(MCLBHwnd, MCLB_QUERYCOLSIZES, MPFROMP(SizeList), MPVOID);
  184.               sprintf(Buff, "Columns resized to (%li, %li, %li)", SizeList[0], SizeList[1], SizeList[2]);
  185.               WinSetDlgItemText(hwnd, ID_MSG, Buff);
  186.               return 0;
  187.               }
  188.           } // switch on MCLB notify code
  189.           break;
  190.       }                                                                         
  191.       break; /* End of WM_CONTROL */                                            
  192.  
  193.     case WM_WINDOWPOSCHANGED: {
  194.  
  195.       /* Dialog was resized, so we resize/move the dialog controls as needed. */
  196.       /* When we resize the MCLB, it will adjust it's column widths according */
  197.       /* the the MCLBS_SIZEMETHOD_* algorithm we specified in the style bits. */
  198.       /* Resizing the control does NOT cause a MCLBN_COLSIZED control message.*/
  199.  
  200.       SWP  Pos1, Pos2;
  201.  
  202.       /* Let def dlg proc set frame controls */
  203.       WinDefDlgProc(hwnd, msg, mp1, mp2);
  204.  
  205.       /* Size/place MCLB above OK button, centered in dialog.  Note that the */
  206.       /* dialog window is the frame, so we must account for frame controls.  */
  207.  
  208.       WinQueryWindowPos(CONTROLHWND(DID_OK), &Pos1);
  209.       WinQueryWindowPos(hwnd, &Pos2);
  210.       Pos2.cy = Pos2.cy - WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) - WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  211.       Pos2.cx = Pos2.cx - (2 * Pos1.x),
  212.       WinSetWindowPos(MCLBHwnd, HWND_TOP,
  213.          Pos1.x,
  214.          Pos1.y+Pos1.cy+5,
  215.          Pos2.cx,
  216.          Pos2.cy - (Pos1.y+Pos1.cy+7+Pos1.y),
  217.          SWP_MOVE|SWP_SIZE);
  218.  
  219.       /* Size/place message control */
  220.       WinQueryWindowPos(CONTROLHWND(ID_MSG), &Pos1);
  221.       WinQueryWindowPos(hwnd, &Pos2);
  222.       WinSetWindowPos(CONTROLHWND(ID_MSG), HWND_TOP,
  223.          0,0,
  224.          Pos2.cx-Pos1.x-(2*WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER))-3,
  225.          Pos1.cy,
  226.          SWP_SIZE);
  227.  
  228.       return 0;  // Already called default proc, so just return.
  229.       }
  230.                                                                                 
  231.   } /* End of (msg) switch */                                                   
  232.                                                                                 
  233.   return WinDefDlgProc(hwnd, msg, mp1, mp2);                                    
  234.                                                                                 
  235. } /* End dialog procedure */                                                    
  236.  
  237. /*----------------------------------------------------------------------------*/
  238. int main(int argc,char **argv, char **envp)                                     
  239. /*----------------------------------------------------------------------------*/
  240. /*  Main routine just runs a dialog box (no main window).                     */
  241. /*----------------------------------------------------------------------------*/
  242. {                                                                               
  243.   /* Initialize PM window environment, get a message queue */                   
  244.                                                                                 
  245.   hab = WinInitialize(0L);                                                      
  246.   MyQ = WinCreateMsgQueue(hab, 0) ;                                             
  247.                                                                                 
  248.   WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, (PFNWP)                                 
  249.             ID_MAINDLG_Proc,                                                    
  250.             NULLHANDLE,                                                         
  251.             ID_MAINDLG,                                                         
  252.             NULL);                                                              
  253.                                                                                 
  254.   /* Cleanup when dialog terminates */                                          
  255.                                                                                 
  256.   WinDestroyMsgQueue(MyQ);                                                      
  257.   WinTerminate(hab);                                                            
  258.  
  259.   return 0;
  260. }                                                                               
  261.