-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_message_box.py
37 lines (30 loc) · 1.12 KB
/
display_message_box.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
"""
Filename: display_message_box.py
Description: Creates a pop-up with the Ok and Cancel buttons. All code in this
file copied from Brandon Dennis' "Hacking Windows API With Python" course on Udemy.
Created by: Benjamin M. Singleton
Created: 03-09-2020
"""
import ctypes
# we need the DLLs for the MessageBox to be able to use it, and kernel32 to catch errors
user_handle = ctypes.WinDLL("User32.dll")
k_handle = ctypes.WinDLL("Kernel32.dll")
# these are the arguments for MessageBoxW
hWnd = None # not specifying a handle for the MessageBox as it's optional
lpText = "Hello World" # text to display in the box
lpCaption = "Hello, students" # title of the box
uType = 0x00000001 # type is message box with OK and Cancel at bottom
# make the actual API call
response = user_handle.MessageBoxW(hWnd, lpText, lpCaption, uType)
# check for errors
error = k_handle.GetLastError()
if error != 0:
print("Error code: {0}".format(error))
exit(1)
# determine which button was clicked
if response == 1:
print("User clicked okay")
elif response == 2:
print("User clicked cancel")
else:
print("User did something else")