I tried the following code for creating the menu in a thread. However nothing appears. TrackPopupMenuEx returns 0, GetLastError returns 0.
Code:
typedef struct popupMenuStruct
{
HMENU *menu;
HWND *wnd;
int x, y;
};
DWORD WINAPI DisplayPopupMenu( void *v )
{
popupMenuStruct *PMS = (popupMenuStruct*) v;
int ret = TrackPopupMenuEx( *PMS->menu,
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD |
TPM_LEFTBUTTON | TPM_HORIZONTAL,
PMS->x,
PMS->y,
*PMS->wnd,
NULL );
printf( "TrackPopupMenuEx: %d\n", ret );
printf( "error: %d\n", GetLastError() );
return 0;
}
...
popupMenuStruct *popupInfo = new popupMenuStruct;
popupInfo->menu = &userInfoMenu;
popupInfo->wnd = &WindowHandle;
popupInfo->x = 100;
popupInfo->y = 100;
CreateThread( NULL, 0, &DisplayPopupMenu, (void*)popupInfo, 0, NULL );