This function can return a combination of the PSL_OK and PSL_STOP flags:
// undocumented, not in import lib
void (WINAPI *SwitchToThisWindow)(HWND, int) = NULL;
// not in win95, but we can live without it
BOOL (WINAPI *dAlphaBlend)( IN HDC, IN int, IN int, IN int, IN int,
IN HDC, IN int, IN int, IN int, IN int, IN BLENDFUNCTION) = NULL;
// not in win95, but we can emulate it
HWND WINAPI GetAncestor95(HWND hWnd, UINT rootOwner);
HWND (WINAPI *dGetAncestor)(HWND, UINT) = &GetAncestor95;
lsLinkItem DynFuncs[] =
{
// anything before the first dll is linked from USER32.DLL
{ "SwitchToThisWindow", (int**)(&SwitchToThisWindow) },
{ "GetAncestor", (int**)(&dGetAncestor) },
// now import things from a different library
{ "MSIMG32.DLL", NULL },
{ "AlphaBlend", (int**)(&dAlphaBlend) },
// end of list marker
{ NULL, NULL }
};
LSLinkFunctions(DynFuncs);
There are two reasons to link this way instead of using an import library:
char *ColorStrings[] = { "red", "green", "blue", NULL };
int GetColorComponent(const char *comp,COLORREF color)
{
switch (LSStringEnum(comp,ColorStrings))
{
case 0: return GetRValue(color);
case 1: return GetGValue(color);
case 2: return GetBValue(color);
}
return 0;
}
struct PaintScreenData {
HDC hdc;
RECT rAll;
};
BOOL PaintMonitorProc(LSMONITOR Mon,LPARAM psd)
{
RECT rMon;
LSGetMonitorScreenRect(Mon,&rMon);
OffsetRect(&rMon,
-(PaintScreenData *)psd->rAll.left,
-(PaintScreenData *)psd->rAll.top);
// rMon is now the section of psd->hdc that should be drawn here
Rectangle((PaintScreenData *)psd->hdc,
rMon.left,rMon.top,rMon.right,rMon.bottom);
return TRUE;
}
BOOL PaintScreenProc(HDC hdc)
{
PaintScreenData psd;
psd.hdc = hdc;
LSGetMonitorScreenRect(LSMONITOR_ALL,&psd.rAll);
LSForEachMonitor(&PaintMonitorProc,(LPARAM)&psd);
return TRUE;
}
BOOL bShouldUnhookPD;
bShouldUnhookPD = LSSetPaintDesktopHook(&PaintScreenProc);
...
if (bShouldUnhookPD) LSSetPaintDesktopHook(NULL);
Calling LSSetPaintDesktopHook with NULL will remove the hook. You
should never remove the hook unless you successfully set it.