Solved

changing background colour

Posted on 1998-12-30
7
352 Views
Last Modified: 2010-04-01
I want to change details from a window class before it is created, such as background colour of the window. It seems I can only get a pointer to the class name (a string). I am currently using this code

CRect rect;
GetClientRect( rect );
pDC->FillSolidRect( rect, RGB( 0, 0xbb, 0 ) );

in the OnDraw function but this is highly inefficient. How can I do better?

Also, a trivial but annoying thing (not worth points but bugging me all the same) I have edited the document icon in my application but windows continues to use the old one on my system (I have not tried distributing the app yet). I have tried importing the .reg file but still no good. I guess this must be a windows thing because the application definitely recognises the new icon.
0
Comment
Question by:agrillage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:zyqwert
ID: 1181328
Before the class is registered, your app has a WNDCLASS structure, it contains members like hbrBackground which is an HBRUSH used to erase the background, if you fill it in then it will be used by every window of the class.

After the class is created, you can use SetClassLong to change the properties of a class.  The change will only affect new windows, not existing ones.

Since you use MFC, you might want to use AfxRegisterWndClass to get exactly the class you want.

0
 
LVL 6

Accepted Solution

by:
stsanz earned 50 total points
ID: 1181329
Create a solid brush in your init code :
CBrush  BackgroundBrush ;
BackgroundBrush.CreateSolidBrush(RGB(0,0xbb,0)) ;

Then, when you want to change the background color for the window, use :
SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)HBRUSH(BackgroundBrush)) ;

Don't forget to destroy the brush in your exit code :
BackgroundBrush.DeleteObject() ;

About your icon problem, is it an icon you associate with files having a particular extension or what is it associated with ?


0
 
LVL 1

Author Comment

by:agrillage
ID: 1181330
The icon is associated with the document ( the only document ) class for the application. It is the default from the app wizard. All I did was edit it.

I am trying the SetClassLong Function in the meantime.

Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:stsanz
ID: 1181331
For the icon problem, I think you have edited the 32x32 version of the icon, but not the 16x16 version, which is used to display the document icon in MFC.
WHen you edit the icon in Visual C++, you have a combobox where you can choose between the 32x32 version and the 16x16 version to edit.


0
 
LVL 1

Author Comment

by:agrillage
ID: 1181332
Points are for the background colour. I edited both icons and niether comes through correctly. I think it must be a bug but I would be interested to hear any more thoughts you might have.
0
 
LVL 6

Expert Comment

by:stsanz
ID: 1181333
Which version of Visual C++ do you use ?
Is your MFC application SDI or MDI ?

Try to open your application .EXE with Visual C++
using "Open as : resource" and tell me if the icon
in the .EXE appears as you modified it or as the default.
0
 
LVL 1

Author Comment

by:agrillage
ID: 1181334
Visual C++ 5.0 Enterprise
SDI
The icons appear as I want, correctly modified.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question