我想将一些编辑字段放在启动屏幕的顶部,该屏幕在另一个顶级窗口中呈现(类似于此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.
}