+ case WM_INITMENU:
+ /* We must ensure menu bar is fully constructed and up to date
+ before allowing user interaction with it. To achieve this
+ we send this message to the lisp thread and wait for a
+ reply (whose value is not actually needed) to indicate that
+ the menu bar is now ready for use, so we can now return.
+
+ To remain responsive in the meantime, we enter a nested message
+ loop that can process all other messages.
+
+ However, we skip all this if the message results from calling
+ TrackPopupMenu - in fact, we must NOT attempt to send the lisp
+ thread a message because it is blocked on us at this point. We
+ set menubar_active before calling TrackPopupMenu to indicate
+ this (there is no possibility of confusion with real menubar
+ being active). */
+
+ f = x_window_to_frame (dpyinfo, hwnd);
+ if (f
+ && (f->output_data.w32->menubar_active
+ /* We can receive this message even in the absence of a
+ menubar (ie. when the system menu is activated) - in this
+ case we do NOT want to forward the message, otherwise it
+ will cause the menubar to suddenly appear when the user
+ had requested it to be turned off! */
+ || f->output_data.w32->menubar_widget == NULL))
+ return 0;
+
+ {
+ deferred_msg msg_buf;
+
+ /* Detect if message has already been deferred; in this case
+ we cannot return any sensible value to ignore this. */
+ if (find_deferred_msg (hwnd, msg) != NULL)
+ abort ();
+
+ return send_deferred_msg (&msg_buf, hwnd, msg, wParam, lParam);
+ }
+
+ case WM_EXITMENULOOP:
+ f = x_window_to_frame (dpyinfo, hwnd);
+
+ /* Indicate that menubar can be modified again. */
+ if (f)
+ f->output_data.w32->menubar_active = 0;
+ goto dflt;
+
+ case WM_MEASUREITEM:
+ f = x_window_to_frame (dpyinfo, hwnd);
+ if (f)
+ {
+ MEASUREITEMSTRUCT * pMis = (MEASUREITEMSTRUCT *) lParam;
+
+ if (pMis->CtlType == ODT_MENU)
+ {
+ /* Work out dimensions for popup menu titles. */
+ char * title = (char *) pMis->itemData;
+ HDC hdc = GetDC (hwnd);
+ HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT);
+ LOGFONT menu_logfont;
+ HFONT old_font;
+ SIZE size;
+
+ GetObject (menu_font, sizeof (menu_logfont), &menu_logfont);
+ menu_logfont.lfWeight = FW_BOLD;
+ menu_font = CreateFontIndirect (&menu_logfont);
+ old_font = SelectObject (hdc, menu_font);
+
+ GetTextExtentPoint32 (hdc, title, strlen (title), &size);
+ pMis->itemWidth = size.cx;
+ pMis->itemHeight = GetSystemMetrics (SM_CYMENUSIZE);
+ if (pMis->itemHeight < size.cy)
+ pMis->itemHeight = size.cy;
+
+ SelectObject (hdc, old_font);
+ DeleteObject (menu_font);
+ ReleaseDC (hwnd, hdc);
+ return TRUE;
+ }
+ }
+ return 0;
+
+ case WM_DRAWITEM:
+ f = x_window_to_frame (dpyinfo, hwnd);
+ if (f)
+ {
+ DRAWITEMSTRUCT * pDis = (DRAWITEMSTRUCT *) lParam;
+
+ if (pDis->CtlType == ODT_MENU)
+ {
+ /* Draw popup menu title. */
+ char * title = (char *) pDis->itemData;
+ HDC hdc = pDis->hDC;
+ HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT);
+ LOGFONT menu_logfont;
+ HFONT old_font;
+
+ GetObject (menu_font, sizeof (menu_logfont), &menu_logfont);
+ menu_logfont.lfWeight = FW_BOLD;
+ menu_font = CreateFontIndirect (&menu_logfont);
+ old_font = SelectObject (hdc, menu_font);
+
+ /* Always draw title as if not selected. */
+ ExtTextOut (hdc,
+ pDis->rcItem.left + GetSystemMetrics (SM_CXMENUCHECK),
+ pDis->rcItem.top,
+ ETO_OPAQUE, &pDis->rcItem,
+ title, strlen (title), NULL);
+
+ SelectObject (hdc, old_font);
+ DeleteObject (menu_font);
+ return TRUE;
+ }
+ }
+ return 0;
+
+#if 0
+ /* Still not right - can't distinguish between clicks in the
+ client area of the frame from clicks forwarded from the scroll
+ bars - may have to hook WM_NCHITTEST to remember the mouse
+ position and then check if it is in the client area ourselves. */
+ case WM_MOUSEACTIVATE:
+ /* Discard the mouse click that activates a frame, allowing the
+ user to click anywhere without changing point (or worse!).
+ Don't eat mouse clicks on scrollbars though!! */
+ if (LOWORD (lParam) == HTCLIENT )
+ return MA_ACTIVATEANDEAT;
+ goto dflt;
+#endif
+
+ case WM_ACTIVATE:
+ case WM_ACTIVATEAPP:
+ case WM_WINDOWPOSCHANGED:
+ case WM_SHOWWINDOW:
+ /* Inform lisp thread that a frame might have just been obscured
+ or exposed, so should recheck visibility of all frames. */
+ my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
+ goto dflt;
+