I've tried this:
I put this in "WM_CREATE:", but this doesn't workCode:HDC h = hwnd; // hwnd is my window SetBkColor(h,RGB(233,233,233));
I've checked MSDN, but it doesn't give good details on how to use SetBkColor.
Can anyone please help?
I've tried this:
I put this in "WM_CREATE:", but this doesn't workCode:HDC h = hwnd; // hwnd is my window SetBkColor(h,RGB(233,233,233));
I've checked MSDN, but it doesn't give good details on how to use SetBkColor.
Can anyone please help?
SetBkColor() will only take effect when you draw to the HDC. What you need to do is place the color specification in your window class registration.
Look up the CreateBrushIndirect() function for the parameters. You'll have to remember to delete the brush when you're done with it, which will likely be at the termination of the application.Code:hBrush=CreateBrushIndirect(...); wcx.hBrush=hBrush;
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Oops hbrBackground. Sorry.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
My code:
It compile's fine, but I get the error message from Windows.Code:HBRUSH hBrush; LOGBRUSH *logBrush; logBrush->lbStyle = BS_SOLID; logBrush->lbColor = RGB(233,233,233); // Define our mainw's class mainw.wc.cbSize = sizeof(WNDCLASSEX); mainw.wc.style = 0; mainw.wc.lpfnWndProc = mainw_proc; mainw.wc.cbClsExtra = 0; mainw.wc.cbWndExtra = 0; mainw.wc.hInstance = hInstance; mainw.wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); mainw.wc.hCursor = LoadCursor(NULL, IDC_ARROW); mainw.wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); mainw.wc.lpszMenuName = NULL; mainw.wc.lpszClassName = g_szClassName; mainw.wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); hBrush = CreateBrushIndirect(logBrush); mainw.wc.hbrBackground = hBrush;
What error message do you get?
Anyway, you're not doing things right.
There you go.Code:HBRUSH hBrush; LOGBRUSH logBrush; //You have to declare the variable, not a pointer logBrush.lbStyle = BS_SOLID; logBrush.lbColor = RGB(233,233,233); logBrush.lbHatch= NULL; //You have to make sure this member is NULL if you're not using it hBrush=CreateBrushIndirect(&logBrush); //Now fill the WNDCLASSEX members
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
(I declared a pointer because that's what MSDN showed me).
See?Code:HBRUSH CreateBrushIndirect( CONST LOGBRUSH *lplb // brush information );
Anyways. Now the background is different, but it's BLACK! I don't see how it gets that color from "RBG(233,233,233)", but I'll figure this one out for myself for the time being.
EDIT:
Nevermind! I found my error.
MSDN told you to pass the address of a LOGBRUSH instance to CreateBrushIndirect(). You have to first create a LOGBRUSH instance and fill it. You then use the & operator to pass its address. Capeesh?(I declared a pointer because that's what MSDN showed me).
It works fine for me. Post the code you're using.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
What was your error?
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
By Error was:
I forgot to change the second line to be "logBrush.lbHatch".Code:... logBrush.lbColor = RGB(233,233,233); logBrush.lbColor = NULL; ...
lol. I'm glad it's solved.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Thanks for helping me. Though, I do have another question:
How do I make my buttons look "normal" (Like a normal Win9x button)? Currently, it looks really weird.
Post pictures to show what you mean.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Hmmm. Try creating the button with the style WS_EX_CLIENTEDGE, but I'm not too sure about that. Remember to use CreateWindowEx(), not CreateWindow().
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials