| |

VerySource

 Forgot password?
 Register
Search
View: 2322|Reply: 4

I want to be a program that closes the web page. . Trouble up

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-4-25 15:30:02
| Show all posts |Read mode
DWORD FINDPROCESS (Char * Appname)
{
    Handle hsnapshot;
    DWORD ID = 0;
Processentry32 PE32 = {SIZEOF (Processentry32)};

HSnapshot = CreateToolHelp32Snapshot (TH32CS_SNAPPROCESS, 0);

IF (hsnapshot == invalid_handle_value)
    {
Return 0;
    }

    For (Bool Bok = Process32First (HSnapshot, 0uO0PE32); Bok; Bok = Process32Next (HSnapshot, 0uO0PE32))
    {
        IF (strcmpi (pe32.szexefile, appname) == 0)
        {
            ID = pe32.th32processid;
            Break;
        }
    }

    CloseHandle (HSnapshot);
    Return ID;
}
Void __fastcall tform1 :: Timer1Timer (TOBJECT * SENDER)
{

   
    HWnd = FindWindow (NULL, "Good 123 URL House - Practical URL, search Daquan, all in www_hao123_com - microsoft Internet explorer");
    SendMessage (hwnd, wm_close, 0, 0);
    Handle H = OpenProcess (Process_Terminate, NULL, ID);
    TERMINATEPROCESS ((Handle) H, 0);
    CloseHandle (H);

}


You can't close the web pages you want to turn after running. . Isn't it?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-4-25 17:45:01
| Show all posts
Yes no.
The above function is to find a process.
For example, those processes in the task manager.
HWND = FindWindow (Null, "Explorer.exe");
This is close to IE.
I don't know if I don't know how to close the webpage.
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-4-25 18:00:01
| Show all posts
Void __fastcall tform1 :: Timer1Timer (TOBJECT * SENDER)
{

      
        HWnd = FindWindow (NULL, "Good 123 URL House - Practical URL, search Daquan, all in www_hao123_com - microsoft Internet explorer");
        SendMessage (hwnd, wm_close, 0, 0);
        Handle H = OpenProcess (Process_Terminate, NULL, ID);
        TERMINATEPROCESS ((Handle) H, 0);
        CloseHandle (H);

}
---------------------
This can be.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-4-25 18:15:01
| Show all posts
// Enumerate the current process so you can get the process ID you want to close, then Kill can drop
INT __fastcall watchmointor (char ppexename [], int kill)
{
    Bool continueloop;
    Handle fsnapshothandle;
    TPROCESSENTRY32 FPROCESSENTRY32;
    Char TMPEXENAME [MAX_WATCHEXE_NUM];
    Handle Phand;

    INT impound = -1;

    Fsnapshothandle = CreateToolHelp32Snapshot (TH32CS_SNAPPROCESS, 0);
    FPROCESSSENTRY32.DWSIZE = SIZEOF (fProcesSsentry32);
    Continueloop = Process32First (fsnapshothandle,&fprocessentry32);

    // Get the list of processes
    While (Continuelo)
    {
        MEMSET (TMPEXENAME, 0, SIZEOF (TMPEXENAME));
        Strpcopy (TMPEXENAME, FPROCESSENTRY32.SZEXEFILE);
        IF (stricmp (ppexename, tmpexename) == 0)
        {
            IF (kill == 1)
            {
               PHAND = OpenProcess (1, False, FProcesSsentry32.th32processid);
               IF (PHAND! = NULL)
                  TERMINATEPROCESS (PHAND, -1);

               iFound = 0;
               Break;
            }
        }
        Continueloop = process32next (fsnapshothandle,&fprocessentry32);
    }
   
    CloseHandle (fsnapshothandle);
    Return.
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2021-4-25 18:30:01
| Show all posts
See what you want.
If it is IE, use the above,
If it is other IE kernel, it needs to be a modified method.
But there is a premise, you have to get the HWnd of that window, otherwise, don't say anything.
If you have already got hwnd, what is going on.
For example, after getting the HWnd of the form under the mouse, it is judged whether it is an HWnd of the IE kernel.
If so, proceed.

Below is a part of the code I am using in the Data Collection Library, you can see it.

[code = c / c ++]]

BOOL __FASTCALL TFORM :: FindHTMLParent (HWND HWND)
{
    // Todo: Find a look at the HTML's father form is not docbook or the resource manager.
    // Returns True. Otherwise, false
    HWND HWNDPARENT = NULL;
    / / Find the parent window handle of Internet Explorer_Server
    HWndParent = getParent (hwnd);
    IF ((hwndparent! = hwnd)&&hwndparent! = null)
    {
        Char bufclassname [255], bufclasscaption [255];
        GetClassName (HWndParent, BufcoSsName, 255);

        IF (("" "" "SHELLDLL_DEFVIEW"> 0) // Explorer.
          || (BUFCLASSNAME) .POS ("Internet Explorer_tridentdlgFrame")> 0) // IE dialog
            Return True;
        ansistring (bufclassname) .POS ("shell docobject view"> 0)
        {
            // If it is an IE or other browser, it is necessary to determine if Docbook's browser.
            Int textLength;
            HWnd hmainwndparent = getParent (hwndparent);
            GetClassName (HmainWndParent, BufclassName, 255);
            IF (bufclassname) .pos ("shell embedding")> 0)
            {
                HWnd hpmainwndparent = getParent (hmainwndparent);
                GetClassName (HPMainWndParent, BufclassName, 255);
                TextLength = SendMessage (HPMainWndParent, WM_GettextLength, 0, 0);
                IF (TextLength> 256) TextLength = 255;
                IF (TextLength> 0)
                {
                  SendMessage (HPMainWndParent, WM_Gettext, TextLength + 1, (LPARAM) 0uO0BufClassCAption [0]);
                  IF (BUFCLASSCAPTION) .POS ("DOCBOOK")) Return True;
                }
            } // end of shell embedding
        } // end of shell docObject view
    } // end of null.
    Return False;
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform :: ONGETDOCINTERFACE (HWND HWND)
{
    // Todo: A corresponding web_ie_doc
    FindHTMLParent (HWND)) Return;

Coinitialize (NULL);
// oleinitialize (null);
    // TODO: A content obtained by obtaining the obtained IE.
// Explicitly Load MSAA SO We know if it's installed
    Wchar_t * sztitle = l "", * szurl = L "";
    IHTMLDocument2 * WebDoc = NULL;
Hinstance hinst = :: loadLibrary (_t ("oleacc.dll"));
IF (hinst! = null)
{
IF (hwnd! = null)
{
// ccomptr <htmldocument2> spdoc;
System :: delphiinterface <htmldocument2> spdoc;
LRESULT LRES;

UINT NMSG = :: RegisterWindowMessage (_t ("wm_html_getobject")))
:: SendMessagetimeout (HWND, NMSG, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD *) 0u0lres;

LPFNObjectFromlResult PfObjectfromlresult = (lpfnobjectfromlresult) :: getProcaddress (Hinst, _t ("ObjectFromlResult");
IF (pfObjectfromlresult! = null)
{
HRESULT HR;
HR = (* pfObjectfromlResult) (Lres, IID_IHTMLDocument, 0, (void **) 0uO0Spdoc);
En (ac))
{
System :: DelphiInterface <iDispatch> SPDISP;
System :: DelphiInterface <htmlwindow2> spwin;
// ccomptr <iDispatch> spdisp;
// ccomqiptr <htmlwindow2> spwin;
                        SPDOC-> Get_Script (0uO0SPDISP);
SPWIN = SPDISP;
// spwin-> get_document (0uO0spdoc.p);
                        // WebDoc = (lpdispatch) SPDOC;
                        Spwin-> get_document (0uO0Webdoc);
                        // spdoc-> get_title (0uO0sztitle);
                        // SPDOC-> GET_URL (0uO0Szurl);
                        Webdoc-> get_title (0uO0sztitle);
                        WebDoc-> get_url (0uO0Szurl);

}
                } // end of if (pfObjectFromlResult! = null)
} // if (hwnd! = null)
:: Freelibrary (HINST);
} // Else Active Accessibility Is Not Installed


    IF (ANSISTRING (SZURL) == "" ")
    {
        Return;
    }
    Couninitialize ();

}
/ / -------------------------------------------------------------------------------------------- ---------------------------

// Turn off the code.
HDESTHWND is to close
// Turn off the specified window.
Char bufclassname [256];
MEMSET (BUFCLASSNAME, 0X00, SIZEOF (BUFCLASSNAME);
GetClassName (HDesthWnd, BufcoSsName, 255);
IF (strcmp (bufclassname, "hh child")! = 0) // hh child is not closed.
{
// Maxthon has a problem, and it doesn't work directly to PostMessage.
// Only the complete path of EXE is obtained by the form handle.

// First obtain the handle of the main form of the program
HWnd MaxthonRoothWnd = GetanceStor (HDESTHWND, GA_ROOT);
DWORD LPDWPROCESSID;
Handle ExeHandle;
HModule HMODS = NULL;

// A re-acquisition of the program's EXE path
GetWindowThreadProcessId (MaxthonRoothWnd, 0uO0Lpdwprocess);
ExeHandle = OpenProcess (Process_Query_information | Process_vm_Read,
True, LPDWPROCESSID;
IF (exehandle)
{
MEMSET (BUFCLASSNAME, 0X00, SIZEOF (BUFCLASSNAME);
GetModuleFileNameEx (ExeHandle, HMODS, BUFCLASSNAME, SIZEOF (BUFCLASSNAME);

IF (BUFCLASSNAME) .uppercase (). POS ("Maxthon.exe")))
{
// HDesthwnd is not a real window, it should be striking.
HDESTHWND = getParent (HDESTHWND);
}
} // end of if (exehandle)

Postmessage (HDesthWnd, WM_Close, Null, NULL);
} // end of if (bufflassname, "hh child")
[/ code]
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list