//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
//---------------------------------------------------------------------------
#include "rsrc.h"
#include "ENMENU.H"
//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
HWND hGUI;
BOOL (WINAPI *InstMenuHook)(TMeta);
BOOL (WINAPI *UnstMenuHook)(void);
char DllName[]="MenuHook.dll";
HWND hPause,hLblWnd,hLblMenu;//hLbAbt1,hLbAbt2;
HWND hWnd;
HMENU hMenu;
BOOL Pause=TRUE;
HINSTANCE HHookDll;
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// g_hInstance=hInstance;
HWND hWnd;
HRSRC hRsrc;
HGLOBAL hMem;
DWORD dwSize,dwSizeDone;
BYTE *Buf,*RsrcBuf;
HANDLE hFile;
hWnd=FindWindow(
MAKEINTRESOURCE(32770),
"灰色菜单克星"
);
if(hWnd){
ShowWindow (hWnd,SW_RESTORE);
SetForegroundWindow (hWnd);
return 1;
}
else{
hFile=CreateFile(//将嵌入在资源里的MenuHook.dll释放的同层文件夹
DllName, // pointer to name of the file
GENERIC_WRITE, // access (read-write) mode
0, // share mode
NULL, // pointer to security attributes
CREATE_NEW, // how to create
FILE_ATTRIBUTE_NORMAL, // file attributes
NULL // handle to file with attributes to copy
);
if(hFile!=(HANDLE)0xffffffff){(//将嵌入在资源里的MenuHook.dll释放的同层文件夹
hRsrc=FindResource(hInstance,MAKEINTRESOURCE(IDR_MENUHOOKDLL),RT_RCDATA);
dwSize=SizeofResource(hInstance,hRsrc);
hMem=LoadResource(hInstance,hRsrc);
RsrcBuf=LockResource(hMem);
Buf=(BYTE *)malloc(dwSize);
memcpy(Buf,RsrcBuf,dwSize);
WriteFile(
hFile, // handle to file to write to
Buf, // pointer to data to write to file
dwSize, // number of bytes to write
&dwSizeDone, // pointer to number of bytes written
NULL // pointer to structure for overlapped I/O
);
CloseHandle(hFile);
}
HHookDll=LoadLibrary(DllName);
InstMenuHook=(BOOL (WINAPI *)(TMeta))GetProcAddress(HHookDll,"InstMenuHook");
UnstMenuHook=(BOOL (WINAPI *)(void))GetProcAddress(HHookDll,"UnstMenuHook");
if(((DWORD)HHookDll &(DWORD) InstMenuHook & (DWORD)UnstMenuHook))
return DialogBox(hInstance,MAKEINTRESOURCE(TEnMenu),NULL, (DLGPROC)WinProc);
else
return 1;
}
}
//---------------------------------------------------------------------------
// Message handler for gui
LRESULT CALLBACK WinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
TMeta Meta;
int Cnt,nPos;
char TextBuf[16];
switch (message)
{
case WM_INITDIALOG:
hGUI=hDlg;
ShowWindow(hDlg, SW_SHOWDEFAULT);
UpdateWindow(hDlg);
SetWindowPos(hGUI,HWND_TOPMOST,NULL,NULL,NULL,NULL,SWP_NOMOVE|SWP_NOSIZE);
hPause=FindWindowEx(hDlg,NULL,"Button","开始(&S)");
hLblWnd=FindWindowEx(hDlg,NULL,"Static","66666666");
hLblMenu=FindWindowEx(hDlg,NULL,"Static","88888888");
/*
hLbAbt1=FindWindowEx(hDlg,NULL,"Static","By DebugAnyway 21/03/2009");
hLbAbt2=FindWindowEx(hDlg,NULL,"Static","QQ = 1048485");
EnableWindow(hLbAbt1,FALSE);
EnableWindow(hLbAbt2,FALSE);
*/
return TRUE;
case WM_LBUTTONDOWN:
ReleaseCapture();
SendMessage(hDlg,WM_NCLBUTTONDOWN,HTCAPTION,0);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
UnstMenuHook();
FreeLibrary(HHookDll);
DeleteFile(DllName);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
case IDPAUSE:
if(Pause==TRUE){//Paused
Pause=FALSE;
SetWindowText(hPause,"暂停(&P)");
InstMenuHook(Meta);
}
else{//Running
UnstMenuHook();
SetWindowText(hPause,"运行(&S)");
Pause=TRUE;
}
break;
}
break;
case WM_HOTKEY:
// OnHotKey(wParam);
break;
case WM_OBJ_MENU:
hWnd=(HANDLE)wParam;
hMenu=(HANDLE)lParam;
Cnt=GetMenuItemCount(hMenu);
for(nPos=0;nPos<Cnt;nPos++){
EnableMenuItem(
hMenu,
nPos,
MF_ENABLED|MF_BYPOSITION
);
}
sprintf(TextBuf,"%08X",(DWORD)hWnd);
SetWindowText(hLblWnd,TextBuf);
if(hMenu){
sprintf(TextBuf,"%08X",(DWORD)hMenu);
SetWindowText(hLblMenu,TextBuf);
}
break;
}
return FALSE;
}
//---------------------------------------------------------------------------