Posted on 1998-01-18
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.
Question by:sjm
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
  • 3
  • 3
LVL 23

Accepted Solution

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

Author Comment

ID: 1314312

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.
LVL 23

Expert Comment

ID: 1314313
I don't understand your comment. Would you please explain it to me more clearly?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1314314

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.  
LVL 23

Expert Comment

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.

Author Comment

ID: 1314316

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.

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 55
Different colored text in ComboBox without Subclassing 8 72
ORA-01403: no data found 43 111
notReplace  challenge 53 151
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.

735 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