How do I find the current Word Pad application with Python and win32gui fonts? I was able to find Windows Handler and the child windows A sample application is below
import win32gui,win32api,win32con,win32ui
hwnd = win32gui.GetDesktopWindow()
dc = win32gui.GetWindowDC(hwnd)
hfont = win32gui.SendMessage(dc, win32con.WM_GETFONT, 0,0)
fnt_spc = {}
fnt_n = win32ui.CreateFont(fnt_spc)
lf = win32gui.SelectObject(hfont,fnt_n.GetSafeHandle())
print(lf.lfFaceName)
As you can see in the Spy++, the control in WordPad is Rich Edit:
According to the Unsupported Edit Control Functionality:
EM_GETCHARFORMATshould be used instead ofWM_GETFONT.First, you need to get the Rich Edit handle(with Spy++ directly,or
WindowFromPoint,FindWindowEx,EnumChildWindowsand etc. ButGetDesktopWindowyou used will just return a handle to the desktop window, andSendMessagereceive a window handle but not a device context handle)In addition, you still need to note that when sending
EM_GETCHARFORMATmessage in another process, you need to request a piece of memory for reading and writing aCHARFORMAT2structure in the window process to interact with the two processes.C++ Sample(remove the error checking):
Result: