WM_DRAWITEM消息不能起作用

漂流的代码 2004-01-30 11:45:08
各位大虾,小弟在使用WM_DRAWITEM消息时居然没有任何反映,我的调用如下:
LRESLT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
.....
switch(message)
{
....
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpdis=(LPDRAWITEmSTRUCT)lParam;
HMENU hMenu=GetMenu(hWnd);
.....
}
...
}
return 0;
}

以上case WM_DRAWITEM的内容不能被执行,我是用来绘制自定义的菜单的。
我怀疑需要给对象指定特殊的风格,但是MSDN上找不到任何提示,用Spy++跟踪了很多窗口,也没有发现WM_DRAWITEM消息的影子,我不知道如何处理,很郁闷啊!
...全文
227 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingtsui 2004-01-30
  • 打赏
  • 举报
回复
楼上说得很对,更详细信息可以看看PlatformSDK的文档
User Interface Services/Windows User Interface/Resources/Menus/Menu Overviews/Using Menus的 Create Owner-Drawn Menu Items这一节

Creating Owner-Drawn Menu Items
If you need complete control over the appearance of a menu item, you can use an owner-drawn menu item in your application. This section describes the steps involved in creating and using an owner-drawn menu item.

Setting the Owner-Drawn Flag
Owner-Drawn Menus and the WM_MEASUREITEM Message
Owner-Drawn Menus and the WM_DRAWITEM Message
Owner-Drawn Menus and the WM_MENUCHAR Message
Setting Fonts for Menu-Item Text Strings
Example of Owner-Drawn Menu Items

Setting the Owner-Drawn Flag
You cannot define an owner-drawn menu item in your application's resource-definition file. Instead, you must create a new menu item or modify an existing one by using the MFT_OWNERDRAW menu flag.

You can use the InsertMenuItem or SetMenuItemInfo function to specify an owner-drawn menu item. Use InsertMenuItem to insert a new menu item at the specified position in a menu bar or menu. Use SetMenuItemInfo to change the contents of a menu.

When calling these two functions, you must specify a pointer to a MENUITEMINFO structure, which specifies the properties of the new menu item or the properties you want to change for an existing menu item. To make an item an owner-drawn item, specify the MIIM_FTYPE value for the fMask member and the MFT_OWNERDRAW value for the fType member.

By setting the appropriate members of the MENUITEMINFO structure, you can associate an application-defined value, which is called item data, with each menu item. To do so, specify the MIIM_DATA value for the fMask member and the application-defined value for the dwItemData member.

You can use item data with any type of menu item, but it is particularly useful for owner-drawn items. For example, suppose a structure contains information used to draw a menu item. An application might use the item data for a menu item to store a pointer to the structure. The item data is sent to the menu's owner window with the WM_MEASUREITEM and WM_DRAWITEM messages. To retrieve the item data for a menu at any time, use the GetMenuItemInfo function.

Applications written for earlier versions of the system can continue to call AppendMenu, InsertMenu, or ModifyMenu to assign the MF_OWNERDRAW flag to an owner-drawn menu item.

When you call any of these three functions, you can pass a value as the lpNewItem parameter. This value can represent any information that is meaningful to your application, and that will be available to your application when the item is to be displayed. For example, the value could contain a pointer to a structure; the structure, in turn, might contain a text string and a handle to the logical font your application will use to draw the string.

ross33123 2004-01-30
  • 打赏
  • 举报
回复
You cannot define an owner-drawn menu item in your application's resource definition file. Instead, you must create a new menu item or modify an existing one by using the MFT_OWNERDRAW menu flag.

You can use the InsertMenuItem or SetMenuItemInfo function to specify an owner-drawn menu item
漂流的代码 2004-01-30
  • 打赏
  • 举报
回复
Tank you the two browser helping!The score fellow the sloving

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧