用Delphi 写的肯定要比asm的大不少啦。那个13KB 的是用upx压缩过,未压缩的大小为20K.呆会儿贴出源代码。其实很简单,就是全部用 api 来写就可以达到很小的尺寸了。
//源代码program fallWin;uses windows, messages;{$R *.res}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); setLength(windowsInfoList, length(windowsINfoList) + 1); _length := length(windowsInfoList) - 1; windowsInfoList[_length].Handle := _hwnd; windowsInfoList[_length].Rect := rect; windowsInfoList[_length].Caption := String(Caption); windowsInfoList[_length].Speed := random(127) + 1; end;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); //register hotkey gAtom := globalAddAtom('fallWindowsScreen'); registerHotKey(0, gAtom, 0, VK_ESCAPE); // press ESC to exit getWindowsInfo; winCount := length(windowsInfoList); //debugMsg(intToStr(winCount)); setLength(threadIdList, winCount); 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.
本程序一次只能运行一个实例。
下载地址:
http://www.goomoo.net/tmp/happy.exe源代码明天贴出来请各位前辈斧正.
下载地址:
http://www.goomoo.net/tmp/happy.exe源代码明天贴出来请各位前辈斧正.怎么解不了?99
.model flat, stdcall
option casemap:noneincludelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.libinclude \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.code
start:invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, SW_SHOWNORMAL
invoke ExitProcess, NULLWinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL hwnd:DWORD
LOCAL msg:MSG
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wcINVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW-WS_SIZEBOX-WS_MAXIMIZEBOX,CW_USEDEFAULT,\
CW_USEDEFAULT,400,300,NULL,NULL,\
hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endpWndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
mov eax, uMsg
.IF eax==WM_CREATE
invoke MessageBox, NULL, ADDR AppName, ADDR AppName, NULL
.ELSEIF eax==WM_DESTROY
invoke PostQuitMessage, NULL
.ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
.ENDIF
ret
WndProc endp
end start
http://hanlin.hbu.edu.cn/personal/slave/mysoft/ip.exe
只有15.5K其实不用ASM也可以做得很少,用C就可以,大家试过LCC吗??用它写出来的windows程序和用win32ASM写出来的差不多.
windows, messages;{$R *.res}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); setLength(windowsInfoList, length(windowsINfoList) + 1);
_length := length(windowsInfoList) - 1;
windowsInfoList[_length].Handle := _hwnd;
windowsInfoList[_length].Rect := rect;
windowsInfoList[_length].Caption := String(Caption);
windowsInfoList[_length].Speed := random(127) + 1;
end;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); //register hotkey
gAtom := globalAddAtom('fallWindowsScreen');
registerHotKey(0, gAtom, 0, VK_ESCAPE); // press ESC to exit getWindowsInfo; winCount := length(windowsInfoList);
//debugMsg(intToStr(winCount)); setLength(threadIdList, winCount); 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.