-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser32__DATETIMEPICK_CLASS.py
95 lines (81 loc) · 3.67 KB
/
User32__DATETIMEPICK_CLASS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import win32gui
import win32con
import win32api
import commctrl
import struct
import math
from ctypes import windll, wintypes, Structure, c_ushort, sizeof, create_unicode_buffer
# the code that process data from SendMessage is generated by AI and edit by me
# fix win32timezone.SYSTEMTIME https://stackoverflow.com/questions/51566069/python-ctypes-sizeof-always-returns-0
class SYSTEMTIME(Structure):
_fields_ = [
('wYear', c_ushort),
('wMonth', c_ushort),
('wDayOfWeek', c_ushort),
('wDay', c_ushort),
('wHour', c_ushort),
('wMinute', c_ushort),
('wSecond', c_ushort),
('wMilliseconds', c_ushort),
]
# Define the GetDeviceCaps function signature
GetDeviceCaps = windll.gdi32.GetDeviceCaps
GetDeviceCaps.argtypes = [wintypes.HDC, wintypes.INT]
GetDeviceCaps.restype = wintypes.INT
dp_hwnd = int() # Store the combobox handle
def WndProc(hwnd, msg, wParam, lParam):
global dp_hwnd
if msg == win32con.WM_COMMAND and wParam == 102: # Assuming 102 is the ID of the submit button
# Get selected item from the combobox
st = SYSTEMTIME()
buf = create_unicode_buffer(sizeof(st))
# Send DTM_GETSYSTEMTIME message to get the system time
system_time = win32gui.SendMessage(dp_hwnd, commctrl.DTM_GETSYSTEMTIME, 0, buf)
bytes_data = bytes(buf)[:16]
unpacked_data = struct.unpack('<HHHHHHHH', bytes_data) # '<' for little-endian, 8 H (unsigned shorts)
st.wYear = unpacked_data[0]
st.wMonth = unpacked_data[1]
st.wDayOfWeek = unpacked_data[2]
st.wDay = unpacked_data[3]
st.wHour = unpacked_data[4]
st.wMinute = unpacked_data[5]
st.wSecond = unpacked_data[6]
st.wMilliseconds = unpacked_data[7]
date_str = f"{st.wYear}-{st.wMonth}-{st.wDay}"
print(date_str)
elif msg == win32con.WM_DESTROY:
win32gui.PostQuitMessage(0)
return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
def main():
dpiX = 0
dpiY = 0
hdc = win32gui.GetDC(0) # 0 represents the entire screen
if hdc:
dpiX = GetDeviceCaps(hdc, win32con.LOGPIXELSX)
dpiY = GetDeviceCaps(hdc, win32con.LOGPIXELSY)
win32gui.ReleaseDC(0, hdc)
width = int(math.ceil(640.0 * dpiX / 96.0))
height = int(math.ceil(480.0 * dpiY / 96.0))
wc = win32gui.WNDCLASS()
wc.lpszClassName = "MyWindowClass"
wc.lpfnWndProc = WndProc
class_atom = win32gui.RegisterClass(wc)
hwnd = win32gui.CreateWindow(class_atom, "My Window", win32con.WS_OVERLAPPEDWINDOW,
win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, width, height, 0, 0, 0, None)
# Example combobox creation (adjust xpos, ypos, nwidth, nheight, hwndParent)
xpos, ypos = 10, 10 # Example position
nwidth, nheight = 200, 20 # Example size
hwndParent = hwnd # Set parent to the main window
# Create a listbox control
global dp_hwnd
dp_hwnd = win32gui.CreateWindow(commctrl.DATETIMEPICK_CLASS, "",
win32con.WS_BORDER | win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPED | commctrl.DTS_SHOWNONE, # Style
xpos, ypos, nwidth, nheight, hwndParent, 101, 0, None)
# Create a button
button_hwnd = win32gui.CreateWindow("BUTTON", "Submit", win32con.WS_VISIBLE | win32con.WS_CHILD,
20, 120, 80, 25, hwnd, 102, 0, None)
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
win32gui.UpdateWindow(hwnd)
win32gui.PumpMessages()
if __name__ == "__main__":
main()