c++ - GetMenuItemInfo does not set fType with MIIM_TYPE -
i have been working winapi little bit, making project owner draw on menus. when called getmenuiteminfo
, sets text of menu item, not ftype uint variable flags.
have declared:
menuitem->fmask = miim_type
and msdn says:
miim_type retrieves or sets ftype , dwtypedata members.
i don't know if got confused miim_type flag.
here code:
void setownerdrawmenu(hmenu * menu) { menuif * menu_item_information; hmenu sub_menu_ocational; uint uid_menuitem; int nmenucountitems = getmenuitemcount(*menu); menuiteminfo * menuitem = (menuiteminfo*)malloc(sizeof(menuiteminfo)); for(int i=0;i<nmenucountitems;i++) { menu_item_information = (menuif*)malloc(sizeof(menuif)); menu_item_information->isseparator=false; menu_item_information->max_width=0; sub_menu_ocational = 0; uid_menuitem = getmenuitemid(*menu,i); memset(&menuitem,0,sizeof(menuitem)); menuitem = (menuiteminfo*)malloc(sizeof(menuiteminfo)); menuitem->cbsize = sizeof(menuitem); menuitem->fmask = miim_type; menuitem->cch = max_odm_cch; menuitem->dwtypedata = menu_item_information->szitemtext; getmenuiteminfo(*menu,uid_menuitem,false,menuitem); uint final_flags = mf_byposition | mf_ownerdraw; if( ( mft_separator & menuitem->ftype ) == mft_separator ) { final_flags |= mf_separator; menu_item_information->isseparator = true; } else { // not important stuff } sub_menu_ocational = getsubmenu(*menu,i); if(sub_menu_ocational!=null) { modifymenu(*menu,i,final_flags,0,(lpctstr)menu_item_information); // got submenu, repeat operation setownerdrawmenu(&sub_menu_ocational); } else { modifymenu(*menu,i,final_flags,0,(lpctstr)menu_item_information); } } }
i inserting menus insertmenu
function:
insertmenu(tid_cmenu,0,mf_byposition | mf_separator,0,null); insertmenu(tid_cmenu,0, mf_byposition | mf_string, tid_exit, "exit");
exactly, why getmenuiteminfo
not retriving ftype?
if checking return code getmenuiteminfo
see failing. error in line:
menuitem->cbsize = sizeof(menuitem);
the menuiteminfo::cbsize
member supposed set size of menuiteminfo
structure, setting size of menuiteminfo*
pointer (i.e. 4 or 8 bytes, depending on platform).
change code to:
menuitem->cbsize = sizeof(menuiteminfo);
also, code allocating menuitem
outside loop, once per-iteration inside loop, leaking memory.
Comments
Post a Comment