atePopupMenu和TrackPopupMenu时拦截WM

atePopupMenu和TrackPopupMenu时拦截WM

本文介绍了使用CreatePopupMenu和TrackPopupMenu时拦截WM_NCPAINT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何拦截使用CreatePopupMenu创建并使用TrackPopupMenu显示的弹出菜单窗口的WM_NCPAINT消息?有没有办法将应用程序定义的WindowProc分配给只有HMENU句柄的菜单?



我可以在父窗口的WM_INITMENUPOPUP处理程序中获取弹出窗口的句柄with

Hello,

how can i intercept WM_NCPAINT message of a popup menu window created with CreatePopupMenu and displayed with TrackPopupMenu? Is there a way to assign an application defined WindowProc to a menu having only a HMENU handle?

I can get the handle to the popup window in the parent window's WM_INITMENUPOPUP handler with

HWND hMenuWnd = FindWindow("#32768", NULL);





现在,如果我此时通过SetWindowLong设置GWL_WNDPROC属性,这会有效吗?



您的建议将受到高度赞赏!



Now, will this work if i set the GWL_WNDPROC property through SetWindowLong at this point?

Your advice will be highly appreciated!

推荐答案


LRESULT CALLBACK MenuButton::WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
	{
		TRACE("menubutton::wndproc message = %x, wparam = %x\n", message, wparam);
		if (message == WM_KEYDOWN && wparam == VK_LEFT) {
			MenuButton* prev = dynamic_cast<menubutton*>(prevWidget());
			if (prev) {
				cancelMenu(Widget::hwnd());
				fnNativePoint pt(1,1);
				prev->clientToNativePt(pt);
				PostMessage(Widget::hwnd(), WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
				return 0;
			}
			return 0;
		} else if (message == WM_KEYDOWN && wparam == VK_RIGHT) {
			MenuButton* next = dynamic_cast<menubutton*>(nextWidget());
			if (next) {
				cancelMenu(Widget::hwnd());
				fnNativePoint pt(1,1);
				next->clientToNativePt(pt);
				PostMessage(Widget::hwnd(), WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
				return 0;
			}
		}
		return CallWindowProc(prevWndProc_, hwnd, message, wparam, lparam);
	}





在上面我模拟了窗口默认菜单栏的下一个/上一个功能。 cancelMenu(hwnd)将WM_CANCELMODE发送到父窗口。



In above I simulate the next/prev feature of window's default menu bar. cancelMenu(hwnd) send WM_CANCELMODE to parent window.


这篇关于使用CreatePopupMenu和TrackPopupMenu时拦截WM_NCPAINT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:22