tags:

views:

54

answers:

1

Here is what I'm doing. I'v created a combobox but I'm not using it for that. When I click it, it calls trackpopup and brings up a context menu. However after I'v clicked the context menu, I'd like it to close the combobox in the same way it would if you clicked anywhere (killing the focus) or selected an item from the combobox.

Here's the event for the combobox:

 if(uMsg == WM_COMMAND)
 {

  HMENU m;
  m = CreatePopupMenu();
  MENUITEMINFO itm;
  itm.cbSize = sizeof(MENUITEMINFO);
  itm.fMask = MIIM_FTYPE | MIIM_STRING;
  itm.fType = MIIM_STRING;
  itm.dwTypeData = "Kill time";
  itm.cch = 12;
POINT p;
GetCursorPos(&p);
  InsertMenuItem(m,4,false,&itm);

  if((int)HIWORD(wParam) == CBN_DROPDOWN)
  {
   SendMessage(engineGL.controls.TopSelHwnd,WM_KILLFOCUS,(WPARAM)engineGL.controls.TopSelHwnd,0);
   SendMessage(engineGL.controls.TopSelHwnd,WM_IME_SETCONTEXT,(WPARAM)0,(LPARAM)ISC_SHOWUIALL);

   TrackPopupMenu(m,0,p.x,p.y,NULL,hWnd,NULL);
    SendMessage(hWnd,WM_KILLFOCUS,0,0);

   SetFocus(HWND_DESKTOP);

  }

  return 1;
 } 

How can I make it so that after I click an item on the context menu, the combobox closes properly as if I'd actually chosen an item from it?

Thanks

+1  A: 

I'm not sure. Need to try your code. However I'm sure that one should not send the WM_KILLFOCUS message manually. Instead you need to set the focus to another window by calling SetFocus. The OS will automatically send messages to the window losing the focus and the new window that is gaining the focus.

valdo