Como saber se alguém lidou com o ONCONTEXTMENU
-
26-09-2019 - |
Pergunta
eu tenho um CWnd
classe derivada que tem um WM_CONTEXTMENU
manipulador (OnContextMenu
), que tem meu menu de contexto padrão. Esta aula está sendo usada em vários lugares da minha aplicação.
Alguns dos lugares onde está sendo usado também lidam com o WM_CONTEXTMENU
no nível dos pais (o pai da janela). Eles basicamente substituem o menu de contexto padrão.
Quando estou dentro do CWnd
Classe derivada, eu basicamente quero saber se alguém (um pai da janela) lidou com o menu de contexto.
por exemplo:
void MyDerivedWnd::OnContextMenu( CWnd* in_pWnd, CPoint in_point )
{
LRESULT res = __super::Default();
// Now, how to I know of something happened inside __super::Default();??
// Show my default menu
// ...
}
É possível através da estrutura Win32/MFC?
Solução
Encontrei uma maneira de descobrir se algo aconteceu durante a implementação do manipulador padrão. Pode não ser a solução mais elegante, mas aqui está:
bool g_bWindowCreated = false;
HHOOK g_hHook = NULL;
LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam)
{
if( code == HCBT_CREATEWND )
g_bWindowCreated = true;
return CallNextHookEx( g_hHook, code, wParam, lParam );
}
void MyDerivedWnd::OnContextMenu( CWnd* in_pWnd, CPoint in_point )
{
// Setup a hook to know if a window was created during the
// Default WM_CONTEXT_MENU handler
g_bWindowCreated = false;
g_hHook = SetWindowsHookEx( WH_CBT, HookProc, NULL, GetCurrentThreadId() );
// Call the default handler
LRESULT res = __super::Default();
UnhookWindowsHookEx( g_hHook );
if( !g_bWindowCreated )
{
// Show my default menu
// ...
}
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow