Activate the Disabled button

xiaoxiao2021-03-06  63

Some software If you don't enter the correct registration, the damn "next" button has been disable. This Disable button cannot be obtained using WindowFromPoint, FindWindowex.

However, using EnumChildWindows, getWindow can enumerate all controls in each window, including Disabled control, find the handle, we can operate

Test environment: WinXP VB6

Please refer to MSDN for specific API functions.

New project, add two buttons in Form, two text boxes. Where the button 2 Enabled attribute is False

FORM's CAPTION is set to "Activate the DISABLED button".

After compiling, run.

1. Let's first look at the use of getWindow enumeration

Let's find the FORM window with FindWindow, then find all the sub-control handles in the window, then use the enableWindow function to activate

Add 1 button, 2 List controls.

Option expedition

Private Declare Function FindWindow Lib "User32.dll" Alias ​​"Findwindowa" (Byval LpwindownAme As String) AS LONG

Private Declare Function GetClassName Lib "User32" Alias ​​"getclassnamea" (Byval HWnd As Long, Byval Nmaxcount As long) AS Long

Private Declare Function EnableWindow Lib "User32.dll" (Byval Hwnd As Long) AS Long

Private Declare Function GetWindow Lib "User32" (Byval Hwnd As Long) As long

Const GW_Child = 5

Const GW_HWndNext = 2

Const WM_Gettext = & HD

Const WM_ENABLE As Long = & HA

Private sub fascist2_click ()

DIM TWND AS Long

DIM BWND As Long

DIM LPCLASSNAME AS STRING

DIM RETVAL AS Long

DIM I as integer

DIM MNAME AS STRING

Twnd = FindWindow (VBnullString, "DISABLED of the Activation Program")

BWnd = getWindow (twnd, gw_child)

Do While BWND <> 0

LPClassName = Space (256)

'The name of the name here is mainly to see the control corresponding to the BWnd.

Retval = getClassName (BWnd, LPClassName, 256)

I = INSTR (1, lpclassname, chr (0))

MNAME = Left (LPClassName, I - 1)

List1.additem BWND & "& MNAME

List2 is mainly for convenient operation

List2.additem bwnd

'Continue to find the next control

BWnd = getWindow (bwnd, gw_hwndnext)

Loop

End Sub

'Click the handle you want to activate

Private sub list2_click ()

EnableWindow List2.List (List2.listIndex), TRUE

End Sub

Ok, after running, click the button, all the control handles in the window fill in the list box, then click the list box, you can find that the DISABLED button is activated, you can run it.

2. Enumerate using EnumChildWindows

Function function: an enumeration of the specified parent window

Private Declare Function EnumchildWindows lib "user32" alias "enumchildwindows" (Byval Hwndparent As Long, Byval LPARAM As long) As long

【Parameters Table】

HWndParent ----- Long, the handle of the parent window for the enumeration

LpenumFunc ----- long, a pointer to the function called for each sub-window. Get the address of the addressof operator in a standard module

code show as below:

window

Private Declare Function FindWindow Lib "User32.dll" Alias ​​"Findwindowa" (Byval LpwindownAme As String) AS LONG

Private Declare Function EnableWindow Lib "User32.dll" (Byval Hwnd As Long) AS Long

Private Declare Function EnumChildWindows lib "user32" (Byval lPenumfunc as long, byval lparam as long) As long

Const WM_ENABLE As Long = & HA

Private submmand1_click ()

DIM TWND AS Long

Twnd = FindWindow (VBnullString, "DISABLED of the Activation Program")

EnumchildWindows Twnd, Addressof EnumchildProc, Byval 0 &

End Sub

Private sub list1_click ()

EnableWindow List1.List (List1.ListIndex), TRUE

End Sub

Module

Option expedition

Public Function EnumchildProc (Byval Hwnd As Long, BYVAL LPARAM AS Long) As long

Form1.List1.AddItem HWND

'Continue enumeration

EnumChildProc = 1

END FUNCTION

Ok, after running, click the button, all the control handles in the window fill in the list box, then click the list box, you can find that the DISABLED button is activated, you can run it.

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

New Post(0)