Adding rostests as part of the tree restructure
[reactos.git] / rostests / tests / dirdlg / dirdlg.c
1 #include <windows.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <io.h>
5 #include "resource.h"
6
7 static char selected[MAX_PATH + 1];
8
9 INT_PTR
10 CALLBACK
11 DlgMainProc(
12 HWND hwndDlg,
13 UINT uMsg,
14 WPARAM wParam,
15 LPARAM lParam
16 )
17 {
18 char dir[MAX_PATH + 1];
19
20 switch(uMsg)
21 {
22 case WM_COMMAND:
23 {
24 switch(HIWORD(wParam))
25 {
26 case LBN_DBLCLK:
27 {
28 switch(LOWORD(wParam))
29 {
30 case IDC_DIRS:
31 {
32 if(DlgDirSelectEx(hwndDlg, dir, MAX_PATH, IDC_DIRS))
33 {
34 chdir(dir);
35 GetCurrentDirectory(MAX_PATH, dir);
36 DlgDirList(hwndDlg, dir, IDC_DIRS, IDC_DIREDIT, DDL_DIRECTORY | DDL_DRIVES);
37 }
38 else
39 {
40 SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_OK, 0), 0);
41 }
42 break;
43 }
44 }
45 break;
46 }
47 default:
48 {
49 switch(LOWORD(wParam))
50 {
51 case IDC_OK:
52 {
53 char file[MAX_PATH + 1];
54 int len;
55
56 if(!DlgDirSelectEx(hwndDlg, file, MAX_PATH, IDC_DIRS))
57 {
58 GetCurrentDirectory(MAX_PATH, selected);
59 len = strlen(selected);
60 if(strlen(file))
61 {
62 if(selected[len - 1] != '\\')
63 {
64 lstrcat(selected, "\\");
65 }
66 lstrcat(selected, file);
67 EndDialog(hwndDlg, IDC_OK);
68 }
69 }
70 break;
71 }
72 case IDC_CANCEL:
73 {
74 EndDialog(hwndDlg, IDC_CANCEL);
75 break;
76 }
77 }
78 break;
79 }
80 }
81 break;
82 }
83 case WM_INITDIALOG:
84 {
85 SendDlgItemMessage(hwndDlg, IDC_DIRS, LB_SETCOLUMNWIDTH, 150, 0);
86 GetCurrentDirectory(MAX_PATH, dir);
87 DlgDirList(hwndDlg, dir, IDC_DIRS, IDC_DIREDIT, DDL_DIRECTORY | DDL_DRIVES);
88 SetFocus(GetDlgItem(hwndDlg, IDC_DIRS));
89 break;
90 }
91 case WM_CLOSE:
92 {
93 EndDialog(hwndDlg, IDC_CANCEL);
94 return TRUE;
95 }
96 }
97 return FALSE;
98 }
99
100 int WINAPI
101 WinMain(
102 HINSTANCE hInstance,
103 HINSTANCE hPrevInstance,
104 LPSTR lpszCmdLine,
105 int nCmdShow)
106 {
107 char str[MAX_PATH + 32];
108 if(DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), 0, DlgMainProc) == IDC_OK)
109 {
110 sprintf(str, "You selected \"%s\"", selected);
111 MessageBox(0, str, "Selected file", MB_ICONINFORMATION);
112 }
113 return 0;
114 }
115