Solved

InitInstance()

Posted on 2003-10-21
4
1,010 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

12 Experts available now in Live!

Get 1:1 Help Now