AxibugEmuOnline/References/VirtuaNESex_src_191105/WndHook.cpp

77 lines
1.7 KiB
C++
Raw Normal View History

2024-08-05 17:58:53 +08:00
//
// <20><><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>t<EFBFBD>B<EFBFBD><42><EFBFBD>^<5E><><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>T<EFBFBD>|<7C>[<5B>g<EFBFBD>N<EFBFBD><4E><EFBFBD>X
//
#include "DebugOut.h"
#include "App.h"
#include "Wnd.h"
#include "WndHook.h"
// Instance
CWndHook WndHook;
BOOL CWndHook::m_bMsgFiltering = FALSE;
BOOL CWndHook::m_bMsgFilter = FALSE;
HHOOK CWndHook::m_hOldMsgFilter = NULL;
// <20><><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>t<EFBFBD>B<EFBFBD><42><EFBFBD>^<5E>t<EFBFBD>b<EFBFBD>N<EFBFBD>̏<EFBFBD><CC8F><EFBFBD><EFBFBD><EFBFBD>(<28>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><C482><EFBFBD><EFBFBD>Ăяo<D18F><6F><EFBFBD><EFBFBD>)
void CWndHook::Initialize()
{
m_hOldMsgFilter = ::SetWindowsHookEx( WH_MSGFILTER, (HOOKPROC)MessageFilterProc, NULL, ::GetCurrentThreadId() );
}
void CWndHook::Release()
{
if( m_hOldMsgFilter ) {
::UnhookWindowsHookEx( m_hOldMsgFilter );
m_hOldMsgFilter = NULL;
}
}
// <20><><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>t<EFBFBD>B<EFBFBD><42><EFBFBD>^<5E><><EFBFBD><EFBFBD>(<28>_<EFBFBD>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD>͕<EFBFBD><CD95>ʂł͗<C582><CD97>Ȃ<EFBFBD><C882><EFBFBD><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD><57><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E982BD>)
LRESULT CALLBACK CWndHook::MessageFilterProc( INT code, WPARAM wParam, LPARAM lParam )
{
if( code < 0 ) {
return ::CallNextHookEx( m_hOldMsgFilter, code, wParam, lParam );
}
if( m_bMsgFiltering && code == MSGF_DIALOGBOX ) {
// <20><><EFBFBD>Ƀt<C983>B<EFBFBD><42><EFBFBD>^<5E><><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>H
if( m_bMsgFilter )
return FALSE;
m_bMsgFilter = TRUE;
LPMSG lpMsg = (LPMSG)lParam;
if( lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST ) {
if( WalkPreTranslateTree( lpMsg ) ) {
m_bMsgFilter = FALSE;
return 1L;
}
}
m_bMsgFilter = FALSE;
}
return ::CallNextHookEx( m_hOldMsgFilter, code, wParam, lParam );
// return FALSE;
}
BOOL CWndHook::WalkPreTranslateTree( MSG* lpMsg )
{
// <20><><EFBFBD>C<EFBFBD><43><EFBFBD>t<EFBFBD><74><EFBFBD>[<5B><><EFBFBD>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E
HWND hWndStop = CApp::GetHWnd();
// PreTranslateMessage<67><65><EFBFBD>H<EFBFBD><48>
for( HWND hWnd = lpMsg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd) ) {
if( hWnd == hWndStop )
break;
CWnd* pWnd = (CWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
if( pWnd ) {
if( pWnd->PreTranslateMessage( lpMsg ) )
return TRUE;
}
if( hWnd == hWndStop )
break;
}
return FALSE;
}