81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
//---------------------------------------------------------------------------
|
|
#pragma hdrstop
|
|
#include <tchar.h>
|
|
#include "MenuHookUnit.h"
|
|
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
|
|
WNDPROC MenuOldWndProc;
|
|
|
|
LRESULT CALLBACK MenuWndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
LRESULT ret;
|
|
switch( Msg ){
|
|
case WM_CREATE:
|
|
ret = CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
|
|
{
|
|
//去除边界
|
|
DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
|
|
dwStyle &= ~( WS_BORDER | WS_DLGFRAME );
|
|
SetWindowLong(hWnd, GWL_STYLE, dwStyle );
|
|
|
|
//去除框架
|
|
DWORD dwStyleEx = GetWindowLong(hWnd, GWL_EXSTYLE);
|
|
dwStyleEx &= ~( WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE );
|
|
SetWindowLong(hWnd, GWL_EXSTYLE, dwStyleEx);
|
|
}
|
|
return ret;
|
|
|
|
case WM_PRINT:
|
|
return CallWindowProc( MenuOldWndProc, hWnd, WM_PRINTCLIENT, wParam, lParam );
|
|
|
|
case WM_WINDOWPOSCHANGING:
|
|
{
|
|
//将菜单大小改小
|
|
PWINDOWPOS lpPos = PWINDOWPOS(lParam);
|
|
int deltaX = GetSystemMetrics(SM_CXEDGE) + GetSystemMetrics(SM_CXFOCUSBORDER);
|
|
int deltaY = GetSystemMetrics(SM_CYEDGE) + GetSystemMetrics(SM_CYFOCUSBORDER);
|
|
|
|
lpPos->cx -= 2 * deltaX;
|
|
lpPos->cy -= 2 * deltaY;
|
|
}
|
|
return CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
|
|
|
|
case WM_GETICON:
|
|
return 0;
|
|
|
|
case WM_NCPAINT:
|
|
return CallWindowProc( MenuOldWndProc, hWnd, WM_PRINT, wParam, lParam );
|
|
|
|
default:
|
|
return CallWindowProc( MenuOldWndProc, hWnd, Msg, wParam, lParam );
|
|
}
|
|
}
|
|
|
|
LRESULT CALLBACK WindowsHook( int Code, UINT wParam, long lParam)
|
|
{
|
|
PCWPSTRUCT pStruct;
|
|
WNDPROC lastWndProc;
|
|
TCHAR strClassName[64];
|
|
|
|
pStruct = (PCWPSTRUCT)lParam;
|
|
|
|
//捕捉菜单创建WM_CREATE和0x01E2消息,检查是否菜单窗口
|
|
if( Code==HC_ACTION && ( pStruct->message==WM_CREATE || pStruct->message==0x01E2 ) &&
|
|
GetClassName(pStruct->hwnd, strClassName, sizeof(strClassName))==6 &&
|
|
_tcscmp(strClassName, L"#32768")==0 ){
|
|
lastWndProc = (WNDPROC)GetWindowLong( pStruct->hwnd, GWL_WNDPROC );
|
|
|
|
if( lastWndProc!=MenuWndProc ){
|
|
//替换菜单窗口过程函数
|
|
SetWindowLong( pStruct->hwnd, GWL_WNDPROC, (long)MenuWndProc );
|
|
//保留旧的窗口过程
|
|
MenuOldWndProc = lastWndProc;
|
|
}
|
|
}
|
|
|
|
return CallNextHookEx( (HHOOK)WH_CALLWNDPROC, Code, wParam, lParam );
|
|
}
|
|
|