2

How to get handles of all the child windows in Mozilla firefox. Spy++ is showing only one class and window caption for all the windows. I tried using GetWindow and FindWindowEx but got nothing. I want to read URL from mozilla firefox.

1
  • 1
    This question is asked many many times a day. I still don't understand why people don't find automation. Jun 15, 2015 at 10:01

2 Answers 2

4

Spy++ uses standard Windows API calls to inspect window hierarchies (EnumWindows, EnumChildWindows, etc.). If Spy++ doesn't show any native windows, then there aren't any native windows. Consequently, you cannot find any native windows either. Firefox uses what's called Windowless Controls.

If you need to automate a GUI (which is likely the reason why you wish to find native windows), use the standard infrastructure available: UI Automation.

1
  • Thanks IInspectable for your answer. It is really helpful. Jun 15, 2015 at 10:22
-1

I got this answer from hazzey's answer and Ignas2526's comment on this post here

import win32gui
import win32ui
from ctypes import windll
from PIL import Image
import numpy as np

tab_name= '''[4k][60FPS] Optimus prime vs Lockdown Final Fight 4K 60FPS HFR[UHD] ULTRA HD - YouTube — Mozilla Firefox'''
hwnd= win32gui.FindWindow(None, tab_name)

window_rect = win32gui.GetWindowRect(hwnd)
w = window_rect[2] - window_rect[0]
h = window_rect[3] - window_rect[1]

hwndDC = win32gui.GetWindowDC(hwnd)
mfcDC = win32ui.CreateDCFromHandle(hwndDC)
saveDC = mfcDC.CreateCompatibleDC()

saveBitMap = win32ui.CreateBitmap()
saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

saveDC.SelectObject(saveBitMap)

result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 2)

# print(result)
bmpinfo = saveBitMap.GetInfo()
bmpstr = saveBitMap.GetBitmapBits(True)

im = Image.frombuffer(
    'RGB',
    (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
    bmpstr, 'raw', 'BGRX', 0, 1)
im.shape = (h, w, 4)
# im= np.array(im)

win32gui.DeleteObject(saveBitMap.GetHandle())
saveDC.DeleteDC()
mfcDC.DeleteDC()
win32gui.ReleaseDC(hwnd, hwndDC)

if result == 1:
    # PrintWindow Succeeded
    im.save("test.png")

For mozilla (or at least for my computer) the third parameter for this statement is 2 to make it work, but if not you can play and try another number with it.

result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 2)

The test.png: The test.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.