fixed some bugs
[reactos.git] / reactos / subsys / system / msconfig / toolspage.c
1 #include <precomp.h>
2
3 HWND hToolsPage;
4 HWND hToolsListCtrl;
5 HWND hToolsDialog;
6
7 void AddItem ( DWORD, DWORD, DWORD, DWORD );
8 void FillListView ( void );
9
10 DWORD ListItems_Cmds[20];
11 DWORD ListItems_Params[20];
12
13 void AddItem ( DWORD name_id, DWORD descr_id, DWORD cmd_id , DWORD param_id ) {
14 TCHAR szTemp[256];
15 LV_ITEM item;
16
17 LoadString(hInst, name_id, szTemp, 256);
18 memset(&item, 0, sizeof(LV_ITEM));
19 item.mask = LVIF_TEXT;
20 item.iImage = 0;
21 item.pszText = szTemp;
22 item.iItem = ListView_GetItemCount(hToolsListCtrl);
23 item.lParam = 0;
24 ListView_InsertItem(hToolsListCtrl, &item);
25
26 ListItems_Cmds[item.iItem] = cmd_id;
27 ListItems_Params[item.iItem] = param_id;
28
29 LoadString(hInst, descr_id, szTemp, 256);
30 item.pszText = szTemp;
31 item.iSubItem = 1;
32 SendMessage(hToolsListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
33 }
34
35 void FillListView ( void ) {
36 AddItem(IDS_TOOLS_CMD_NAME, IDS_TOOLS_CMD_DESCR, IDS_TOOLS_CMD_CMD, IDS_TOOLS_CMD_PARAM);
37 AddItem(IDS_TOOLS_REGEDIT_NAME, IDS_TOOLS_REGEDIT_DESCR, IDS_TOOLS_REGEDIT_CMD,IDS_TOOLS_REGEDIT_PARAM);
38 AddItem(IDS_TOOLS_SYSDM_NAME, IDS_TOOLS_SYSDM_DESCR, IDS_TOOLS_SYSDM_CMD, IDS_TOOLS_SYSDM_PARAM);
39 AddItem(IDS_TOOLS_INFO_NAME, IDS_TOOLS_INFO_DESCR, IDS_TOOLS_INFO_CMD, IDS_TOOLS_INFO_PARAM);
40 }
41
42 INT_PTR CALLBACK
43 ToolsPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
44 {
45 LV_COLUMN column;
46 TCHAR szTemp[256];
47 TCHAR szTemp2[256];
48 LPNMITEMACTIVATE lpnmitem;
49 LPNMHDR nmh;
50 DWORD dwStyle;
51
52 switch (message) {
53 case WM_INITDIALOG:
54
55 hToolsListCtrl = GetDlgItem(hDlg, IDC_TOOLS_LIST);
56 hToolsDialog = hDlg;
57
58 dwStyle = (DWORD) SendMessage(hToolsListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
59 dwStyle = dwStyle | LVS_EX_FULLROWSELECT;
60 SendMessage(hToolsListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
61
62 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
63
64 // Initialize the application page's controls
65 column.mask = LVCF_TEXT | LVCF_WIDTH;
66
67 LoadString(hInst, IDS_TOOLS_COLUMN_NAME, szTemp, 256);
68 column.pszText = szTemp;
69 column.cx = 150;
70 ListView_InsertColumn(hToolsListCtrl, 0, &column);
71
72 column.mask = LVCF_TEXT | LVCF_WIDTH;
73 LoadString(hInst, IDS_TOOLS_COLUMN_DESCR, szTemp, 256);
74 column.pszText = szTemp;
75 column.cx = 500;
76 ListView_InsertColumn(hToolsListCtrl, 1, &column);
77
78 FillListView();
79 return TRUE;
80
81 case WM_COMMAND:
82 switch (LOWORD(wParam))
83 {
84 case IDC_BTN_RUN:
85 if (ListView_GetSelectionMark(hToolsListCtrl) != -1) {
86 LoadString(hInst, ListItems_Cmds[ListView_GetSelectionMark(hToolsListCtrl)], szTemp, 256);
87 LoadString(hInst, ListItems_Params[ListView_GetSelectionMark(hToolsListCtrl)], szTemp2, 256);
88 ShellExecute(0, _T("open"), szTemp, szTemp2, _T(""), SW_NORMAL);
89 }
90 }
91 break;
92
93 case WM_NOTIFY:
94 nmh = (LPNMHDR) lParam;
95 if (nmh->hwndFrom == hToolsListCtrl)
96 {
97 switch (nmh->code)
98 {
99 case NM_CLICK:
100 lpnmitem = (LPNMITEMACTIVATE) lParam;
101 if (lpnmitem->iItem > -1) {
102 LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], szTemp, 256);
103 LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256);
104 _tcscat(szTemp, _T(" "));
105 _tcscat(szTemp, szTemp2);
106 SendDlgItemMessage(hToolsDialog, IDC_TOOLS_CMDLINE, WM_SETTEXT, 0, (LPARAM) szTemp);
107 }
108 break;
109 case NM_DBLCLK:
110 lpnmitem = (LPNMITEMACTIVATE) lParam;
111 if (lpnmitem->iItem > -1) {
112 LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], szTemp, 256);
113 LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256);
114 ShellExecute(0, _T("open"), szTemp, szTemp2, _T(""), SW_NORMAL);
115 }
116 break;
117 }
118 }
119 break;
120 }
121
122 return 0;
123 }
124