MCPcopy Create free account
hub / github.com/NetHack/NetHack / ExtCmdDlgProc

Function ExtCmdDlgProc

win/win32/mhdlg.c:202–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202INT_PTR CALLBACK
203ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
204{
205 struct extcmd_data *data;
206 RECT main_rt, dlg_rt;
207 SIZE dlg_sz;
208 int i;
209 TCHAR wbuf[255];
210
211 switch (message) {
212 case WM_INITDIALOG:
213 data = (struct extcmd_data *) lParam;
214 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
215
216 /* center dialog in the main window */
217 GetWindowRect(GetNHApp()->hMainWnd, &main_rt);
218 GetWindowRect(hWnd, &dlg_rt);
219 dlg_sz.cx = dlg_rt.right - dlg_rt.left;
220 dlg_sz.cy = dlg_rt.bottom - dlg_rt.top;
221
222 dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2;
223 dlg_rt.right = dlg_rt.left + dlg_sz.cx;
224 dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2;
225 dlg_rt.bottom = dlg_rt.top + dlg_sz.cy;
226 MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2,
227 (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx,
228 dlg_sz.cy, TRUE);
229
230 /* fill combobox with extended commands */
231 for (i = 0; extcmdlist[i].ef_txt; i++) {
232 SendDlgItemMessage(
233 hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM) 0,
234 (LPARAM) NH_A2W(extcmdlist[i].ef_txt, wbuf, sizeof(wbuf)));
235 }
236
237 /* set focus to the list control */
238 SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST));
239
240 /* tell windows we set the focus */
241 return FALSE;
242 break;
243
244 case WM_COMMAND:
245 data = (struct extcmd_data *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
246 switch (LOWORD(wParam)) {
247 /* OK button ws clicked */
248 case IDOK:
249 *data->selection = (int) SendDlgItemMessage(
250 hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
251 if (*data->selection == LB_ERR)
252 *data->selection = -1;
253 FALLTHROUGH;
254 /* FALLTHRU */
255
256 /* CANCEL button ws clicked */
257 case IDCANCEL:
258 EndDialog(hWnd, wParam);
259 return TRUE;

Callers

nothing calls this directly

Calls 1

GetNHAppFunction · 0.70

Tested by

no test coverage detected