Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create CStatic not working with SetBitmap function

Posted on 2000-03-11
9
Medium Priority
?
1,693 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
[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
  • 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

604 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