Skip to main content
gamedev.net
🔒 Locked

Win32 Application

Started by dev578 2 replies 400+ views
Original Post
dev578
dev578
I am using the Win32 API to make an application to assist in making a custom .font file format for a game GUI I am making. It is a SDI application. I would like to make the background of the window grey. Currently, when the application is initializing, I get the HDC, and change the color like so: HDC hdc = GetDC(hWnd); if(!hdc) return EXIT_FAILURE; RECT rect; GetClientRect(hWnd,▭); FillRect(hdc,▭,CreateSolidBrush(0x00FF0000)); This successfully makes a blue background when the application boots (I know, its stupid, the format is 0x00bbggrr). Here is my problem though, when the user grabs the title bar and moves the application around vigourously for about 3-10 seconds, the blue dissapears to white, and doesn't come back. The only thing I can think of is running the above code on WM_PAINT, but that is extremely unefficient and will glitch. I know I have seen other Win32 applications that have different backgrounds other than white, so I'm sure there is a way to do it. If anyone has any ideas, that would be appreciated. Thank you, -Dev578
SiCrane
SiCrane
Did you try WM_ERASEBKGND?
Wavarian
Wavarian
Application start:

HBRUSH newBrush = CreateSolidBrush(0x00FF0000);ULONG_PTR oldBrush = SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)newBrush);


Application end:

SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)oldBrush);DeleteObject(newBrush);


This code hasn't been tested.. But was probably worth posting.
Samurai Jack
Samurai Jack
When you register your window's class, you can specify the class's hBrush value. I don't exactly know which command you have to use, but help about RegisterClass() or RegisterClassEx() will help you out (MSDN). So you don't have to trap the paint messages unless you would like too (BeginPaint() and EndPaint()).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.