void register_status_window_class(void) { WNDCLASS wcex; ZeroMemory( &wcex, sizeof(wcex)); wcex.style = CS_NOCLOSE; wcex.lpfnWndProc = (WNDPROC)StatusWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = GetNHApp()->hApp; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = status_bg_brush ? status_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS); wcex.lpszMenuName = NULL; wcex.lpszClassName = szStatusWindowClass; RegisterClass(&wcex); }
INT_PTR CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND control; HDC hdc; PNHTextWindow data; TCHAR title[MAX_LOADSTRING]; data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); switch (message) { case WM_INITDIALOG: /* set text control font */ control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); if (!control) { panic("cannot get text view window"); } hdc = GetDC(control); SendMessage(control, WM_SETFONT, (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); ReleaseDC(control, hdc); /* subclass edit control */ editControlWndProc = (WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC); SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHEditHookWndProc); SetFocus(control); /* Even though the dialog has no caption, you can still set the title which shows on Alt-Tab */ LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING); SetWindowText(hWnd, title); return FALSE; case WM_MSNH_COMMAND: onMSNHCommand(hWnd, wParam, lParam); break; case WM_SIZE: { RECT rt; GetWindowRect(hWnd, &rt); ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); mswin_update_window_placement(NHW_TEXT, &rt); LayoutText(hWnd); } return FALSE; case WM_MOVE: { RECT rt; GetWindowRect(hWnd, &rt); ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt); ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1); mswin_update_window_placement(NHW_TEXT, &rt); } return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: mswin_window_mark_dead(mswin_winid_from_handle(hWnd)); if (GetNHApp()->hMainWnd == hWnd) GetNHApp()->hMainWnd = NULL; DestroyWindow(hWnd); SetFocus(GetNHApp()->hMainWnd); return TRUE; } break; case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ HDC hdcEdit = (HDC) wParam; HWND hwndEdit = (HWND) lParam; if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) { SetBkColor(hdcEdit, text_bg_brush ? text_bg_color : (COLORREF) GetSysColor( DEFAULT_COLOR_BG_TEXT)); SetTextColor(hdcEdit, text_fg_brush ? text_fg_color : (COLORREF) GetSysColor( DEFAULT_COLOR_FG_TEXT)); return (INT_PTR)(text_bg_brush ? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); } } return FALSE; case WM_DESTROY: if (data) { if (data->window_text) free(data->window_text); free(data); SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0); } break; } return FALSE; }
/* Edit box hook */ LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; RECT rc; switch (message) { case WM_ERASEBKGND: hDC = (HDC) wParam; GetClientRect(hWnd, &rc); FillRect(hDC, &rc, text_bg_brush ? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); return 1; case WM_KEYDOWN: switch (wParam) { /* close on space in Windows mode page down on space in NetHack mode */ case VK_SPACE: { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; GetScrollInfo(hWnd, SB_VERT, &si); /* If nethackmode and not at the end of the list */ if (GetNHApp()->regNetHackMode && (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin)) SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); else PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); return 0; } case VK_NEXT: SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); return 0; case VK_PRIOR: SendMessage(hWnd, EM_SCROLL, SB_PAGEUP, 0); return 0; case VK_UP: SendMessage(hWnd, EM_SCROLL, SB_LINEUP, 0); return 0; case VK_DOWN: SendMessage(hWnd, EM_SCROLL, SB_LINEDOWN, 0); return 0; } break; case WM_CHAR: switch(wParam) { case MENU_FIRST_PAGE: SendMessage(hWnd, EM_SCROLL, SB_TOP, 0); return 0; case MENU_LAST_PAGE: SendMessage(hWnd, EM_SCROLL, SB_BOTTOM, 0); return 0; case MENU_NEXT_PAGE: SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); return 0; case MENU_PREVIOUS_PAGE: SendMessage(hWnd, EM_SCROLL, SB_PAGEUP, 0); return 0; } break; /* edit control needs to know nothing of focus. We will take care of it * for it */ case WM_SETFOCUS: HideCaret(hWnd); return 0; } if (editControlWndProc) return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam); else return 0; }