Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1034
  • Last Modified:

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?
~.~.~.~.~~.~.~.~.~~.~.~.~.~~.~.~.~.~
0
thesmashest
Asked:
thesmashest
  • 2
1 Solution
 
SteHCommented:
GetDlgItem (ID) is a member of class CWnd. CWinApp is not derived from CWnd. In that context you could try to use ::GetDlgItem (HWND, ID) but I doubt that you have already a valid HWND for dlg. What type of app do you have? If it is a dlg based up you could try to put the code in InitDialog () instead of InitInstance (). Even better would be to use a variable (type control not value) for that control. For that variable you can just call
c_cbOK.EnableWindow (FALSE);
in the scope where that variable is declared. To define the variable use the class wizard.

HTH
0
 
thesmashestAuthor Commented:
I am using dlg based application.
I know I can do that outside InitInstance(), but I really have to use InitInstance().
Any suggestions?
0
 
SteHCommented:
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.
0
 
itsmeandnobodyelseCommented:
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;
}

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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