Solved

Create CStatic not working with SetBitmap function

Posted on 2000-03-11
9
1,590 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

705 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

17 Experts available now in Live!

Get 1:1 Help Now