Solved

InitInstance()

Posted on 2003-10-21
4
1,014 Views
Last Modified: 2013-11-20
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
Comment
Question by:thesmashest
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
SteH earned 50 total points
ID: 9591480
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
 

Author Comment

by:thesmashest
ID: 9592457
I am using dlg based application.
I know I can do that outside InitInstance(), but I really have to use InitInstance().
Any suggestions?
0
 
LVL 13

Expert Comment

by:SteH
ID: 9596897
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 9598939
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now