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

  1. /*
  2.  *  Function Name:   DlgDirList
  3.  *  Program Name:    ddirli.c
  4.  *  Special Notes:
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.0
  9.  *
  10.  *  Description:
  11.  *   The program below allows the display of filenames and directories from
  12.  *   the disk.  It will display the current directory and
  13.  *   allow the user to select the filenames.
  14.  *
  15.  *   Windows Version 2.0 function demonstration application
  16.  *
  17.  */
  18.  
  19. #include <windows.h>
  20. #include "ddirli.h"
  21.  
  22. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  23. BOOL FAR PASCAL DialogProc(HWND, unsigned, WORD, LONG);
  24.  
  25. HANDLE   hInst;
  26.  
  27. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  28. HANDLE     hInstance, hPrevInstance;
  29. LPSTR     lpszCmdLine;
  30. int     cmdShow;
  31.   {
  32.   MSG         msg;
  33.   HWND         hWnd;
  34.   HMENU      hMenu;
  35.   WNDCLASS   wcClass;
  36.  
  37.   if (!hPrevInstance)
  38.     {
  39.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  40.     wcClass.lpfnWndProc    = WndProc;
  41.     wcClass.cbClsExtra       = 0;
  42.     wcClass.cbWndExtra       = 0;
  43.     wcClass.hInstance       = hInstance;
  44.     wcClass.hIcon       = LoadIcon(hInstance, NULL);
  45.     wcClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  46.     wcClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  47.     wcClass.lpszMenuName   = (LPSTR)"MenuName";
  48.     wcClass.lpszClassName  = (LPSTR)"DlgDirList";
  49.  
  50.     if (!RegisterClass(&wcClass))
  51.       return FALSE;
  52.     }
  53.  
  54.   hWnd = CreateWindow("DlgDirList",
  55.              "DlgDirList()",
  56.              WS_OVERLAPPEDWINDOW,
  57.              CW_USEDEFAULT,
  58.              CW_USEDEFAULT,
  59.              CW_USEDEFAULT,
  60.              CW_USEDEFAULT,
  61.              NULL,
  62.              NULL,
  63.              hInstance,
  64.              NULL);
  65.  
  66.   hInst = hInstance;
  67.   ShowWindow(hWnd, cmdShow);
  68.   UpdateWindow(hWnd);
  69.   while (GetMessage(&msg, NULL, 0, 0))
  70.     {
  71.     TranslateMessage(&msg);
  72.     DispatchMessage(&msg);
  73.     }
  74.   return msg.wParam;
  75.   }
  76.  
  77. long FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  78. HWND      hWnd;
  79. unsigned  message;
  80. WORD      wParam;
  81. LONG      lParam;
  82.   {
  83.   switch (message)
  84.     {
  85.     case WM_COMMAND:
  86.       if (wParam == IDM_1)
  87.     {
  88.     FARPROC lpprocDialogBox;
  89.     lpprocDialogBox = MakeProcInstance ((FARPROC) DialogProc, hInst);
  90.     DialogBox (hInst, MAKEINTRESOURCE(DIALOGID), hWnd, lpprocDialogBox);
  91.     FreeProcInstance ((FARPROC) lpprocDialogBox);
  92.     }
  93.       break;
  94.  
  95.     case WM_DESTROY:
  96.       PostQuitMessage(0);
  97.       break;
  98.  
  99.     default:
  100.       return DefWindowProc(hWnd, message, wParam, lParam);
  101.     }
  102.   return(0L);
  103.   }
  104.  
  105. /* Window procedure for the dialog box */
  106. BOOL FAR PASCAL DialogProc (hDlg, message, wParam, lParam)
  107. HWND       hDlg;
  108. unsigned   message;
  109. WORD       wParam;
  110. LONG       lParam;
  111.   {
  112.   BOOL       bListed;
  113.   char       str[128];
  114.  
  115.   switch (message)
  116.     {
  117.     case WM_INITDIALOG:
  118.       {
  119.       bListed = DlgDirList(hDlg, "*.*", ID_LISTBOX, NULL, 0x4010);
  120.       if (!bListed)
  121.     {
  122.     MessageBox(NULL, (LPSTR)"DlgDirList failed", (LPSTR)"ERROR", MB_ICONHAND);
  123.     return FALSE;
  124.     }
  125.       SetDlgItemText(hDlg, ID_EDIT, (LPSTR)"");
  126.       return TRUE;
  127.       break;
  128.       }
  129.     case WM_COMMAND:
  130.       {
  131.       switch (wParam)
  132.     {
  133.     case ID_LISTBOX:
  134.       if ((HIWORD(lParam)) == LBN_SELCHANGE)
  135.         {
  136.         DlgDirSelect(hDlg, (LPSTR)str, ID_LISTBOX);
  137.         SetDlgItemText(hDlg, ID_EDIT, (LPSTR)str);
  138.         return TRUE;
  139.         }
  140.       break;
  141.     case IDCANCEL:
  142.       EndDialog(hDlg, TRUE);
  143.       break;
  144.     default:
  145.       return FALSE;
  146.     }
  147.       }
  148.     default:
  149.       return FALSE;
  150.     }
  151.   return TRUE;
  152.   }
  153.