?
Solved

InitInstance()

Posted on 2003-10-21
4
Medium Priority
?
1,026 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
SteH earned 200 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

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.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 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