type
TWindowInfo = record
Handle: THandle;
Caption: String;
Rect: TRect;
Speed: Byte;
end;
const
gDebug = False;
var
windowsInfoList: array of TWindowInfo;
gAtom: ATOM;
winCount, aInt, gScreenHeight, gScreenWidth, gIndex: Integer;
msg: tagMsg;
threadIdList: array of DWORD;
//speedFactor:UINT;
procedure debugMsg(s: String);
begin
if gDebug then
messageBox(0, PChar(s), 'Debug Message', 0);
end;
function enumWindowsProc(_hwnd: HWND; _lparam: LPARAM): BOOL; stdcall;
var
Caption: array[0..511] of Char;
rect: TRect;
_length: Integer;
begin
Result := True;
if _hwnd = HWND_DESKTOP then
exit;
if not isWindowVisible(_hwnd) then
exit;
getWindowText(_hwnd, Caption, 512);
if (String(Caption) = '') or (String(Caption) = 'Program Manager') then
exit;
//debugMsg(string(caption));
getWindowRect(_hwnd, rect);
if ((rect.Bottom - rect.Top) = gScreenHeight) then
exit;
if isIconic(_hwnd) then
exit; //showWindow(_hwnd,SW_RESTORE);
procedure restoreWindows;
var
i: Integer;
_hwnd: HWND;
x, y: Integer;
begin
for i := 0 to winCount - 1 do
begin
_hwnd := windowsInfoList[i].Handle;
x := windowsInfoList[i].Rect.Left;
y := windowsInfoList[i].Rect.Top;
setWindowPos(_hwnd, 0, x, y, 0, 0, SWP_NOZORDER or SWP_NOSIZE);
end;
end;
procedure getWindowsInfo;
begin
enumWindows(@enumWindowsProc, 0);
end;
function threadProc(lpdData: LPDWORD): DWORD; stdcall;
var
x, y, sn: Integer;
rect: TRect;
begin
inc(gIndex);
sn := gIndex;
//debugMsg(intToStr(gIndex));
while (True) do
begin
getWindowRect(windowsInfoList[sn].Handle, rect);
x := Rect.Left;
y := Rect.Top;
y := y + windowsInfoList[sn].Speed;
if y > gScreenheight then
begin
y := -gScreenHeight;
x := random(gScreenWidth);
end;
setWindowPos(windowsInfoList[sn].Handle, 0, x, y, 0, 0,
SWP_NOSIZE or SWP_NOZORDER);
sleep(32);
end;
Result := 1;
end;
//////////////////////////////////////////////////////////////////////////////
// start from here ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
begin
gAtom := globalFindAtom('fallWindowsScreen');
if gAtom <> 0 then // program have a previous instance
begin
//globalDeleteAtom(gAtom);
exit;
end;
// get screen's height
gScreenWidth := getSystemMetrics(SM_CXFULLSCREEN);
gScreenHeight := getSystemMetrics(SM_CYFULLSCREEN);
for aInt := 0 to winCount - 1 do
begin
//create threads for every window
createThread(nil, 0, @threadProc, nil, 0, threadIdList[aInt]);
//setTimer(0,0,160,@timerProc);
end;
// message loop
while (getMessage(msg, 0, 0, 0)) do
begin
if msg.message = WM_HOTKEY then
begin
globalDeleteAtom(gAtom);
restoreWindows;
//MessageBox(0,'Please visit http://www.goomoo.net to get more goodies! ;-)','Information',0);
exit;
end
else
begin
translateMessage(msg);
dispatchMessage(msg);
end;
end;
end.
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
WinMain PROTO STDCALL :DWORD, :DWORD, :DWORD, :DWORD
WndProc PROTO STDCALL :DWORD, :DWORD, :DWORD, :DWORD
.data?
hInstance dd ?
.data
ClassName db "FirstWindowClass",0
AppName db "FirstWindow",0