Permalink
Browse files

[Win32] Fix status icon menu assignment

  • Loading branch information...
1 parent 79038e3 commit fc21101f747254bbe8e2636b16771ae917840e18 @milani milani committed Nov 6, 2012
Showing with 23 additions and 6 deletions.
  1. +2 −1 src/native_menu/native_menu_win.cpp
  2. +21 −5 src/native_status_icon/native_status_icon_win.cpp
View
3 src/native_menu/native_menu_win.cpp
@@ -64,9 +64,10 @@ int NativeMenu::AddSubMenu(HMENU& menu,Settings* settings){
menuItemInfo.fMask = MIIM_DATA;
menuItemInfo.dwTypeData = label;
menuItemInfo.dwItemData =(ULONG_PTR) actionCb;
+ menuItemInfo.cch = wcslen(label);
if( wcslen(label) == 0 ) {
- menuItemInfo.fType = MIIM_TYPE;
+ menuItemInfo.fMask |= MIIM_TYPE;
menuItemInfo.fType = MF_SEPARATOR;
} else {
menuItemInfo.fMask |= MIIM_STRING;
View
26 src/native_status_icon/native_status_icon_win.cpp
@@ -37,10 +37,16 @@ LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
menuItem.fMask = MIIM_DATA;
int idx = wParam;
GetMenuItemInfo(menu,idx,TRUE,&menuItem);
+
appjs::appjs_action_callback* actionCallback = (appjs::appjs_action_callback*) menuItem.dwItemData;
- v8::Persistent<v8::Object> action = actionCallback->action;
appjs::NativeMenu* nativeMenu = actionCallback->menu;
+ if( actionCallback == NULL) {
+ return 0;
+ }
+
+ v8::Persistent<v8::Object> action = actionCallback->action;
+
if(action->IsCallable()) {
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = {actionCallback->item};
@@ -72,10 +78,20 @@ LRESULT CALLBACK StatusIconProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l
HMENU popup = CreatePopupMenu();
int loop = GetMenuItemCount(hPop);
for(int i = 0; i < loop; i++) {
- TCHAR* menuTitle = new TCHAR[1000];
- GetMenuString(hPop,i,menuTitle,1000,MF_BYPOSITION);
- AppendMenu(popup,MF_POPUP, (UINT)GetSubMenu(hPop,i), menuTitle);
-// AppendMenu(popup,MF_POPUP, (UINT)GetMenuItemID(hPop,i), menuTitle);
+ TCHAR* menuTitle = new TCHAR[256];
+ GetMenuString(hPop,i,menuTitle,256,MF_BYPOSITION);
+ if(IsMenu(GetSubMenu(hPop,i))) {
+ AppendMenu(popup,MF_POPUP, (UINT)GetSubMenu(hPop,i), menuTitle);
+ } else {
+ MENUITEMINFO menuItem;
+ menuItem.cbSize = sizeof(MENUITEMINFO) - 4;
+ menuItem.fMask = MIIM_DATA | MIIM_STRING;
+ menuItem.dwItemData = NULL;
+ menuItem.dwTypeData = NULL;
+ GetMenuItemInfo(hPop,i,TRUE,&menuItem);
+ menuItem.dwTypeData = menuTitle;
+ InsertMenuItem(popup,i,TRUE,&menuItem);
+ }
}
MENUINFO menuInfo;

0 comments on commit fc21101

Please sign in to comment.