home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / metafile / ddirsel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  5.6 KB  |  208 lines

  1. /*
  2.  *  Function Name:   DlgDirSelect
  3.  *  Program Name:    ddirsel.c
  4.  *  Author:          bertm
  5.  *  Date Completed:  2-Feb-88
  6.  *  Special Notes:
  7.  *
  8.  *  SDK Version:         2.03
  9.  *  Runtime Version:     2.03
  10.  *  Microsoft C Version: 5.0
  11.  *
  12.  *  Description:
  13.  *   This program allows the user to select filenames or directories from
  14.  *   the list box. The program below will display the current directory
  15.  *   and allow the user to select the filenames.  The program will not
  16.  *   select directories (demonstrating the return value).
  17.  *
  18.  *   Microsoft Product Support Services
  19.  *   Windows Version 2.0 function demonstration application
  20.  *   Copyright (c) Microsoft 1988
  21.  *
  22.  */
  23.  
  24. #include "windows.h"
  25. #include "ddirsel.h"
  26.  
  27. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  28.  
  29. HANDLE   hInst;
  30.  
  31. /**************************************************************************/
  32.  
  33. /* Window procedure for the dialog box */
  34. BOOL FAR PASCAL DialogProc (hDlg, message, wParam, lParam)
  35. HWND hDlg;
  36. unsigned message;
  37. WORD wParam;
  38. LONG lParam;
  39. {
  40.   char  str[128];
  41.  
  42.   switch (message)
  43.   {
  44.     case WM_INITDIALOG:
  45.       DlgDirList(hDlg, (LPSTR) "*.*", ID_LISTBOX, NULL, 0x4010);
  46.       SetDlgItemText(hDlg, ID_EDIT, (LPSTR) "");
  47.       return TRUE;
  48.       break;
  49.  
  50.     case WM_COMMAND:
  51.       switch (wParam)
  52.       {
  53.         case ID_LISTBOX:
  54.           switch (HIWORD(lParam))
  55.           {
  56.             case LBN_SELCHANGE:
  57.                                          /* filenames only chosen   */
  58.              if (!DlgDirSelect(hDlg, (LPSTR)str, ID_LISTBOX))
  59.                SetDlgItemText(hDlg, ID_EDIT, (LPSTR)str);
  60.               return TRUE;
  61.               break;
  62.  
  63.             default:
  64.               return FALSE;
  65.           }
  66.         case IDCANCEL:
  67.           EndDialog(hDlg, TRUE);
  68.           break;
  69.  
  70.         default:
  71.           return FALSE;
  72.       }
  73.     default:
  74.       return FALSE;
  75.   }
  76.   return TRUE;              /*  return TRUE if message is processed by us  */
  77. }
  78.  
  79. /**************************************************************************/
  80.  
  81. void CALL_DlgDirSelect(hWnd)
  82. HWND   hWnd;
  83. {
  84.   FARPROC lpprocDialogBox;
  85.                     /*  Bind callback function with module instance  */
  86.     lpprocDialogBox = MakeProcInstance ((FARPROC) DialogProc, hInst);
  87.                     /*  Create a modal dialog box  */
  88.     DialogBox (hInst, MAKEINTRESOURCE(DIALOGID), hWnd, lpprocDialogBox);
  89.     FreeProcInstance ((FARPROC) lpprocDialogBox);
  90.  
  91. return;
  92. }
  93.  
  94. /**************************************************************************/
  95.  
  96. /* Procedure called when the application is loaded for the first time */
  97. BOOL WinInit( hInstance )
  98. HANDLE hInstance;
  99. {
  100.     WNDCLASS   wcClass;
  101.  
  102.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  103.     wcClass.lpfnWndProc    = WndProc;
  104.     wcClass.cbClsExtra     =0;
  105.     wcClass.cbWndExtra     =0;
  106.     wcClass.hInstance      = hInstance;
  107.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  108.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  109.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  110.     wcClass.lpszMenuName   = (LPSTR)"MenuName";
  111.     wcClass.lpszClassName  = (LPSTR)"DlgDirSelect";
  112.  
  113.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  114.         /* Initialization failed.
  115.          * Windows will automatically deallocate all allocated memory.
  116.          */
  117.         return FALSE;
  118.  
  119.     return TRUE;        /* Initialization succeeded */
  120. }
  121.  
  122.  
  123. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  124. HANDLE hInstance, hPrevInstance;
  125. LPSTR lpszCmdLine;
  126. int cmdShow;
  127. {
  128.     MSG   msg;
  129.     HWND  hWnd;
  130.     HMENU hMenu;
  131.  
  132.     if (!hPrevInstance)
  133.         {
  134.         /* Call initialization procedure if this is the first instance */
  135.         if (!WinInit( hInstance ))
  136.             return FALSE;
  137.         }
  138.  
  139.     hWnd = CreateWindow((LPSTR)"DlgDirSelect",
  140.                         (LPSTR)"DlgDirSelect()",
  141.                         WS_OVERLAPPEDWINDOW,
  142.                         CW_USEDEFAULT,
  143.                         CW_USEDEFAULT,
  144.                         CW_USEDEFAULT,
  145.                         CW_USEDEFAULT,
  146.                         (HWND)NULL,        /* no parent */
  147.                         (HMENU)NULL,       /* use class menu */
  148.                         (HANDLE)hInstance, /* handle to window instance */
  149.                         (LPSTR)NULL        /* no params to pass on */
  150.                         );
  151.  
  152.      hInst = hInstance;
  153.  
  154.     /* Make window visible according to the way the app is activated */
  155.     ShowWindow( hWnd, cmdShow );
  156.     UpdateWindow( hWnd );
  157.  
  158.     /* Polling messages from event queue */
  159.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  160.         {
  161.         TranslateMessage((LPMSG)&msg);
  162.         DispatchMessage((LPMSG)&msg);
  163.         }
  164.     return (int)msg.wParam;
  165. }
  166.  
  167. /* Procedures which make up the window class. */
  168. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  169. HWND hWnd;
  170. unsigned message;
  171. WORD wParam;
  172. LONG lParam;
  173. {
  174.     PAINTSTRUCT ps;
  175.  
  176.     switch (message)
  177.     {
  178.       case WM_COMMAND:
  179.         switch (wParam)
  180.         {
  181.           case IDM_1:
  182.             CALL_DlgDirSelect(hWnd);
  183.             break;
  184.  
  185.           default:
  186.             return DefWindowProc( hWnd, message, wParam, lParam );
  187.             break;
  188.         }
  189.  
  190.     case WM_PAINT:
  191.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  192.         ValidateRect(hWnd, (LPRECT) NULL);
  193.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  194.         break;
  195.  
  196.     case WM_DESTROY:
  197.         PostQuitMessage( 0 );
  198.         break;
  199.  
  200.     default:
  201.         return DefWindowProc( hWnd, message, wParam, lParam );
  202.         break;
  203.     }
  204.     return(0L);
  205. }
  206.  
  207.  
  208.