我有3个QQ,每天都要登录,可是登录后,"腾讯网迷你首页"就会自动弹出,干扰了我的心情(呵呵~~只有会员才免遭此罪哦).于是,我编写了个程序:在10分钟内主动查找"腾讯网迷你首页",发现就把它关掉,不给它弹出的机会!于是,世界开始宁静了... ...10分钟后,这个小程序又自动退出了.
以下是代码(已测试),希望大家批评指正:
;用定时器定时查找QQ迷你窗口,找到后就关闭它;
;如果10分钟内没有找到,则自动退出.
;作者:ONEPROBLEM
;===========================================
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
ID_TIMER equ 1
ICO_MAIN equ 1
DLG_MAIN equ 1
IDC_COUNT equ 100
.data?
hInstance dd ?
hWinMain dd ?
idTimer dd ?
.const
szCaption db '腾讯网迷你首页',0
;========================================================
.code
_ProcTimer proc _hWnd,uMsg,_idEvent,_dwTime ;定时器过程
pushad
invoke GetDlgItemInt,hWinMain,IDC_COUNT,NULL,FALSE
《GetDlgItemInt函数功能说明如下:
Translates the text of a specified control in a dialog box into an integer value.
Remarks
The GetDlgItemInt function retrieves the text of the specified control by sending the control aWM_GETTEXT message. The function translates the retrieved text by stripping any extra spaces at the beginning of the text and then converting the decimal digits. The function stops translating when it reaches the end of the text or encounters a nonnumeric character.
The GetDlgItemInt function returns zero if the translated value is greater than INT_MAX (for signed numbers) or UINT_MAX (for unsigned numbers).
》
sub eax,1
.if eax == 0 ;倒计时为0,则程序退出
invoke SendMessage,hWinMain,WM_CLOSE,0,0
《SendMessage函数功能说明如下:
Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use thePostMessage orPostThreadMessage function.
Remarks
When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).
Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >=WM_USER) to another process, you must do custom marshalling.
If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. For more information on nonqueued messages, seeNonqueued Messages.
》
.endif
invoke SetDlgItemInt,hWinMain,IDC_COUNT,eax,FALSE
《 SetDlgItemInt函数功能说明如下:
Sets the text of a control in a dialog box to the string representation of a specified integer value.
Remarks
To set the new text, this function sends a WM_SETTEXT message to the specified control
》
popad
ret
_ProcTimer endp
;====================================================================
_ProcDlgMain proc uses ebx edi esi,hWnd,uMsg,wParam,IParam
mov eax,uMsg
.if eax == WM_TIMER
mov eax,wParam
.if eax == ID_TIMER
invoke FindWindow,NULL,addr szCaption ;查找QQ首页
《
FindWIndow函数功能说明如下:
Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
To search child windows, beginning with a specified child window, use the FindWindowEx function.
Remarks
If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks for GetWindowText.
》
.if eax
mov hWnd,eax
invoke SendMessage,hWnd,WM_CLOSE,0,0
.endif
.endif
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke LoadIcon,hInstance,ICO_MAIN
《
LoadIcon函数功能说明如下:
Loads the specified icon resource from the executable (.exe) file associated with an application instance.
Note This function has been superseded by the LoadImage function.
Remarks
LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing resource. The function searches the icon resource for the icon most appropriate for the current display. The icon resource can be a color or monochrome bitmap.
LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes.
》
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke SetTimer,hWnd,ID_TIMER,3000,NULL ;每3秒钟就查找一次
《
SetTimer函数功能说明如下:
Creates a timer with the specified time-out value.
Remarks
An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.
The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter.
The timer identifier, nIDEvent, is specific to the associated window. Another window can have its own timer which has the same identifier as a timer owned by another window. The timers are distinct.
SetTimer can reuse timer IDs in the case where hWnd is NULL.
》
invoke SetTimer,NULL,NULL,1000,addr _ProcTimer
mov idTimer,eax
.elseif eax == WM_CLOSE
invoke KillTimer,hWnd,ID_TIMER
《
KillTimer函数说明如下:
Destroys the specified timer.
Remarks
The KillTimer function does not remove WM_TIMER messages already posted to the message queue.
》
invoke KillTimer,NULL,idTimer
invoke EndDialog,hWnd,NULL
《
EndDialog函数说明如下:
Destroys a modal dialog box, causing the system to end any processing for the dialog box.
Remarks
Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose.
A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.
EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.
》
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;=============================================================
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start
;===================================================================================
;===================================================================================
;以下是.RC文件:
#include <resource.h>
#define DLG_MAIN 1 //对话框
#define ICO_MAIN 1
#define IDC_COUNT 100
ICO_MAIN ICON "1.ico"
DLG_MAIN DIALOG 50,50,120,60
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "守候者 SH1.0"
FONT 14,"宋体"
{
LTEXT "说明:1、这个小工具可以帮你\n关掉烦人的腾讯网迷你首页;",-1,8,5,100,22
LTEXT "2、程序将在10分钟后自动关闭。",-1,8,22,100,22
LTEXT "倒计时:",-1,30,43,35,10
LTEXT "600",IDC_COUNT,60,43,15,10
LTEXT "秒",-1,75,43,10,10
}