我想将父窗口设为非透明,RGB值为(99,99,99)?以前我的窗口是透明的,但现在我要求窗口不透明。
下面提到的是与我父窗口相关的功能:
ATOM MyRegisterClass(HINSTANCE hInstance)
{
LogEntry(L"Entered in myRegisterClass Function");
WNDCLASS CLASS_NAME_ONE_SEG_APP;
CLASS_NAME_ONE_SEG_APP.cbClsExtra = 0;
CLASS_NAME_ONE_SEG_APP.cbWndExtra = 0;
CLASS_NAME_ONE_SEG_APP.hbrBackground = 0;
CLASS_NAME_ONE_SEG_APP.hCursor = 0;
CLASS_NAME_ONE_SEG_APP.hIcon = 0;
CLASS_NAME_ONE_SEG_APP.hInstance = hInstance;
CLASS_NAME_ONE_SEG_APP.lpfnWndProc = (WNDPROC) WndProc;
CLASS_NAME_ONE_SEG_APP.lpszClassName = className;
CLASS_NAME_ONE_SEG_APP.lpszMenuName = 0;
CLASS_NAME_ONE_SEG_APP.style = 0;
LogEntry(L"Exiting from myRegisterClass Function");
return RegisterClass(&CLASS_NAME_ONE_SEG_APP);
}
下面提到的是一个InitInstance函数,我在其中创建父窗口。
handles.parent是我的父窗口。
bool WINAPI InitInstance(HINSTANCE hInstance, int nCmdShow)
{
LogEntry(L"Entered in InitInstance Function");
handles.parent = CreateWindowEx(0,
className,
windowName,
WS_VISIBLE | WS_POPUP,
0, 0,
coordinates.width, coordinates.height,
NULL,
NULL,
hInstance,
NULL);
if(handles.parent == NULL)
{
LogValue(L"Cannot Create Parent Window"
L"\nInitInstance Function terminated abnormally");
return false;
}
else
{
UpdateWindow(handles.parent);
ShowWindow(handles.parent, nCmdShow);
LogEntry(L"Exiting from InitInstance Function");
return true;
}
}
以下提到的是WM_PAINT的函数:
case WM_PAINT:
LogEntry(L"Entred in WM_PAINT");
PaintWindow();
SetFocus(handles.parent);
LogEntry(L"Exited from WM_PAINT");
break;
这个PaintWindow执行以下操作.....
void PaintWindow()
{
LogEntry(L"Entered in PaintWindow Function");
HWND *handle = &handles.volUp;
//Paint Buttons on the window
for(register char i = MIN_BUTTON; i <= MAX_BUTTON; i++)
{
PaintButton( (INITIAL_BUTTON + i) , *handle, btns, i);
handle++;
}
//Paint the AXIS_VOL_ON_OFF Button According to its Status
if(volumeStatus.status == VOLUME_ON)
PaintButton(IDB_BTN_VOL_OFF, handles.volOnOff, btns, AXIS_VOL_ON_OFF);
else if(volumeStatus.status = VOLUME_MUTE)
PaintButton(IDB_BTN_VOL_ON, handles.volOnOff, btns, AXIS_VOL_ON_OFF);
//Paint Images on the window
if(handles.screenMode == SCREEN_MODE_OPERATION)
InsertImages();
LogEntry(L"Exited from PaintWindow Function");
}
提前致谢......
答案 0 :(得分:1)
您需要为您的班级提供非空背景画笔
CLASS_NAME_ONE_SEG_APP.hbrBackground = CreateSolidBrush(RGB((99,99,99));
在WindowProc中,您需要确保将WM_ERASEBKGND消息传递给DefWindowProc。 (那部分可能已经发生了)
好的,你的WM_PAINT代码做错了。处理WM_PAINT消息时,请务必调用BeginPaint和EndPaint
,并且必须使用绘制时从BeginPaint获取的HDC。
case WM_PAINT:
{
LogEntry(L"Entred in WM_PAINT");
PAINTSTRUCT ps;
HDC hdc = BeginPaint(&ps);
PaintWindow(hdc);
EndPaint(hwnd, &ps);
LogEntry(L"Exited from WM_PAINT");
}
break;
您的窗口是透明的,因为您从未在WM_PAINT处理程序中调用BeginPaint,因此您永远不会在屏幕上绘制任何内容。
有关更完整的示例,请参阅Drawing in the Client Area。