Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CButton

Posted on 1998-01-18
6
Medium Priority
?
571 Views
Last Modified: 2013-11-20
Hi all,

How can I create a button derived form CButton in a ClistView class.  I need to create it in my OnDraw(). But when I  do I get an arror saying that pWnd cannot be NULL.  I use "this" when I create my button.  If I try to use afxgetparet, the button will not display correctly in the view.  And when I try to resize I get the same error as before.  I know this should be easy but I can't seem to get it.  Could some one help me.
0
Comment
Question by:sjm
  • 3
  • 3
6 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1314311
You should create it in OnCreate() rather than OnDraw. Put the button object as a member variable of your CListView.
0
 

Author Comment

by:sjm
ID: 1314312
Chenusa,

I can't put it in OnCreate because im using a derived class of CDC to do a BitMap copy of the screen to prevent flicker. I already have my buttons in OnCreate, but when I do an update flicker is gone, except for the buttons.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1314313
I don't understand your comment. Would you please explain it to me more clearly?
0
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.

 

Author Comment

by:sjm
ID: 1314314
Chenusa,

Ok, I am trying to get rid of the flicker I get when my app updates the screen.  I have a class derived from CDC that creates a bitmap image of the screen and blts it so that the screen redraws as one image to remove the flicker.  I have all my drawing routines in my Cview drevided class under OnDraw and my CDocument class under GetData.  But the buttons I use for the app are created under OnCreate in my Cview class.  When the screen updates it copies the images and blts it back, but after this process completes, the OnCreate functions redraws the buttons and I again have the flicker of the redrawn buttons.  When I tryied to place the buttons in my OnDraw function, I get an error saying that pWnd can't be NULL, refering the the CWnd* used by the creation of the buttons.  I tried to use afxgetparent but this caused the button to be painted outside the view.  And when I went ahead and resized the screen the same error came up.  I am trying to find the correct Cwnd* for my Cview to pass to the the button creation.  This should allow me to create the buttons in my OnDraw function.  
0
 
LVL 23

Expert Comment

by:chensu
ID: 1314315
Apply WS_CLIPCHILDREN style to your view. You should not create the button in OnDraw since OnDraw is called frequently.

> I am trying to find the correct Cwnd* for my Cview to pass to the the button creation. This should allow me to create the buttons in my OnDraw function.

CView is derived from CWnd. You can pass the this pointer.
0
 

Author Comment

by:sjm
ID: 1314316
chensu,

The WS_CLIPCHILDREN style worked great.  But note that I too thought that I could use the "this" pointer.  But as I said earlier, this caused an error stating that pWnd can not be NULL.
But thanks for the better way to go.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Integration Management Part 2
Suggested Courses

963 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