Link to home
Start Free TrialLog in
Avatar of jeanhetu
jeanhetu

asked on

Unable to add a CStatic button control in a new dialog box.

In brief here is an overview of my application I am working on which is created using embedded visual c++ (pocket pc 2003 app) that was started by a collegue of mine and that must be completed by myself. The application is to be full screened without any top or bottom task bars.

I have a main dialog box(DialogA) which upon certain incoming user inputs calls up one of two different additionnal dialog box(DialogB and DialogC). In each of these extra dialog boxes I have added a label which I use as a button for user input to kill the extra dialog boxes. In DialogA there two buttons one to call DialogB and another for DialogC.  I have successfully created the interaction which allows me to popup the DialogB or DialogC in full screen upon user input from DialogA as well as being able to kill the DialogB or DialogC from user input from there respective "kill buttons".  

Up to until here my application works as desired. I must specify that DialogB was created by my collegue and that I am working on DialogC. My problem occurs when I try to add CStatic controls to these "kill buttons" to allow me to play arround with their position as well as other features.  I use the Class wizard and add variables to the "kill button" of DialogC and once I do this I recompile (no problems here) but when I try and start my application it loads up fine but at a certain point (after various application initializations) it just shuts down by itself.  I cannot imagine how to solve this problem since this is not the first application I have created that calls up a new DialogBox where I play around with CStatic controls of buttons on the new DialogBox.

Is there an initialization I have forgotten, how can this behavior be explained and where should I start looking for a solution. I have checked out the Ressource.h file where all of the IDC... are defined and I have noticed that some have the same numbers but these other controls seem to work fine regardless of the identical identifiers.  

Perhaps worths noting is that I am able to successfully add CString controls to the buttons in questions which has allowed me to use a workaround to some of my problems(ie: label content) but I would like to create a clean solution to this problem.
Avatar of Member_2_1001466
Member_2_1001466

You should add a CButton control variable when dealing with a button. A CStatic is the control of a "static text". A CString value variable can be used for either to change the appropriate text (button or label).

Or are these "kill buttons" static text?
Avatar of jeanhetu

ASKER

These "kill buttons" are effecitvely static text that I use as buttons. The reason for this is more of a standardization point of view seing as my predecessor had started using these static texts as buttons.
Avatar of Axter
You can create a button that is flat by setting the properties.
Yes I knew of this property of the button, but like I mentionned I need these static text buttons because first of all this is how the application was initially developped and furthermore these buttons are used more like static text than buttons.

Please stick to the initial problem of I not being able to attribute CStatic controls to these static texts.  I basically would like to know where to start looking for the problem. It seems to be during the initial creation of the DialogC  class since if I do create the CStatic controls of the static texts but I comment out the DialogC pointer initialized in my main DialogA class my application seems to work fine but obviously I am unable to use the DialogC without this pointer. Sample Code follows:

class DialogA: public CDialog
{
// Construction
public:
        DialogB dlgPtrB;
        DialogC dlgPtrC;
      DialogA(CWnd* pParent = NULL);   // standard constructor
}

class DialogB: public CDialog
{
// Construction
public:
      DialogB(CWnd* pParent = NULL);   // standard constructor
}


class DialogC: public CDialog
{
// Construction
public:
      DialogC(CWnd* pParent = NULL);   // standard constructor
}

Now to call either DialogB or DialogC from DialogA

Either:

dlgPtrB.Create(IDD_DIALOGB);
dlgPtrB.ShowWindow(SW_SHOW);
dlgPtrB.SetForegroundWindow();

or

dlgPtrC.Create(IDD_DIALOGC);
dlgPtrC.ShowWindow(SW_SHOW);
dlgPtrC.SetForegroundWindow();

Hope this bit of code can clear things up.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks SteH,

I accepted the answer because this explanation does clarify the point of creating Dialogs from within other Dialogs.

Unfortunately I have yet to make my application work properly although I have found a workaround.  There are perhaps things that are initialized by my predecessor that I do not quite understand why they where done in such a fashion but the end result is that I found a workaround to my problem.  

Just to let you know it was still impossible for me to create the new Dialog in the above fashion which leaves me guessing.
I made a small mistake as I added to my dialog class's constructor a parameter. For you it should be sufficient to use:

This is how I do this in one of my application. It is in the OnInitDialog of the main dialog

    s_pDlg = new CMyDlg (); // empty constructor needed overriden in your class!
    iRet = s_pDlg->Create (IDD_MYDLG, this); // main dialog is parent.
    // iRet = s_pDlg->SetWindowPos (&wndTop, iLeft , iTop, iWidth, iHeight, SWP_HIDEWINDOW);  // only for embedding dialog as                  
                                                                                                                                              //subwindow.
And in OnDestroy of the main dialog I call
        s_pDlg->DestroyWindow ();
        delete s_pDlg;
        s_pDlg = NULL;