Solved

Create CStatic not working with SetBitmap function

Posted on 2000-03-11
9
1,602 Views
Last Modified: 2013-11-20
I'm having problems creating a dynamic CStatic field.  When I created a dynamic CStatic field the SetBitmap function doesn't work.
if (!Create("",WS_CHILD|WS_VISIBLE|BS_BITMAP|SS_NOTIFY, MyRect, PWnd, 16969+intRoomNumber))//WS_CHILD|SS_BITMAP|WM_CTLCOLOR|WS_VISIBLE  
{
      MessageBox("Create failed","",0);
      return;
}
SetBitmap((HBITMAP)LoadImage(NULL,szFilename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION));

I know the problem is not in the LoadImage function, because I have the exact same statement on a field that is not dynamic, and it works with no problem.
I'm pretty sure the problem is with the Create function because that is the only difference between the two.

Please do not give me an answer by referring me to a previously answered questioned.  I've already wasted about 100 points looking at previous similar questions, and non of them had the right answer for my particular problem.

Thanks in advance…..
0
Comment
Question by:Axter
  • 6
  • 3
9 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2607841
Try
Create("",WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_NOTIFY, MyRect, ....)
0
 
LVL 5

Accepted Solution

by:
Wyn earned 100 total points
ID: 2607843
oops,it's:
Create("",WS_CHILD|WS_VISIBLE|SS_BITMAP, MyRect, ....)

or

Create("",WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE   , MyRect, ....)
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2607848
Besides,although less chance,you'd not subclass it.
0
 
LVL 30

Author Comment

by:Axter
ID: 2608320
Wyn,
I tried that setting, but it only works if I remove the "OnPaint" member.
I need it to work with the OnPaint.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Wyn
ID: 2608869
No,you'd not reject me,at least It works for adding bitmap.

I bet you'v got to add code to your OnPaint for bitmap,I suggest you check the source code of CStatic.
0
 
LVL 30

Author Comment

by:Axter
ID: 2610183
I'm sorry Wyn, but I can't accept the answer if I have to remove required code from the program.  Your answer does me no good if I have to remove the OnPaint function to get it to work.
I need a working solution that let's me keep my OnPaint function.
I'll take a look at the source code for CStatic, if this helps me figure it out, I'll give you the points, but if it doesn't, I have to reject your answer.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2610818
->I'm sorry Wyn, but I can't accept the answer if I have to remove required code from the program.  Your answer does me no good if I have to remove the OnPaint function to get it to work.
====================================
Oh,not at all.
You misundertand me.You should reject me.I just want to say you'd better ask more because I dont know OnPaint matter when you ask this quesiotn,Right:)
 
->I need a working solution that let's me keep my OnPaint function.
====================
You can do this.All in all,you can blit the bitmap mannually and setbkmode to transparent and write text onto it.That's all.
0
 
LVL 30

Author Comment

by:Axter
ID: 2612471
Wyn,
I finally figured out the problem with the OnPaint problem, and your answer definitely help me focus on the right direction.  When the OnPaint function is created by the Class-Wizard, it creates the following:
void RoomIconGroup::OnPaint()
{
      CPaintDC dc(this); // device context for painting

      // Do not call CStatic::OnPaint() for painting messages
}

This is very misleading and it inappropriately put together.  If the above function is left as-is, the "CStatic" bitmap will not appear.  What has to be added to the above function is a call to the base class OnPaint() function.

void RoomIconGroup::OnPaint()
{
      CPaintDC dc(this); // device context for painting

      // Do not call CStatic::OnPaint() for painting messages
      CStatic::OnPaint();
}

The commented line that the Class-Wizard puts in the function, makes it look like you're not supposed to make a call to the base function.  Further more, in most cases where the base class function has to be called, the class-wizard automatically puts the call into the function.  This proves to me that you can't always rely on the class-wizard to do everything.  You have to double check it.

Just to info anyone else that may have a similar problem with "CbitmapButton" it also has the same problem with OnPaint.

Thanks for your help Wyn.

P.S.
Wyn,
I'm not sure if you can add comments after I award you the points.  So, could you please tell me what you're talking about "blit the bitmap mannually", and if it's not to much trouble, could you give me a short example?
Any additional information would be appreciated.... Thanks!
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2622160
I dont know why you give me a C degree.I havent gotten this degree for a time:)

Regarding your problem,i'm surprised that you solve it by adding CStatic:OnPaint() to it:)
What does CStatic::OnPaint do here?
I think it's just CWnd::OnPaint(),correct me if I'm wrong.I'm not very familiar with MFC.

Try call this sequence:
SetBitmap();
Invalidate();
UpdateWindow();

Regards
W.Yinan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 111
Looking for a specific application/software 2 104
EvenOdd challenge 10 88
mapAB Challlenge 35 124
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now