Solved

Create CStatic not working with SetBitmap function

Posted on 2000-03-11
9
1,631 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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