Link to home
Start Free TrialLog in
Avatar of thesmashest
thesmashest

asked on

InitInstance()

Greetings experts:
~.~.~.~.~~.~.~.~.~~.~.~.~.~~.~.~.~.~

I am trying to do the following:

BOOL CProgramApp::InitInstance()
{

AfxEnableControlContainer();

CButton *c = (CButton *)GetDlgItem(IDOK);
c->EnableWindow(FALSE);

.....

}

//I am getting the following error:
//"'GetDlgItem' : function does not take 1 parameters"


Is there a way to solve this thing?
~.~.~.~.~~.~.~.~.~~.~.~.~.~~.~.~.~.~
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
Avatar of thesmashest
thesmashest

ASKER

I am using dlg based application.
I know I can do that outside InitInstance(), but I really have to use InitInstance().
Any suggestions?
The problem I see is that during InitInstance of the application neither the dlg nor any control in it exist. How to change their behaviour/appearance then? What is your intention in disabling the button? Perhaps with some more information someone can give you a hint.

If you use the variable approach you can change the variable just after declaration and assure it is disabled when it is first shown.
If you have a dialog based application created by AppWizard then InitInstance should have somewhere code like this:

      CMyDialog myDlg;
      myDlg.DoModal();
      return FALSE;

There the dialog is constructed (1. line), created and executed (2. line). The return FALSE prevents CWinApp to start its own message loop because if  DoModal() returns the dialog gets closed (and the application ends).

Now, you can't disable the dialog button in InitInstance with

      CMyDialog myDlg;
      CWnd* pBtn = myDlg.GetDialogItem(IDOK);
      pBtn->EnableWindow(FALSE);
      myDlg.DoModal();
      return FALSE;

because the dialog object - and it's child the OK button are no windows after construction. They become windows in DoModal() that is a member of CDialog.

But you should have an implementation of your CMyDialog class - cmydialog.cpp - where AppWizard has generated CMyDialog::InitDialog(). That is the place where you should disable the button:

CMyDialog::InitDialog()
{
      CDialog::InitDialog();
      ...

      CWnd* pBtn = GetDialogItem(IDOK);
      pBtn->EnableWindow(FALSE);
           

      return FALSE;
}