how to prevent drop-down menu disappearing after adding transparant layer

78 Views Asked by At

I have built an application that adds on-screen application help in context of an windows desktop application. When the object of help relates to a drop-down menu I am encountering problems that the drop-down menu disappears when adding a transparant overlay. What attributes should I use to keep the drop-down menu visible? Please see the following code where I define the window to draw on top of the current foreground window:

    exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT
    style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE

    oWindow = win32gui.CreateWindowEx(
        exStyle,
        owndClassAtom,
        'Per52Overlay', # WindowName
        style,
        winX1, # x
        winY1, # y
        #win32api.GetSystemMetrics(win32con.SM_CXSCREEN), # width
        #win32api.GetSystemMetrics(win32con.SM_CYSCREEN), # height
        winWidth, #width
        winHeight, #height
        hwnd, # hWndParent
        None, # hMenu
        hInstance,
        None # lpParam
    )
    oWindowHndl = oWindow
    # //msdn.microsoft.com/en-us/library/windows/desktop/ms633540(v=vs.85).aspx
    win32gui.SetLayeredWindowAttributes(oWindow, 0x00ffffff, 255, win32con.LWA_COLORKEY | win32con.LWA_ALPHA)
    hdc, paintStruct = win32gui.BeginPaint(oWindow)
    hPen = win32gui.CreatePen(win32con.PS_SOLID,3, win32api.RGB(0,255,0))
    win32gui.SelectObject(hdc, hPen)
    win32gui.Rectangle(hdc, objX1, objY1, objX2, objY2)
    win32gui.EndPaint(oWindow, paintStruct)
    win32gui.SetWindowPos(oWindow, win32con.HWND_TOPMOST, winX1, winY1, winWidth, winHeight, win32con.SWP_DRAWFRAME | win32con.SWP_NOACTIVATE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
    win32gui.ShowWindow(oWindow, win32con.SW_SHOW)
    win32gui.UpdateWindow(oWindow)

At some stage the window shall be drawn:

winCrd = win32gui.GetWindowRect(activeWindow)
objCrd = (startX, startY, endX, endY)
drawOnApp(activeWindow, winCrd, objCrd, message)
win32gui.BringWindowToTop(activeWindow)

My guess is that I am doing something wrong with the attributes in combination with what window should be on top / activated / to foreground etc. etc.

Can you give me some clues to dive more in this matter?

0

There are 0 best solutions below