C ++ Builder master advanced (1) Write a pop-up advertising killer

zhaozj2021-02-16  25

C builder master advanced

(1) Write a pop-up advertising killer

nxyc_twz@163.com

First, system analysis

As a software developer, it will inevitably look for information frequently, and annoying advertising is really troubled. Is there a way to automatically close these ads? The answer is yes! Maybe you will say: "There are many software online software. Just find one, don't you do it?" You said it is really good, you can use a software developer, you can't rely on others? " How do you do your own? If you don't have to dry, you must first find out the working principle of the pop-up advertising window:

1. Using your own "System Window Analyzer" (in the next phase of the development process), it is easy to find the feature of the pop-up advertising window: The window class is CabinetWClass or IEframe.

2. If you find the window class is the window of CabinetWClass or ieframe, isn't it OK to send WM_CLOSE? I can't help but happiness in my heart!

3. Use the timer timing to detect, find the WM_CLOSE message to find the eligible window.

Second, the frontier of actual combat

How do you find the window class name? This needs to use the API function:

GetWindowText: Get window text

GetWindow: get the window handle

GetClassName: Get class name

PostMessage: Send a message

SetWindowlong: Setting mode

Please consult the relevant information for specific usage.

Third, design process

1. Start C Builder 5, create a new Application, set the Form's Name to Form1, which is set to BSNOne, set the icon in the ICON of the Form.

2. Define data variables:

TRAYICON_ID = 1;

IconEvent = WM_APP 100;

TNotifyicondata Traylon;

3. Drag and drop a Timer control and a popMENU control to the form. Timer's properties: name-> Timer1, Interval-> 1000; Add three children on popmenu1: Continue -> ContinueCmd, Pausecmd-> Pause, exitcmd-> Exit.

4. Enter the application into the system tray: void trayiconcmd (void);

Trayicon.cbsize = sizeof (tnotifyicondata);

TRAYICON.HWND = HANDLE;

TRAYICON.UID = ID_TRYICON;

TRAYICON.UFLAGS = NIF_ICON | NIF_MESSAGE | NIF_TIP;

Trayicon.ucallbackMessage = iconEvent;

TRAYICON.HICON = FORM1-> icon-> Handle;

Trayicon.sztip = "Advertising Window Killer";

Shell_Notifyicon (NM_ADD, & TRAYICON);

5. Make the application exit the system tray: void trayiconexit (void);

Shell_Notifyicon (Nim_Delete, & Trayicon); 6. Enter the application directly to the system tray directly: Write the oncreate event of Form1

TRAYICONCMD (); // Install icon in the system tray

Width = 0;

SetWindowlong (Application-> Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

7. Uninstall the icon from the system tray: Write the onClose event of Form1

Trayiconexit ();

8. Custom message TRAYICONONCLICK:

Definition in the header file. H:

Private:

Message void __fastcall trayiconclick (tMessage & Message);

Begin_MESSAGE_MAP

Message_handler (iconEvent, TMessage, Trayiconnclick);

END_MESSAGE_MAP (TFORM)

9. The mouse click on the system tray icon, then pops up the menu:

TPOINT P;

IF (message.lparam == wm_lbuttondown ||

Message.lpram == WM_RBUTTONDOWN)

{

PopupMenu1-> popupComponent = Form1;

SetForegroundWindow (Handle);

GetCursorpos (P);

Popupmenu-> Popup (p.x, p.y);

}

10. Enumerate all sub-windows of the specified window handle: Void MenumChildWindows (HWND HAND);

CHAR TEMPSTR [255];

Bool ispopwindow = true;

HWnd h = getWindow (Hand, GW_CHILD);

While (h)

{

GetClassName (H, Tempstr, 256);

IF (! strcmp (tempstr, "workera") ||! strcmp (Tempstr, "Workerw"))))))

IF (iswindowvisible (h)) ispopwindow = false;

H = getWindow (h, gw_hwndnext);

}

IF (ISPOPWindw) PostMessage (Hand, WM_Close, 0, 0);

11. Double-click the Timer control and add its event ontimer:

CHAR TEXT [255];

HWND H: = getWindow (Handle, GW_HWndFirst);

While (h)

{

IF (GetWindowText (H, Text, 255)> 0)

IF (GetClassName (H, Text, 255)> 0)

IF (! strcmp (text, "cabinetwclass") ||! strcmp (text, "iframe")))

EnumchildWindows (h);

H = getWindow (h, gw_hwndnext);

}

12. Write a menu response event:

Continuecmd: Continue

Timer1-> enabled = true;

Pausecmd-> checked = false;

Continuecmd-> checked = true;

Pausecmd: Pause

Timer1-> enabled = false;

Pausecmd-> checked = true;

Continuecmd-> checked = false;

EXITCMD :: Exit

CLOSE ();

转载请注明原文地址:https://www.9cbs.com/read-26454.html

New Post(0)