请问: 如何给子窗口添加菜单我建了一人对话框,设置了它的child窗口.当我在InitDialog()中加入如下代码之后, 为何显示不出菜单:
m_hMenu= ::LoadMenu(...);
::SetMenu(m_hMenu);谢谢先...
m_hMenu= ::LoadMenu(...);
::SetMenu(m_hMenu);谢谢先...
解决方案 »
- 如何把对话框显示在单文档工程文件的主窗口
- 控件中调用有创建线程的动态库问题
- 如何从ITypeInfo接口返回类型信息
- 求一代码用原始套接字写一个发送字符串的程序(服务端和客户端).
- 请问多语言多coder的开发环境下,如何作好代码的版本控制?用什么工具?
- 问一下,在VC中用DWORD LPCTSTR BSTR等定义变量和用C++中的CHAR STRING * INT只类的比有什么好处啊?区别?
- 请问如何在一篇word文档的最后,添加新的一行或段落。
- 如何实现一个自己定义的IP头?
- 谁知道学习Com+什么书比较好?
- opencv3.0------BackgroundSubtractorMOG的头文件
- 人生不如意,散
- 极度郁闷一下。
Dialog的属性没有修改,就是说既没有改成Child,也没有指定Menu
然后再Dialog的class里加一个成员变量CMenu *m_pMenu;
在OnInitDialog里
m_pMenu = new CMenu;
m_pMenu->LoadMenu(IDR_MAINMENU);
SetMenu(m_pMenu);
就OK了
子窗口不能有菜单。
你看一下 CreateWindowEx() 函数就应该明白,在系统维护的窗口内部结构里,菜单句柄和子窗口 ID 共用一个变量,不是子窗口时,该变量表示菜单句柄,否则为子窗口 ID。
长见识了,明天到公司时一定看看CreateWindowEx的源码
CreateWindowEx
The CreateWindowEx function creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the CreateWindow function. For more information about creating a window and for full descriptions of the other parameters of CreateWindowEx, see CreateWindow. HWND CreateWindowEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // menu handle or child identifier //注意这个
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // window-creation data
);
下面看看解释:hMenu
[in] Handle to a menu, or specifies a child-window identifier, depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
直接在VC中对话框的“属性”里的Menu下拉框里选择菜单ID就可以了。
看了半天WINMDI.CPP,就是没想起来看看MSDN