home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / COMBO.ZIP / COMBOSMP.C < prev    next >
C/C++ Source or Header  |  1990-01-28  |  4KB  |  148 lines

  1. /*
  2.     COMBOSMP.C - Sample program to illustrate use of combo box support
  3.                  routines
  4.  
  5.     Written by Dave Briccetti, CIS 74475,1072, 28-Jan-1990
  6.     This code may be used for any purpose
  7.  
  8.  */
  9.  
  10. #define  INCL_WINDIALOGS
  11. #define  INCL_WINENTRYFIELDS
  12. #define  INCL_WINLISTBOXES
  13. #define  INCL_WINSYS
  14. #define  INCL_WINWINDOWMGR
  15. #include <os2.h>
  16.  
  17. #include "combosmp.h"
  18. #include "combosup.h"
  19.  
  20. #define ID_COMBO1   1
  21. #define ID_COMBO2   2
  22.  
  23. #define COMBOBOXWIDTH   100
  24. #define COMBOBOXHEIGHT  100
  25. #define COMBOBOXSPACING 10
  26.  
  27. int main( VOID );
  28. MRESULT EXPENTRY ComboSampWindowProc( HWND hwnd, USHORT msg,
  29.     MPARAM mp1, MPARAM mp2 );
  30.  
  31. static  HAB     hab;
  32.  
  33.  
  34. int main( VOID )
  35. {
  36.     HMQ     hmq;
  37.     QMSG    qmsg;
  38.     HWND    hwndFrame;
  39.     HWND    hwndClient;
  40.     ULONG   flCreate;
  41.     SHORT   cyFrame;
  42.  
  43.     hab = WinInitialize( 0 );           // Initialize
  44.     hmq = WinCreateMsgQueue( hab, 0 );  // Create message queue
  45.  
  46.     WinRegisterClass( hab, "COMBOSMP",  // Register window class
  47.         ComboSampWindowProc, 0L, 0 );
  48.  
  49.     flCreate = FCF_STANDARD             // Set frame creation flags
  50.         & ~FCF_ICON & ~FCF_MENU & ~FCF_ACCELTABLE
  51.         | FCF_NOBYTEALIGN;
  52.  
  53.     hwndFrame = WinCreateStdWindow(     // Create main window
  54.         HWND_DESKTOP, 0L,
  55.         &flCreate, "COMBOSMP", "", 0L,
  56.         0, 1, &hwndClient );
  57.  
  58.     cyFrame = (SHORT) WinQuerySysValue( // Find space required for title, border
  59.         HWND_DESKTOP, SV_CYTITLEBAR ) +
  60.         (SHORT) WinQuerySysValue( HWND_DESKTOP,
  61.         SV_CYSIZEBORDER );
  62.  
  63.     WinSetWindowPos( hwndFrame,         // Size main window
  64.         HWND_TOP,
  65.         0, 0, 2 * COMBOBOXWIDTH + 3 * COMBOBOXSPACING,
  66.         COMBOBOXHEIGHT + 2 * COMBOBOXSPACING + cyFrame,
  67.         SWP_SHOW | SWP_SIZE | SWP_ZORDER );
  68.  
  69.     while( WinGetMsg( hab, &qmsg,       // Process messages
  70.         0, 0, 0 ) )
  71.         WinDispatchMsg( hab, &qmsg );
  72.  
  73.     WinDestroyMsgQueue( hmq );          // Destroy message queue
  74.     WinTerminate( hab );                // Terminate
  75.  
  76.     return 0;
  77. }
  78.  
  79.  
  80.  
  81. MRESULT EXPENTRY ComboSampWindowProc( HWND hwnd, USHORT msg,
  82.     MPARAM mp1, MPARAM mp2 )
  83. {
  84.     static  HWND    hwndCombo1;
  85.     static  HWND    hwndCombo2;
  86.  
  87.     switch( msg )
  88.     {
  89.         case WM_CREATE:
  90.         {
  91.             static  SHORT   aCombo1Init[] =
  92.                 { IDS_ITEM1, IDS_ITEM2, IDS_ITEM3, IDS_ITEM4 };
  93.             static  PSZ apszCombo2Init[] =
  94.                 { "Item 1", "Item 2", "Item 3", "Item 4", 0 };
  95.  
  96.  
  97.             hwndCombo1 = WinCreateWindow( hwnd, WC_COMBOBOX, "",
  98.                 CBS_DROPDOWNLIST, 0, 0, 0, 0,
  99.                 hwnd, HWND_TOP, ID_COMBO1, 0, 0 );
  100.  
  101.             hwndCombo2 = WinCreateWindow( hwnd, WC_COMBOBOX, "",
  102.                 CBS_DROPDOWNLIST, 0, 0, 0, 0,
  103.                 hwnd, HWND_TOP, ID_COMBO2, 0, 0 );
  104.  
  105.  
  106.             // Initialize combo box 1 with dynamically loaded values
  107.             // from resource string table
  108.  
  109.             InitComboBoxFromRcStrings( hab, hwnd, ID_COMBO1,
  110.                 sizeof aCombo1Init / sizeof aCombo1Init[ 0 ],
  111.                 aCombo1Init, 100, 0, 0 );
  112.  
  113.  
  114.             // Initialize combo box 2 with hard-coded values from array
  115.             //  of string pointers
  116.  
  117.             InitComboBox( hwnd, ID_COMBO2, apszCombo2Init, 1 );
  118.  
  119.  
  120.             break;
  121.         }
  122.  
  123.         case WM_SIZE:
  124.             WinSetWindowPos( hwndCombo1, 0,
  125.                 COMBOBOXSPACING, COMBOBOXSPACING,
  126.                 COMBOBOXWIDTH, COMBOBOXHEIGHT,
  127.                 SWP_MOVE | SWP_SIZE | SWP_SHOW );
  128.             WinSetWindowPos( hwndCombo2, 0,
  129.                 COMBOBOXWIDTH + 2 * COMBOBOXSPACING, COMBOBOXSPACING,
  130.                 COMBOBOXWIDTH, COMBOBOXHEIGHT,
  131.                 SWP_MOVE | SWP_SIZE | SWP_SHOW );
  132.             break;
  133.  
  134.         case WM_PAINT:
  135.         {
  136.             HPS hps = WinBeginPaint( hwnd, 0, 0 );
  137.             GpiErase( hps );
  138.             WinEndPaint( hps );
  139.             break;
  140.         }
  141.  
  142.         default:
  143.             return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  144.     }
  145.  
  146.     return 0L;
  147. }
  148.