->Run(); 前面加一句话:
SetWindowLong(Application->Handle, GWL_EXSTYLE, GetWindowLong(Application->Handle, GWL_EXSTYLE)|WS_EX_TOOLWINDOW);
就可以了。
--------------------------------------------------------------------------------
程序介绍
.DLL 文件:这是最关键的钩子的代码:
#include <vcl.h> #include "yb_base.h" //Victor 串口控件里面的一个头文件 #define MYAPPMARK "VICTOR_APPMONI_20010612" //共享内存标志 class __export THookedProcs { public: THookedProcs(); ~THookedProcs(); void WINAPI InitFuncs(void); void WINAPI UninitFuncs(void); private: HHOOK hThisHook; //保存钩子的句柄 static LRESULT CALLBACK HookedShellProc(int nCode, WPARAM wParam, LPARAM lParam); }; //定义共享的数据结构 typedef struct { HHOOK hHook; //当前使用的 HOOK //... 此处可增加其他共享的数据 } THookSharedData; THookedProcs::THookedProcs() { hThisHook = NULL; } THookedProcs::~THookedProcs() { UninitFuncs(); } void WINAPI THookedProcs::InitFuncs(void) { UninitFuncs(); hThisHook = SetWindowsHookEx(WH_SHELL, (HOOKPROC) HookedShellProc, HInstance, 0); TSharedMemory AppMem(MYAPPMARK,4096); //在 EXE 文件里共享的内存 THookSharedData *HookSharedData = ((THookSharedData*)(AppMem.AppInfo->Data)); //共享的数据 HookSharedData->hHook = hThisHook; //把 hThisHook 保存到共享内存里 } void WINAPI THookedProcs::UninitFuncs(void) { if(hThisHook) { UnhookWindowsHookEx(hThisHook); hThisHook = NULL; } } LRESULT CALLBACK THookedProcs::HookedShellProc(int nCode, WPARAM wParam, LPARAM lParam) { TSharedMemory AppMem(MYAPPMARK, 4096); //使用在 .EXE 文件里共享的内存 if(AppMem.Valid)if(AppMem.Exists) //如果共享内存存在 { HWND hMainWnd = AppMem.AppInfo->hMainForm; if(hMainWnd) { if(nCode==HSHELL_WINDOWCREATED) { PostMessage(hMainWnd, WM_USERCMD, UC_WINHOOK, wParam); } } } //在 Hook 里无法调用 hThisHook, 必须用共享内存里面的 hHook THookSharedData *HookSharedData = ((THookSharedData*)(AppMem.AppInfo->Data)); //共享的数据 return CallNextHookEx(HookSharedData->hHook, nCode, wParam, lParam); } -------------------------------------------------------------------------------- EXE文件主程序的代码: WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) { if(!AppMem.Valid) { return 1; } if(AppMem.Exists) //已经存在 (程序以前已经运行过了, 并且正在运行) { if(stricmp(lpCmdLine, "/SHOW")==0) //如果监测到命令行参数 /SHOW 就显示出已经运行的程序的主窗口 { PostMessage(AppMem.AppInfo->hMainForm, WM_USERCMD, UC_SHOWWIN, 0); } return 0; } AppMem.ClearBuffer(); try { Application->Initialize(); Application->CreateForm(__classid(TFormMain), &FormMain); //下面的语句是防止显示在状态栏和任务管理器 SetWindowLong(Application->Handle, GWL_EXSTYLE, GetWindowL
|