簡體   English   中英

WS_EX_LAYERED父級的Win32 Edit控件在背景透明時不接收鼠標/單擊事件

[英]Win32 Edit Controls of WS_EX_LAYERED parent dont receive mouse/click events when their background is transparent

我想將一些編輯字段放在初始屏幕的頂部,該初始屏幕在另一個頂級窗口中呈現(類似於此http://code.logos.com/blog/2008/09/displaying_a_splash_screen_with_c_part_ii.html的透明PNG)。

我創建了一個輔助窗口,該窗口始終位於初始屏幕的頂部,並通過WS_EX_LAYERED使其透明。

現在,我通過捕獲WM_CTLCOLOREDIT來設置wndproc中編輯字段的背景色。

這可以正常工作,我的輸入控件是透明的(例如,不可見),並且在初始屏幕上僅可見輸入的文本。

現在的問題是,指示此處是文本框的鼠標光標不起作用,我也無法在該框中單擊以使其聚焦。 如果我不使編輯控件的背景透明,問題將全部消失。 WM_NCHITTEST透明時也沒有。 我唯一獲得鼠標光標的時間是如果在框中已經輸入了(可見)文本

g_HWNControlsParent = CreateWindowEx( WS_EX_LAYERED,.....);
hwLoginField = CreateWindowEx(NULL,"EDIT", "-User-",    WS_CHILD|WS_VISIBLE|WS_TABSTOP, ....g_HWNControlsParent);
SetLayeredWindowAttributes(g_HWNControlsParent,RGB(0, 0, 0), 0, LWA_COLORKEY) ;

在HWNControlsParent wndproc中

case WM_CTLCOLOREDIT: { // BG Color of Input Fields
        HDC hdc = (HDC)wParam;
        SetTextColor(hdc, RGB(230,230,230));
        SetBkColor(hdc, RGB(0,0,0)); // Color of Background where Text is entered
         SetDCBrushColor(hdc, RGB(0,0,0)); // Color of Background where no Text is
        return (LRESULT) GetStockObject(DC_BRUSH); // return a DC brush.
    }

如果您對透明區域使用1而不是0的alpha值,它們將仍然是透明的,但是會響應鼠標單擊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM