Derived class from CStatic and dialogs

I have a class derived from CStatic and am trying to get it to display in a
dialog-based app.  The class works fine as I have tested it a window-based
app and everything works fine.  In the dialog-based app however, the call
to Create() crashes the app.

I have thus fallen back to trying to get a CStatic instance onto the dialog
instead, with the same results.  The code I'm using to create the object is
the following:

pStatic->Create("", WS_VISIBLE|WS_CHILD, rect, this, IDC_MYSTATIC);

Where pStatic is declared as a class member in the header file and rect is
an instance of CRect.  IDC_MYSTATIC is also correctly defined.  This call
is made from the constructor of the dialog class.

Anyon any idea what I'm doing wrong?
-- 
"That's right," he said. "We're philosophers. We think, therefore we am."
(Small Gods)

0
james3235 (1)
2/9/2005 6:11:25 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
490 Views

Similar Articles

[PageSpeed] 54

"James Telfer" <james@jamesandsian.wanadoo.co.uk> wrote in message
news:cudjo5$bls$1@newsg3.svr.pol.co.uk...
> I have a class derived from CStatic and am trying to get it to display in
a
> dialog-based app.  The class works fine as I have tested it a window-based
> app and everything works fine.  In the dialog-based app however, the call
> to Create() crashes the app.
>
> I have thus fallen back to trying to get a CStatic instance onto the
dialog
> instead, with the same results.  The code I'm using to create the object
is
> the following:
>
> pStatic->Create("", WS_VISIBLE|WS_CHILD, rect, this, IDC_MYSTATIC);
>
> Where pStatic is declared as a class member in the header file and rect is
> an instance of CRect.  IDC_MYSTATIC is also correctly defined.  This call
> is made from the constructor of the dialog class.
>
> Anyon any idea what I'm doing wrong?

I suspect it requires a valid HWND from the parent, and this seems unlikely
in the dialog's ctor. Try doing it from OnInitDialog instead, or consider
using a control member variable mapped to a static on your dialog template.
-- 
Jeff Partch


0
jeffp (1711)
2/9/2005 6:26:16 PM
- Dont call this in constructor of dialog. The dialog window is not yet
created. Do it in OnInitDialog.

- You could simply use a CStatic in resource editor and place it in
your dialog. And then replace the CStatic in your dialog's header file
with your own clss name.

---------
Ajay Kalra
ajaykalra@yahoo.com

James Telfer wrote:
> I have a class derived from CStatic and am trying to get it to
display in a
> dialog-based app.  The class works fine as I have tested it a
window-based
> app and everything works fine.  In the dialog-based app however, the
call
> to Create() crashes the app.
>
> I have thus fallen back to trying to get a CStatic instance onto the
dialog
> instead, with the same results.  The code I'm using to create the
object is
> the following:
>
> pStatic->Create("", WS_VISIBLE|WS_CHILD, rect, this, IDC_MYSTATIC);
>
> Where pStatic is declared as a class member in the header file and
rect is
> an instance of CRect.  IDC_MYSTATIC is also correctly defined.  This
call
> is made from the constructor of the dialog class.
>
> Anyon any idea what I'm doing wrong?
> --
> "That's right," he said. "We're philosophers. We think, therefore we
am."
> (Small Gods)

0
ajaykalra (6842)
2/9/2005 6:27:03 PM
There should be no problem; generally there is no need to do an explicit Create for a
static control; just create a control variable of the correct class. Note that your code
does not show
	CMyStatic * pStatic = new CMyStatic;
which is essential to make the code work. But there is no reason to declare it as a
CMyStatic * or use new; just declare 
	CMyStatic myStatic;
and you are done.
				joe

On Wed, 09 Feb 2005 18:11:25 +0000, James Telfer <james@jamesandsian.wanadoo.co.uk> wrote:

>I have a class derived from CStatic and am trying to get it to display in a
>dialog-based app.  The class works fine as I have tested it a window-based
>app and everything works fine.  In the dialog-based app however, the call
>to Create() crashes the app.
>
>I have thus fallen back to trying to get a CStatic instance onto the dialog
>instead, with the same results.  The code I'm using to create the object is
>the following:
>
>pStatic->Create("", WS_VISIBLE|WS_CHILD, rect, this, IDC_MYSTATIC);
>
>Where pStatic is declared as a class member in the header file and rect is
>an instance of CRect.  IDC_MYSTATIC is also correctly defined.  This call
>is made from the constructor of the dialog class.
>
>Anyon any idea what I'm doing wrong?

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/10/2005 12:18:30 AM
Reply:

Similar Artilces:

Open and close Dialog windows
Hello, I've got a dialog based application which performs a long lasting task for which the user has to wait. I would like to show the user a message that something is happening and I would like to close the message automatically when the task is finished. Because I've little experience with mfc I would like to ask how I can manage this and if there is an example for doing it ? Is there a faq for this group ? Thanks in advance, Ralf. "Ralf Erdmann" <ralf.erdmann@web.de> wrote in message news:403f7fa8.14652421@news.t-online.de... > Hello, > I've got a di...

Simple Class problem
I'm trying to add a member of type fstream to my class, but I keep getting the following compile error. "error C2059: syntax error : 'string'" class CRegistry { public: .... private: std::ofstream m_file("File.txt"); ... } Any idea why I can't do this? Thanks Instead of attempting to initialize the file inside the definition of the class [not possible], remove the ("File.txt") part and have it like this: private: std::ofstream m_file; Then, in the constructor of the class you could open the file and then use the attach method to atta...

Input locale changes to English only when a dialog box with IExplore control is closed
Hi, I found that the Input Locale changes to English only mode when a dialog box with IExplore control is closed. How can I prohibit this unexpected behavior? Please reply. Thanks in advance. Regards, Hyun-jik Bae ...

Class Names not available in Class Wizard
In Visual Studio 6.0 I have added a .cpp and .h file created in another MFC project to my current project They show up in the class view explorer and in the file window but when I am in Class Wizard the only class name available are the ones created in this project. Is there a way to add these so they will be available in Class Wizard? Delete the .clw file. Then try to use ClassWizard. It will rebuild the file with the names. joe On Fri, 5 Mar 2004 12:26:06 -0800, "Ward" <anonymous@discussions.microsoft.com> wrote: >In Visual Studio 6.0 I have added a .cpp and .h f...

Alarm Dialog Box
I am using Office Outlook 2003, Office Pro 2003. When an e- mail comes in with an attachment, I double click on the attachment icon to open/save it. The pop-up alarm box that asks what would you like to do-open this attachment or save it has been turned off (I accidently checked the box that says do not show this again). I would like to turn this option back on, but cannot find where to turn it back on. Thanks ...

Some advice creating a graph class
I am developing a program to draw a graph of database data using the OnPaint function in the View class. In the CView class I am grabbing the device context and then passing it to a function where I draw the actual graph by creating pens & brushes and using moveto/lineto functions etc. void CBView::OnPaint() { CPaintDC dc(this); // device context for painting DrawGraph(&dc); } This is working well but becoming quite large as a function and would think it is time to create a class to encapsulate the graph function. This seemed pretty straight forward until I started and realized it&...

object or class does not support the set of events 03-16-07
I have a form in a MDE that works fine on pc's with Access 2000 (or just the 2000 runtime).When I use that same form in the same MDE on a pc that has Office XP installed (even with Access 2000 runtime installed as well) I get the error "object or class does not support the set of events" when I close the form or when the mouse moves over a the DBITech ctMDay ActiveX control that I use.The MDE has these references on Access 2000:VBA: C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL (6.0.89.67)Access: C:\Program Files\Microsoft Office\Office\MSACC9.OLB (9.0.0.2719)s...

launching modal dialog from PropertyPage
If you launch a dialog or window from a button on a PropertyPage, where should the focus be returned, to the PropertyPage or the parent PropertySheet? ...

Move or Copy dialog box
Is there a way to resize the "Move or Copy" dialog box? I can't see which book I'm choosing because I can't read the entire name. Thanks. Hi AFAIK this is not possible -- Regards Frank Kabel Frankfurt, Germany Jerry wrote: > Is there a way to resize the "Move or Copy" dialog box? I > can't see which book I'm choosing because I can't read > the entire name. Thanks. ...

Way to supress "Enter Network Password" dialog for all time?
Searching around I've seen many mentions of this rude dialog box, which jumps to attention interrupting what you're doing, but those threads pertained more to discovering why they were seeing the box in the first place. At this point, I don't care. Let's just say your ISP keels over and dies and you go to check for mail. It doesn't matter why, I just want never to see it again. Is there a super-secret Registry hack which will accomplish this? I use OL2003 SP1 plus all patches with POP3 Thanks Hi, Milhouse click the following link http://support.microsoft.com/d...

Problem with Dialogs #2
Hello All; I am developing a dialog based application in MFC using visual studio 2005. I have a Property sheet in my dialog and one pane it contains a tree control. I am creating some dialogs again on double click event on tree control. Now the problem starts. When these dialogs are around, and I click on main dialog (Original one), it remains covered with the other dialogs. I want to make this dialog on the top of other dialogs. I have tried SetForeground on this but it was not usefull. any help in this regard will be thankfull Aniruddha Aniruddha wrote: > Hello All; > > I am...

how to draw a picture control on a dialog?
Hi, I cannot draw a picture on a picture control below. My bitmap simply does not show up. Could you give me a hit where I did wrong below? Thanks for your help. Tony void CMyDlg::OnPaint() { CWnd* pPicture = GetDlgItem(IDC_MY_PICTURE_CONTROL); CClientDC dc(pPicture); CDC dcMemory; dcMemory.CreateCompatibleDC((CDC*)&dc); // m_bitmap below was loaded with a resource bitmap at the beginning CBitmap *pOldBitmap = dcMemory.SelectObject(&m_bitmap); dc.BitBlt(100, 100, 100, 100, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); ... Your b...

CRecordSet read-only error in dialog-based app
I have an application that reads and writes to an Access DB using ODBC. The app was originally built as a Doc/View, but I recently converted it to a dialog-based app. Previously, reads/writes to a recordset worked fine (the recordset was set to snapshot). After the conversion to dialog-based, I began receiving a read-only error. First I tried changing to dynaset. That stopped the read-only problem, but caused an access violation in one of the multiple calls to DoFieldExchange() in CRecordSet::Update() ). The documentation says that a snapshot can be updatable as well as read-only. As f...

Building Full text index on Exchange 2003
Hello all, I am trying to build a full text index of the mailstore. The catalog is build fine but when performing a full population of the mailstore no mailboxes are indexed. The following messages show up in the Event log ------------------------------------------- Event Type: Information Event Source: Microsoft Search Event Category: Gatherer Event ID: 3018 Date: 28-7-2006 Time: 8:35:05 User: N/A Computer: TBG-VMS Description: The end of crawl for project <ExchangeServer_TBG-VMS privD88B396F> has been detected. The Gatherer successfully processed 1 documents totaling 0K. It failed...

Embed a dialog in CFormview
I have MDI application which uses CFormView as view. I have ActiveX control which displays modeless dialog. Is it possible to embed this dialog as control ( disabling captions, menus...) in my MDI inside the CFormView ? Since the dialog is invoked from ActiveX control method , I can also send the handle of My form view as Parent to the dialog.? Ashish. Here is how you would embed a Dialog box into a CFormView (now figuring out if you can do that with the activex control's dialog is up to you.) 1. The Child dialog has to be have the WS_CHILD flag and not the WS_POPUP flag. 2. It has to...

How to start a function from different class as Thread
Hello experts, within the same class following syntax works fine: > AfxBeginThread(ThreadFunc, (LPVOID)this, THREAD_PRIORITY_NORMAL); How is the syntax for starting a function from a different class? > AfxBeginThread(CDiff::ThreadFunc, (LPVOID)this, THREAD_PRIORITY_NORMAL); doesn't work. Can anybody help? Best regards "ZZT" <a@b.c> wrote in message news:c0m3tv$dqn$1@news1.wdf.sap-ag.de... > Hello experts, > > within the same class following syntax works fine: > > AfxBeginThread(ThreadFunc, (LPVOID)this, THREAD_PRIORITY_NORMAL); > > How is ...

MFC dialog dll problem
Hi Group I have put all dialogs that my app uses in a dll. This dialog dll is used by several apps. The problem is that when ever i add new dialog item inside the dll. i have to recompile all my app with the dll's lib file. Altough the app never uses the new dialog that i have just added into the dll. If i dont do this the app crashes when ever it tries to load one of the dialogs from the dll. How to get over this . Regards That is expected behavior when you use implicit linking. Your exe module needs import library to compile. Anytime you change a library code you have to rebu...

Model dialogs / UpdateWindow / UpdateData
1. Can I disable any controlls in dialog window using following code? CWnd* pWnd = GetDlgItem(nItem); pWnd->EnableWindow(0); 2. would UpdateWindow() / UpdateData() functions require inside OnCheck*() to update the dialog? I am just enabling / disabling some other controls (textbox, etc.) in the same dialog box using the above code. Thanks. "v4vijayakumar" wrote: > 1. Can I disable any controlls in dialog window using following code? > > CWnd* pWnd = GetDlgItem(nItem); > pWnd->EnableWindow(0); Ok, it will do. > 2. would UpdateWindow() / UpdateData(...

Hey can we change the color of Dialog Boxes
Hey guys i am new in MFC but know C++ programing and done work in win32 console applications now mving to MFC. Its just begining. So want to know can we change the color of dialog boxes and back groung color of our application ? Please guide me in detail. I shall be v.thank full to you. REGARDs: SHIRANI See if the following link helps you http://tinyurl.com/6apqhc Cheers Check Abdoul --------------------- "Xohaib" <zohaib.shirani@gmail.com> wrote in message news:bfce43da-4540-4185-a8bb-de1a24a0152a@8g2000hse.googlegroups.com... > Hey guys i am new in MFC b...

Dialog and destructor
Hi, Hi, I am developing a dialog based application and Im still facing an old problem :( "cmdtarg line 52". The problem is the value of the reference counter. I have 4 dialog (CDialogA, CDialogB, CDialogC, CDialogD) and 3 class derived from CWnd (CWnd1, CWnd2, CWnd3). The "main" dialog is A, from this I run (domodal) B and from this C. Dialog D can be opened from every dialog. The variables (all private) are For class CDialogA CDialogB m_BDlg; CDialogD m_DDlg; CWind1 m_ctlWnd1; CWind2 m_ctlWnd2; For class CDialogB CDialogC m_CDlg CDialogD m_DDlg; CWnd3 m_ctlWnd3 ...

Deriving from CString...?
Hi all, I writing a class that derives from CString and adds a few more pieces of frequently required functionality; e.g. a constructor that accepts an int a formats the CString appropriately, a Split() function that returns a CStringArray of tokens based on a separator etc. Of course, the main requirement for my class is that it can be used anywhere a CString can be used. Problem is that I've run into a situation where it doesn't. e.g. CString str1(_T("CString")); CMyString str2(_T("CMyString")); TRACE(_T("%s; %s\n"), str1, str2); produces the follow...

How to get a OPEN/SAVE dialog option window when open Excel from IE browser
I use the following to open Excel from IE browser, but I don't get a OPEN/SAVE dialog option window. Instead, the Excel opened in the browser window. How to get a OPEN/SAVE dialog option window? THanks. filesys.createTextFile(application("ApplicationPath") & "repository\repository_" & filenameval & ".csv",true) ...

CStatic control image repaint problem
I have an image loaded in a CStatic control. Once I load the image and change my focus to some other application and then change my focus back to the application having the CStatic control, I notice the image is no more seen. Please let me know how to resolve this problem. Thank you. Rajesh Do you draw the image in the OnPaint handler, or use an SS_BITMAP style-static and do a SetBitmap (this causes the built-in OnPaint handler to paint the image). Any other solution will not work. joe On 26 May 2004 14:04:03 -0700, rajesh79@hotmail.com (Rajesh) wrote: >I have an image loaded in a C...

Calling two dialogs in InitInstance
Hello! I have a dialog based application. In the application InitInstance I have a code like: // This part works!! CguiDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); // This part doesn't CguiDlg dlg2; m_pMainWnd = &dlg2; nResponse = dlg2.DoModal(); Any idea why the second call with a second dialog fails? Thanks! When you call "DoModal" you do not return until the dialog closes. Using your code I expect the first dialog to open. Then when you close the first dialog the second dialog will open. If you want both to open at the...

Redux: Wrong dialog displayed using derived classes
First of all, thanks for the help you all have given so far. But it's still not working. My problem: Because I have so many related dialogs, each with lots of code processing the input, I've made a hierarchy of dialog classes derived from CDialog. Each derived dialog has its own unique dialog resource. It took some doing to get it all to link, so it's certain I derived my classes wrong. When I activate a derived dialog at run time, the base class's dialog is displayed instead of that of the derived one. Why, and how to fix it? Thanks very much!! Rick Here is the class hie...