These days, in the use of a software trial version of the process, often pop-up ads, really not very annoying, how to write a small program to remove him? Please come with me!
The idea is this: first you need to know to eliminate the title of the form (such as Mywindow), and then get the handle to the form, to determine whether its title is the same as the title of the form that needs to be eliminated, and if so, turn it off. The reason is simple, implementation is not difficult, look at the following code:
CPoint MP;
char str[256];
HWND hWnd;
GetCursorPos(&MP);
hWnd = ::WindowFromPoint(MP);
::SendMessage(hWnd, WM_GETTEXT, 255, (long)str);
if((strcmp(str, "MyWindow") == 0))
::PostMessage(hWnd, WM_CLOSE, 0, 0);
This is what I copied from a downloaded code. Analyze: First get the coordinates of the current cursor, then get the handle of the form that the cursor points to, get the title of the form through this handle, and close the form if the caption equals Mywindow.
This code basically reached our request, but still feel cumbersome, because it requires us to point to the need to close the cursor to the form, and the fact that we want to do is to let this form automatically closed, in fact, it is not difficult to take all the forms on the desktop to traverse the line! There is an API that can achieve the purpose, EnumWindows:
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);
It requires a callback function as a parameter, and the running process is like this: EnumWindows traverses the form on the desktop, gets the handle to the form, passes the handle to the callback function Lpenumfunc, The enumwindows end condition is that the last desktop form is found or the return value of the callback function is false. This callback function requires the following definition:
BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam // application-defined value
);
An HWND is a form handle that is passed in by EnumWindows, and with this handle you can decide whether to turn it off by judging the handle of the form as above:
char str[256];
::SendMessage(hwnd, WM_GETTEXT, 255, (long)str);
if((strcmp(str, "MyWindow") == 0))
::PostMessage(hWnd, WM_CLOSE, 0, 0);
The example code creates a project based on dialog, which enables the recognition and closure of pop-up ads for a certain period of time, for reference only!
For questions about articles and code, please contact the author:
Mailing Address: No. 6th, West Democratic Street, Changchun, Jilin Province, Earth Exploration Science and Technology College level 2001 Master's degree
Post code: 130026
E-mail: forevergis@sina.com
Author Homepage: http://forevergis.6to23.com
This article supporting source code