You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The program can run to print('Finished enumerating child windows') location。
xxxxxxxxxxxxxxxxxxxxxxxxx
Finished enumerating child windows
x: [8392952]
Actual behavior
Using SECTION 1, The program did not run to x and exited directly.
Steps to reproduce the problem
Run the 3D-tool program and open any 3D model file.
Click the Model Info button to open a panel
Running the following script, the code in Section1 cannot correctly obtain the Combox hwnd for Not assigned, and the program exits. But using code of Section2 can work normally
importwin32guiimportwin32apiimportctypes# Define the required message constantsCB_GETCURSEL=0x0147CB_GETLBTEXT=0x0148CB_GETLBTEXTLEN=0x0149defget_combo_box_selected_value(hwnd):
# Get the currently selected indexindex=win32api.SendMessage(hwnd, CB_GETCURSEL, 0, 0)
ifindex==-1:
print("No item selected.")
returnNone# Get the length of the selected item's texttext_length=win32api.SendMessage(hwnd, CB_GETLBTEXTLEN, index, 0)
iftext_length==-1:
print("Failed to get text length.")
returnNone# SECTION 1: Using PyGetMemory, PyGetBufferAddressAndLen, and PyGetString# Create a buffer to store the textlength=text_length+1buf=b'\0'*lengthwin32gui.PyGetMemory(id(buf), length)
win32api.SendMessage(hwnd, CB_GETLBTEXT, index, buf)
addr, length=win32gui.PyGetBufferAddressAndLen(buf)
text=win32gui.PyGetString(addr, length-1)
# SECTION 2: Using ctypes# Create a buffer to store the text# buffer = ctypes.create_unicode_buffer(text_length + 1)# win32api.SendMessage(hwnd, CB_GETLBTEXT, index, buffer)# text = buffer.valuereturntextdefenum_child_windows_callback(hwnd, x):
# Get the class name and title of the child windowclass_name=win32gui.GetClassName(hwnd)
ifclass_name=='TComboBox':
window_text=get_combo_box_selected_value(hwnd)
print(f"ComboBox text: {window_text}")
else:
window_text=win32gui.GetWindowText(hwnd)
print(f"Window text: {window_text}")
ifclass_name=='TComboBox'andwindow_text=='Not assigned':
print('xxxxxxxxxxxxxxxxxxxxxxxxx')
x.append(hwnd)
returnFalsereturnTrue# Continue enumerating child windowsdefenum_all_child_windows(parent_hwnd, x):
win32gui.EnumChildWindows(parent_hwnd, enum_child_windows_callback, x)
if__name__=="__main__":
calculator_hwnd=win32gui.FindWindow(None, "3D-Tool")
ifcalculator_hwnd:
print(f"Found main window: Handle={hex(calculator_hwnd)}")
x= []
enum_all_child_windows(calculator_hwnd, x)
print('Finished enumerating child windows')
print('x:', x)
else:
print("Could not find the specified window.")
System information
Python version and distribution:
miniconda Python 3.12.8 x64 for window 11 pro, 24H2
pywin32 version:
pywin32 308
The text was updated successfully, but these errors were encountered:
Expected behavior and actual behavior
Expected behavior
Using SECTION 2, the program is normal.
The program can run to
print('Finished enumerating child windows')
location。Actual behavior
Using SECTION 1, The program did not run to x and exited directly.
Steps to reproduce the problem
System information
Python version and distribution:
miniconda Python 3.12.8 x64 for window 11 pro, 24H2
pywin32 version:
pywin32 308
The text was updated successfully, but these errors were encountered: