/*------------------------------------------------------------------------ Procedure: MsgMenuSelect ID:1 Purpose: Shows in the status bar a descriptive explaation of the purpose of each menu item.The message WM_MENUSELECT is sent when the user starts browsing the menu for each menu item where the mouse passes. Input: Standard windows. Output: The string from the resources string table is shown Errors: If the string is not found nothing will be shown. ------------------------------------------------------------------------*/ LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { static char szBuffer[256]; UINT nStringID = 0; UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff; UINT uCmd = GET_WM_MENUSELECT_CMD(wparam, lparam); HMENU hMenu = GET_WM_MENUSELECT_HMENU(wparam, lparam); szBuffer[0] = 0; // First reset the buffer if (fuFlags == 0xffff && hMenu == NULL) // Menu has been closed nStringID = 0; else if (fuFlags & MFT_SEPARATOR) // Ignore separators nStringID = 0; else if (fuFlags & MF_POPUP) // Popup menu { if (fuFlags & MF_SYSMENU) // System menu nStringID = IDS_SYSMENU; else // Get string ID for popup menu from idPopup array. nStringID = 0; } // for MF_POPUP else // Must be a command item nStringID = uCmd; // String ID == Command ID // Load the string if we have an ID if (0 != nStringID) LoadString(hInst, nStringID, szBuffer, sizeof(szBuffer)); // Finally... send the string to the status bar UpdateStatusBar(szBuffer, 0, 0); return 0; }
void GetMenuSelect ( HWND hWndStatus, UINT message, WPARAM wParam, LPARAM lParam) { UINT nStringID = 0; UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wParam, lParam) & 0xffff; UINT uCmd = GET_WM_MENUSELECT_CMD(wParam, lParam); HMENU hMenu = GET_WM_MENUSELECT_HMENU(wParam, lParam); if (fuFlags == 0xffff && hMenu == (HMENU)NULL) nStringID = (UINT) -1; else if (fuFlags & MF_SEPARATOR) nStringID = 0; else if (fuFlags & MF_POPUP) { if (fuFlags & MF_SYSMENU) nStringID = 0; } else { nStringID = uCmd; } DisplayStatusMenuHelp(hWndStatus, nStringID); }
WINDOWPROC MainWndProc( HWND hwnd, UINT msg, WPARAM wParam, LONG lParam) { switch (msg) { case WM_CREATE: { RECT rc; /* * Create the status window. */ CreateDialog(ghInst, MAKEINTRESOURCE(DID_STATUS), hwnd, StatusDlgProc); /* * Save away its height for sizing later (like when * the app is minimized then restored). */ GetWindowRect(hwndStatus, &rc); gcyStatus = rc.bottom - rc.top; ghwndSubClient = CreateWindow(szSubClientClass, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, NULL, ghInst, NULL); ghMenuMain = GetMenu(hwnd); LoadMenuBitmaps(ghMenuMain); } break; case WM_ACTIVATE: /* * If the main window is getting activated, there is no * currently active dialog. */ if (GET_WM_ACTIVATE_STATE(wParam, lParam)) gidCurrentDlg = 0; goto DoDefault; case WM_INITMENU: if (GetMenu(ghwndMain) == (HMENU)wParam) InitMenu((HMENU)wParam); break; case WM_MENUSELECT: if (GET_WM_MENUSELECT_FLAGS(wParam, lParam) & (MF_POPUP | MF_SYSMENU)) gMenuSelected = 0; else gMenuSelected = GET_WM_MENUSELECT_CMD(wParam, lParam); break; case WM_COMMAND: DialogMenu(GET_WM_COMMAND_ID(wParam, lParam)); break; case WM_KEYDOWN: switch (wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Ignore it if we are not in a normal state * (don't allow when dragging). */ if (gState != STATE_NORMAL) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; /* * Move the control in the specified direction. */ MoveControl(wParam); break; case VK_TAB: if (GetKeyState(VK_CONTROL) & 0x8000) break; /* * Ignore it if we are not in a normal state * (don't allow when dragging). */ if (gState != STATE_NORMAL) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; /* * Is the shift key pressed also? */ if (GetKeyState(VK_SHIFT) & 0x8000) SelectPrevious(); else SelectNext(); break; case VK_ESCAPE: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; if (gState == STATE_SELECTING) OutlineSelectCancel(); /* * Cancel any drag operation they might have been doing. */ if (gState != STATE_NORMAL) DragCancel(); break; case VK_RETURN: if ((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)) break; /* * Be sure any outstanding changes get applied * without errors. */ if (!StatusApplyChanges()) break; switch (gState) { MPOINT mpt; POINT pt; DWORD dwPos; case STATE_SELECTING: /* * In outline selection mode. Map the * location of the mouse at the time that * the user pressed Enter into a point * relative to the dialog client and complete * the selection operation. */ dwPos = GetMessagePos(); mpt = MAKEMPOINT(dwPos); MPOINT2POINT(mpt, pt); ScreenToClient(gcd.npc->hwnd, &pt); OutlineSelectEnd(pt.x, pt.y); break; case STATE_DRAGGING: case STATE_DRAGGINGNEW: /* * We are dragging something. Map the * location of the mouse at the time * that the user pressed Enter into a * point relative to the proper window * and complete the drag operation. */ dwPos = GetMessagePos(); mpt = MAKEMPOINT(dwPos); MPOINT2POINT(mpt, pt); /* * The point must be changed to be relative to * the window that the ending mouse up message * would have come through, which will be the * capture window for the drag. This will be * the dialog if we are adding a new control, * or it will be the selected control if we are * dragging an existing control. */ ScreenToClient((gState == STATE_DRAGGING) ? gnpcSel->hwnd : gcd.npc->hwnd, &pt); /* * If the dialog is selected, map the points from * the client area to the window. */ if (gfDlgSelected) MapDlgClientPoint(&pt, TRUE); DragEnd(pt.x, pt.y); break; } break; } break; case WM_NCCALCSIZE: /* * Save away what is going to be the new window position. */ if (!IsIconic(hwnd) && !IsZoomed(hwnd)) grcAppPos = *((LPRECT)lParam); /* * Now let the DefWindowProc calculate the client area normally. */ goto DoDefault; case WM_MOVE: if (gfEditingDlg) RepositionDialog(); break; case WM_SIZE: SizeRibbons(hwnd); /* * Did the app start minimized and is it being restored * for the first time? If so, show the toolbox if * the user has requested it. */ if (fStartAsIcon && !IsIconic(hwnd)) { if (gfShowToolbox) ToolboxShow(TRUE); fStartAsIcon = FALSE; } break; case WM_SYSCOLORCHANGE: LoadSysColorBitmaps(); break; case WM_CLOSE: if (ghwndTestDlg) DestroyTestDialog(); if (DoWeSave(FILE_INCLUDE) == IDCANCEL || DoWeSave(FILE_RESOURCE) == IDCANCEL) break; /* * First destroy the Properties Bar. */ DestroyWindow(hwndStatus); hwndStatus = NULL; DestroyWindow(hwnd); break; case WM_QUERYENDSESSION: if (ghwndTestDlg) DestroyTestDialog(); if (DoWeSave(FILE_INCLUDE) == IDCANCEL || DoWeSave(FILE_RESOURCE) == IDCANCEL) return FALSE; else return TRUE; case WM_DESTROY: /* * Save the position of the app's window. */ WriteWindowPos(&grcAppPos, IsZoomed(hwnd), szAppPos); WinHelp(hwnd, gszHelpFile, HELP_QUIT, 0L); FreeMenuBitmaps(); PostQuitMessage(0); break; default: /* * Is this the registered help message from one of the common * dialogs? If so, show the help for it. * * The check to be sure gmsgHelp is non-zero is just in * case the call to register the help message failed * (it will return zero) and there happens to be a zero * message that gets sent to this window somehow. */ if (msg == gmsgHelp && gmsgHelp) { ShowHelp(FALSE); return 0; } DoDefault: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }