home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 May
/
PCWorld_2003-05_cd.bin
/
Software
/
Vyzkuste
/
rbtray
/
rbhook.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-04-20
|
3KB
|
99 lines
#include <windows.h>
#include "rbtray.h"
#ifdef DBG
#define dbg(X,Y) PostMessage(FindWindow(NAME, NAME),WM_DBG,(WPARAM)Y,(LPARAM)X);
#else
#define dbg(X,Y)
#endif
static HHOOK hMouse=NULL,
hCall =NULL,
hMsg =NULL;
static HWND LastHit;
LRESULT CALLBACK
MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode<0)return CallNextHookEx(hMouse, nCode, wParam, lParam);
if (wParam == WM_NCRBUTTONDOWN
&& ((MOUSEHOOKSTRUCT*)lParam)->wHitTestCode == HTREDUCE)
{
LastHit=((MOUSEHOOKSTRUCT*)lParam)->hwnd;
};
if (wParam == WM_NCRBUTTONUP && LastHit==((MOUSEHOOKSTRUCT*)lParam)->hwnd
&& ((MOUSEHOOKSTRUCT*)lParam)->wHitTestCode == HTREDUCE)
{
LastHit=(HWND)NULL;
PostMessage(FindWindow(NAME, NAME), WM_MYCMD, wParam,
(LPARAM)(((MOUSEHOOKSTRUCT*)lParam)->hwnd));
}
return CallNextHookEx(hMouse, nCode, wParam, lParam);
};
LRESULT CALLBACK
GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
int i;
HMENU hSysMenu;
if (nCode<0)return CallNextHookEx(hMsg, nCode, wParam, lParam);
if (((MSG*)lParam)->message==WM_SIZE)
{
dbg("WM_SIZE",((MSG*)lParam)->hwnd);
};
if (((MSG*)lParam)->message==WM_SYSCOMMAND &&
LOWORD(((MSG*)lParam)->wParam) == IDM_TRAY)
{
PostMessage(FindWindow(NAME, NAME), WM_MYCMD,((MSG*)lParam)->message,(LPARAM)(((MSG*)lParam)->hwnd));
dbg("WM_SYSCOMMAND",((MSG*)lParam)->hwnd);
};
if (((MSG*)lParam)->message==WM_PAINT)
{
hSysMenu=GetSystemMenu(((MSG*)lParam)->hwnd, FALSE);
for(i=0;i<GetMenuItemCount(hSysMenu) && hSysMenu;i++)
if(GetMenuItemID(hSysMenu,i)==IDM_TRAY) hSysMenu=0;
if (hSysMenu)
{
InsertMenu (hSysMenu, GetMenuItemID(hSysMenu,0),MF_STRING,IDM_TRAY, "Minimize in tray");
InsertMenu (hSysMenu, GetMenuItemID(hSysMenu,1),MF_SEPARATOR,IDM_TRAY+1, NULL) ;
}
};
return 0;
};
LRESULT CALLBACK
CallWndProc(int hCode,WPARAM wParam,LPARAM lParam)
{
CWPSTRUCT *pcwps;
pcwps = (CWPSTRUCT*)lParam;
if (hCode >= 0 && pcwps && pcwps->hwnd && pcwps->message==WM_SHOWWINDOW)
{
PostMessage(FindWindow(NAME, NAME),WM_SHOWWINDOW,0,(WPARAM)(pcwps->hwnd));
return 0;
}
return CallNextHookEx(NULL, hCode, wParam, lParam);
}
BOOL DLLIMPORT
RegisterHook(HMODULE hLib)
{
hMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseProc, hLib, 0);
hMsg = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)GetMsgProc, hLib, 0);
hCall = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)CallWndProc, hLib, 0);
if(hMouse==NULL || hMsg==NULL || hCall==NULL)
{
UnRegisterHook();
return FALSE;
}
return TRUE;
}
void DLLIMPORT
UnRegisterHook(void)
{
if(hMouse)UnhookWindowsHookEx(hMouse);
if(hMsg) UnhookWindowsHookEx(hMsg);
if(hCall) UnhookWindowsHookEx(hCall);
}