• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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.
0
jeanhetu
Asked:
jeanhetu
  • 3
  • 3
1 Solution
 
SteHCommented:
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?
0
 
jeanhetuAuthor Commented:
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.
0
 
AxterCommented:
You can create a button that is flat by setting the properties.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jeanhetuAuthor Commented:
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
0
 
SteHCommented:
>Now to call either DialogB or DialogC from DialogA
>Either:
this line I find problematic:
>dlgPtrB.Create(IDD_DIALOGB);
The creation of the dialog should happen only once. See below where to put it.
>dlgPtrB.ShowWindow(SW_SHOW);
>dlgPtrB.SetForegroundWindow();

next point:
>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.


I don't see any pointer in your code example. You could try to rewrite the creation like
class DialogA: public CDialog
{
// Construction
public:
        DialogB* pDlgPtrB;
        DialogC* pDlgPtrC;
     DialogA(CWnd* pParent = NULL);   // standard constructor
    OnInitDialog (); // override this method
}

DialogA::DialogA (CWnd* pParent)
{
    pDlgPtrB = new DialogB (this); // this might need to go in OnInitDialog
    pDlgPtrC = new DialogC (this);
}

DialogA::OnInitDialog ()
{
   pDlgPtrB->Create (IDD_DIALOGB); // these functions should only be called once during the livetime of the dialog object.
   pDlgPtrC->Create (IDD_DIALOGC);
}

0
 
jeanhetuAuthor Commented:
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.
0
 
SteHCommented:
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;
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now