程序如下:(因为太长,有所删节)<br>program trapmouse;<br><br>{$R resrce.res}<br><br>uses<br> Messages,<br> SysUtils,<br> Graphics,<br> Windows;<br><br>//Windows API:CreateWinow,RegisterClass,DefWindowProc,..etc<br>// ShareMem;<br><br>{$R *.RES}<br>{$I trap!.inc}<br><br>const<br> AppName='Trap!';<br> Width=320;<br> Height=120;<br> id_BtnOK=100;<br> id_EditUser=200;<br> id_MoveTimer=300;<br> id_MainBitMap=350;<br> MoveInterval=3000; //窗口每三秒钟移动一次;<br> DefaultStayTime=5; //焦点在EDIT控件上时,窗口停留时间为3*5=15秒;<br> AlwaysStay=100000; //窗口总是不动;<br><br>var<br> OldR,R: TRECT;<br> HPos,VPos: Integer;<br> PassedFlag,CheatMode,CanMove,CanRandomMove: BOOL;<br> ResolutionRatioX,ResolutionRatioY:Integer;<br> MainMsg1,MainMsg2,MainMsg3,MainMsg4:String;<br> TimeCounter,StayTime:Integer;<br> HBtn_OK,HEdit_User,HEdit_Pwd:HWnd;<br> MyConfig:ConfigRecord;<br><br>procedure Trap_OnCreate(Window:HWnd;var Msg:TWMCreate);//AMessage,WParam,LParam:Longint);<br>var<br> myHDC:HDC;<br> Dummy:Integer;<br>begin<br> Configure(Window);<br> myHDC:=GetDC(Window);<br> if myHDC=0 then<br> begin<br> MessageBox(0,'资源不足,无法启动程序!',nil,mb_OK);<br> ReleaseDC(Window,myHDC);<br> Exit;<br> end;<br> OldR.left:=0;<br> OldR.right:=GetDeviceCaps(myHDC,HORZRES);//screen.width;<br> OldR.top:=0;<br> OldR.bottom:=GetDeviceCaps(myHDC,VERTRES);//screen.height;<br> ReleaseDC(Window,myHDC);<br> ResolutionRatioX:=OldR.right; //current resolution ratio.<br> ResolutionRatioY:=OldR.bottom;<br> R.left:=HPos;<br> R.right:=HPos+Width;<br> R.top:=VPos;<br> R.bottom:=VPos+Height;<br> ClipCursor(@R);<br> MainMsg1:='Note:This computer has';<br> MainMsg2:='been locked by TRAP!';<br> MainMsg3:='UserName:';<br> MainMsg4:='PassWord:';<br> HBtn_OK:=CreateWindowEx(0,'Button','&OK',<br> ws_Child or ws_Visible or bs_DefPushButton,<br> 250,66,60,24,Window,id_BtnOK,hInstance,nil);<br> HEdit_User:=CreateWindowEx(0,'Edit','UserName',<br> ws_Child or ws_Visible or ws_TabStop or ws_Border or es_Right or es_AutoHScroll,<br> 120,45,100,20,Window,id_EditUser,hInstance,nil);<br> HEdit_Pwd:=CreateWindowEx(0,'Edit','PassWord',<br> ws_Child or ws_Visible or ws_TabStop or ws_Border or es_Right or es_AutoHScroll or es_PassWord,<br> 120,68,100,20,Window,id_EditUser,hInstance,nil);<br>//to disable ALT-TAB and CTRL-DEL-SHIFT<br> Dummy := 0;<br>//Disable ALT-TAB<br> SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @Dummy, 0);<br>//Disable CTRL-ALT-DEL<br> SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);<br> HideTaskBar;<br> Randomize;<br> SetTimer(Window,id_MoveTimer,MoveInterval,nil);<br> BringWindowToTop(Window);<br>end;<br><br>procedure Trap_OnDestroy(Window:HWnd;var Msg:TWMDestroy);<br>begin<br>... <br>end;<br><br>procedure Trap_OnPaint(Window:HWnd;var Msg:TWMPaint);<br>var<br> PaintX,PaintY:Integer;<br> TheFont,OldFont:HFont;<br> PaintDC:HDC;<br> PaintStruct:TPaintStruct;<br> MainBMP,OldBitMap:HBitmap;<br>begin<br> PaintDC:=BeginPaint(Window,PaintStruct);<br> if PaintDC=0 then<br> begin<br> MessageBox(0,'资源不足,无法启动程序!',nil,mb_OK);<br> EndPaint(Window,PaintStruct);<br> Exit;<br> end;<br> SetBKMode(PaintDC,TransParent);<br> TheFont:=GetFont(16,8,fw_Light,0,0,0,0,'Courier New');<br> OldFont:=SelectObject(PaintDC,TheFont); <br> SetTextColor(PaintDC,RGB(0,0,255));<br> TextOut(PaintDC,15,4,PChar(MainMsg1),Length(MainMsg1));<br> TextOut(PaintDC,15,20,PChar(MainMsg2),Length(MainMsg2));<br> SetTextColor(PaintDC,RGB(0,0,0));<br> TextOut(PaintDC,25,47,PChar(MainMsg3),Length(MainMsg3));<br> TextOut(PaintDC,25,70,PChar(MainMsg4),Length(MainMsg4));<br> SelectObject(PaintDC,OldFont);<br> DeleteObject(TheFont);<br> MainBMP:=LoadBitmap(Window,'MainBitMap'); <br> if MainBMP=0 then<br> begin<br> StayTime:=AlwaysStay;<br> MessageBox(0,'位图打开失败!',nil,mb_OK);<br> StayTime:=DefaultStayTime;<br> end;<br> OldBitMap:=SelectObject(PaintDC,MainBMP);<br> PaintX:=220;<br> PaintY:=2;<br> BitBlt(PaintDC,PaintX,PaintY,PaintX+60,PaintY+60,MainBMP,0,0,SrcPaint);<br> SelectObject(PaintDC,OldBitMap);<br> DeleteObject(MainBMP);<br> EndPaint(Window,PaintStruct);<br>end;<br><br>... ...<br><br>function WindowProc(Window:HWnd;AMessage,WParam,LParam:Longint):Longint;stdcall;export;<br>var<br> AMsg:TMessage;<br>begin<br> WindowProc:=0;<br> AMsg.Msg:=AMessage;<br> AMsg.WParam:=WParam;<br> AMsg.LParam:=LParam;<br> AMsg.Result:=0;<br> case AMessage of<br> wm_Create:<br> begin<br> Trap_OnCreate(Window,TWMCreate(AMsg));<br> WindowProc:=DefWindowProc(Window,AMessage,WParam,LParam);<br> end;<br><br> wm_Paint: Trap_OnPaint(Window,TWMPaint(AMsg));<br><br> wm_KeyDown: Trap_OnKeyDown(Window,TWMKeyDown(AMsg));<br><br> wm_KeyUp: Trap_OnKeyUp(Window,TWMKeyUp(AMsg));<br><br> wm_Move: Trap_OnMove(Window,TWMMove(AMsg));<br><br> wm_Timer: Trap_OnTimer(Window,TWMTimer(AMsg));<br><br> wm_NCLButtonDblClk: Trap_OnNCLButtonDblClk(Window,TWMNCLButtonDblClk(AMsg));<br><br> wm_Command: Trap_OnCommand(Window,TWMCommand(AMsg));<br><br> wm_Destroy: Trap_OnDestroy(Window,TWMDestroy(AMsg));<br><br> else WindowProc:=DefWindowProc(Window,AMessage,WParam,LParam);<br> end;<br>end;<br><br>function WinRegister:Boolean;<br>var<br> WindowClass:TWndClass;<br>begin<br> WindowClass.Style:=cs_NoClose;<br> WindowClass.lpfnWndProc:=@WindowProc;<br> WindowClass.cbClsExtra:=0;<br> WindowClass.cbWndExtra:=0;<br> WindowClass.hInstance:=HInstance;<br> WindowClass.hIcon:=LoadIcon(0,idi_Application);<br> WindowClass.hCursor:=LoadCursor(0,IDC_ARROW);<br> WindowClass.hbrBackground:=HBrush(color_Window);<br> WindowClass.lpszMenuName:=nil;<br> WindowClass.lpszClassName:=Appname;<br><br> Result:=RegisterClass(WindowClass)<>0;<br>end;<br><br>function WinCreate:hWnd;<br>var<br> hWindow:hWnd;<br> WinStyle : int64;<br>begin<br> WinStyle:=WS_DLGFRAME or DS_SETFOREGROUND;<br> hWindow:=CreateWindow(AppName,'Trap! ver 0.1',<br> WinStyle,HPos,VPos,Width,Height,0,0,hInstance,nil);<br> if HWindow<>0 then<br> begin<br> ShowWindow(hWindow,CmdShow);<br> UpdateWindow(hWindow);<br> end;<br> Result:=hWindow;<br>end;<br><br>var<br> AMessage:TMsg;<br> hWindow:hWnd;<br>begin<br> PassedFlag:=False;<br> CheatMode:=False;<br> CanMove:=True;<br> CanRandomMove:=True;<br> HPos:=240;<br> VPos:=240;<br> TimeCounter:=0;<br> StayTime:=5;<br> if not WinRegister then<br> begin<br> MessageBox(0,'窗口注册失败!',nil,mb_OK);<br> Exit;<br> end;<br> hWindow:=WinCreate;<br> if hWindow=0 then<br> begin<br> MessageBox(0,'窗口启动失败!',nil,mb_OK);<br> Exit;<br> end;<br><br> while GetMessage(AMessage,0,0,0) do<br> begin<br> TranslateMessage(AMessage);<br> DispatchMessage(AMessage);<br> end;<br> Halt(AMessage.wParam);<br>end.<br><br>