#include
//save the module handle, release the DLL when the need to use
The static HMODULE gLibModule=0;
//used to hold the clock window of the original process, the DLL when unloading should restore
The static LONG_PTR gOldWndProc=0;
//find the clock window handle
The static HWND FindClockWindow ()
{
HWND h=FindWindow (TEXT (" Shell_TrayWnd "), nullptr);
If (IsWindow (h))
{
H=FindWindowEx (h, 0, TEXT (" TrayNotifyWnd "), nullptr);
If (IsWindow (h))
{
Return FindWindowEx (h, 0, TEXT (" TrayClockWClass "), nullptr);
}
}
return 0;
}
The static DWORD WINAPI FreeSelf (LPVOID param)
{
FreeLibraryAndExitThread (gLibModule EXIT_SUCCESS);
}
The static void RestoreWndProc ()
{
If (gOldWndProc!=0)
SetWindowLongPtr (FindClockWindow (), GWLP_WNDPROC gOldWndProc);
}
//new window processing, core work is here
LRESULT a CALLBACK ClockWndProc (HWND HWND, UINT uMsg, WPARAM WPARAM, LPARAM LPARAM)
{
//in order to receive left-click the mouse right click on the message, must make Windows thought we were "hit" the workspace
If (uMsg==WM_NCHITTEST)
Return HTCLIENT;
//processing left-click the mouse events
If (uMsg==WM_LBUTTONUP)
{
ShellExecute (0, TEXT (" open "), TEXT (" http://blog.csdn.net/aqtata "), nullptr, nullptr, SW_SHOW);
return 0;
}
//handle the mouse right click on the event, here we unload the DLL (itself)
If (uMsg==WM_RBUTTONUP)
{
RestoreWndProc ();
The CloseHandle (CreateThread (nullptr, 0, (LPTHREAD_START_ROUTINE) FreeSelf, nullptr, 0, nullptr));
return 0;
}
Return WNDPROC (gOldWndProc) (hWnd uMsg, wParam, lParam);
}
BOOL APIENTRY DllMain (HMODULE HMODULE, dwords ul_reason_for_call LPVOID lpReserved)
{
The switch (ul_reason_for_call)
{
Case DLL_PROCESS_ATTACH:
{
GLibModule=hModule;
HWND hClock=FindClockWindow ();
If (IsWindow (hClock))
{
GLibModule=hModule;
GOldWndProc=GetWindowLongPtr (hClock GWLP_WNDPROC);
If (gOldWndProc!=0)
{
SetWindowLongPtr (hClock GWLP_WNDPROC, (LONG_PTR) & amp; ClockWndProc);
}
}
break;
}
Case DLL_PROCESS_DETACH:
{
RestoreWndProc ();
break;
}
}
Return TRUE;
}
CodePudding user response:
What is the purpose of your transformation language?If you want to use VB to compile this DLL code, that you used in the first place that several API functions written in TLB,
Again in the DLL project reference corresponding TLB,
If you need is a function of "transplant", it is basically a transplant "find the clock window" and "callback"
These two functions, "entrance" and "release" of the DLL function is not needed,