home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv4_4 / select / demo.c next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  3.6 KB  |  134 lines

  1. #include <windows.h>
  2. #include "select.h"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "demo.h"
  6.  
  7. HWND hWndDemo;
  8. HANDLE hInstDemo;
  9.  
  10. static char szClassName[] = "demo";
  11. static int nTrueFalse = 0;
  12. static int nString = 0;
  13.  
  14. int PASCAL WinMain ( HANDLE hInstance, HANDLE hPrevInstance,
  15.     LPSTR lpszCmdLine, int cmdShow );
  16. long FAR PASCAL DemoWndProc ( HWND hWnd, unsigned message,
  17.     WORD wParam, LONG lParam );
  18. void DemoCommand ( HWND hWnd, WORD wCmd );
  19. BOOL FAR PASCAL DemoDlg ( HWND hWndDlg, unsigned message, 
  20.     WORD wParam, LONG lParam );
  21.  
  22.  
  23. int PASCAL WinMain ( HANDLE hInstance, HANDLE hPrevInstance,
  24.     LPSTR lpszCmdLine, int cmdShow )
  25. {
  26.     MSG msg;
  27.     WNDCLASS Class;
  28.  
  29.     if (hPrevInstance) return TRUE;
  30.     Class.hCursor       = LoadCursor(NULL,IDC_ARROW);
  31.     Class.hIcon         = NULL;
  32.     Class.cbClsExtra    = 0;
  33.     Class.cbWndExtra    = 0;
  34.     Class.lpszMenuName  = szClassName;
  35.     Class.lpszClassName = szClassName;
  36.     Class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);;
  37.     Class.hInstance     = hInstance;
  38.     Class.style         = CS_VREDRAW | CS_HREDRAW;
  39.     Class.lpfnWndProc   = DemoWndProc;
  40.    if (!RegisterClass(&Class)) return FALSE;
  41.  
  42.     hWndDemo = CreateWindow(
  43.         szClassName, szClassName, WS_OVERLAPPEDWINDOW,
  44.         30, 50, 200, 150,
  45.         NULL, NULL, hInstDemo=hInstance, NULL);
  46.  
  47.     ShowWindow ( hWndDemo, cmdShow );
  48.     UpdateWindow ( hWndDemo );
  49.     
  50.     while (GetMessage( &msg, NULL, 0, 0 ))    {
  51.          TranslateMessage((LPMSG)&msg);
  52.          DispatchMessage((LPMSG)&msg);
  53.     }
  54.         
  55.     return msg.wParam;
  56. }
  57.  
  58. long FAR PASCAL DemoWndProc ( HWND hWnd, unsigned message,
  59.     WORD wParam, LONG lParam )
  60. {
  61.     switch (message) {
  62.  
  63.     case WM_COMMAND:
  64.         DemoCommand ( hWnd, wParam );
  65.         break;
  66.     case WM_DESTROY:
  67.         PostQuitMessage (0);
  68.         break;
  69.  
  70.     default:
  71.         return DefWindowProc (hWnd, message, wParam, lParam) ;
  72.     }
  73.     return (0L) ;
  74. }
  75.  
  76. void DemoCommand ( HWND hWnd, WORD wCmd )
  77. {
  78.     int i;
  79.     HMENU hMenu;
  80.     FARPROC lpfnDlg;
  81.  
  82.     switch (wCmd) {
  83.  
  84.     case IDM_TEST:
  85.         lpfnDlg = MakeProcInstance( DemoDlg, hInstDemo );
  86.         DialogBox( hInstDemo, "TEST", hWnd, lpfnDlg );
  87.         FreeProcInstance ( lpfnDlg );
  88.         break;
  89.  
  90.     default:
  91.         break;
  92.     }
  93. }
  94.  
  95.  
  96. BOOL FAR PASCAL DemoDlg ( HWND hWndDlg, unsigned message, 
  97.     WORD wParam, LONG lParam )
  98. {
  99.     char szBuf[40];
  100.     int i;
  101.     switch ( message ) {
  102.     case WM_INITDIALOG:
  103.         for ( i = IDS_COLOR1 ; i <= IDS_COLOR8 ; i++ ) {
  104.             LoadString( hInstDemo, i, szBuf, 40 );
  105.             SendDlgItemMessage( hWndDlg, IDD_COLORS, SL_ADDSTRING,
  106.                 0, (LONG)(LPSTR)szBuf );
  107.         }    
  108.         for ( i = IDS_STRING1 ; i <= IDS_STRING5 ; i++ ) {
  109.             LoadString( hInstDemo, i, szBuf, 40 );
  110.             SendDlgItemMessage( hWndDlg, IDD_STRINGS , SL_ADDSTRING,
  111.                 0, (LONG)(LPSTR)szBuf);
  112.         }    
  113.         SendDlgItemMessage( hWndDlg, IDD_COLORS, SL_SETCURSEL,
  114.             nTrueFalse, 0L );
  115.         SendDlgItemMessage( hWndDlg, IDD_STRINGS, SL_SETCURSEL,
  116.             nString, 0L );
  117.         return TRUE;
  118.  
  119.     case WM_COMMAND:
  120.         if (wParam == IDD_OK) {
  121.             nTrueFalse = (int)SendDlgItemMessage( hWndDlg, IDD_COLORS,
  122.                 SL_GETCURSEL, 0, 0L );
  123.             nString = (int)SendDlgItemMessage( hWndDlg, IDD_STRINGS,
  124.                 SL_GETCURSEL, 0, 0L );
  125.             EndDialog( hWndDlg, TRUE );
  126.         }
  127.         break;
  128.  
  129.     default:
  130.         return FALSE;
  131.     }
  132.     return TRUE;
  133. }
  134.