In my attempt to create my own win32 wrapper I have come across this problem.
Whenever I resize my window the background doesn’t get redrawn ( http://i44.tinypic.com/23k855.png white is supposed to be the background but when I make the window smaller it goes black)
Part of my class:
void Register( tstring _className,
tstring _menuName,
WNDPROC w32proc,
tstring hIcon,
HICON hIconSmall,
LPCTSTR hCursor,
HBRUSH hBrush=(HBRUSH)GetStockObject(WHITE_BRUSH),
UINT windowStyle = CS_HREDRAW | CS_VREDRAW,
int classExtraBytes=NULL,
int windowExtraBytes=NULL
)
{
className = _className;
menuName = _menuName;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = windowStyle;
wcex.lpfnWndProc = w32proc;
wcex.cbClsExtra = classExtraBytes;
wcex.cbWndExtra = windowExtraBytes;
wcex.hInstance = this->hInst;
wcex.hIcon = LoadIcon(this->hInst,hIcon.c_str());
wcex.hCursor = LoadCursor(NULL,hCursor);
wcex.hbrBackground = hBrush;
wcex.lpszMenuName = this->menuName.c_str();
wcex.lpszClassName = this->className.c_str();
wcex.hIconSm = hIconSmall;
RegisterClassEx(&wcex);
}
bool Create(tstring _windowTitle,
DWORD windowStyle,
int width=CW_USEDEFAULT,
int height=CW_USEDEFAULT,
int xPos=CW_USEDEFAULT,
int yPos=CW_USEDEFAULT,
HWND parent=NULL,
LPVOID lpParam=NULL,
HMENU menu=NULL
)
{
windowTitle = _windowTitle;
handle = CreateWindow(this->className.c_str(), this->windowTitle.c_str(), windowStyle,
xPos, yPos, width, height, parent, menu, this->hInst, lpParam);
if (!this->handle)
return false;
Show();
return true;
}
bool Show(int cmd=SW_SHOWNORMAL)
{
if( !ShowWindow(this->handle, cmd) || !UpdateWindow(this->handle) )
return false;
return true;
}
my window proc:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
and how I’m using everything:
mainwin = new Window(hInstance);
mainwin->Register(TEXT("test"),TEXT("test"),WndProc,TEXT("small.ico"),NULL,IDC_ARROW,NULL,NULL,NULL);
mainwin->Create(TEXT("test window"),WS_OVERLAPPEDWINDOW );
mainwin->Show(nCmdShow);
while(mainwin->GetMsg() > 0)
mainwin->TranslateDispatchMsg();
Some help would be very much appreciated 🙂
ps: I also tried handling WM_PAIN,WM_SIZE,WM_SIZING messages to call UpdateWindow and/or ShowWindow with no success
You are passing
NULLto thehBrushparameter ofRegister. That’s why the background is not redrawn when you resize.I suspect you intended to make use of your optional parameters and calling it like this: