Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"'GetDlgItem' : function does not take 1 parameters" error

Status
Not open for further replies.

phoeneous

Programmer
Aug 21, 2001
3
0
0
US
Hello to all,

During build, I keep getting this error:

<b> C:\Program Files\Microsoft Visual Studio\MyProjects\buttons\buttonsDlg.cpp(246) : error C2660: 'GetDlgItem' : function does not take 1 parameters </b>

I recently added the member function ChangeDialogTitle(UINT nID) which will modify the dialog box's title during run time, depending on which button is pressed. Here is my code. Any help as to why I keep getting this error will be greatly appreciated :)

<code>

}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CButtonsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CButtonsDlg::OnShowHide()
{
// TODO: Add your control notification handler code here

//check if the left button is currently visible

BOOL bVisible = GetDlgItem(IDC_LEFT) -> IsWindowVisible ();

//** Toggle the visbility of each control

GetDlgItem(IDC_LEFT) -> ShowWindow(bVisible? SW_HIDE : SW_SHOW);

GetDlgItem(IDC_CENTER) -> ShowWindow(bVisible? SW_HIDE : SW_SHOW);

GetDlgItem(IDC_RIGHT) -> ShowWindow(bVisible? SW_HIDE : SW_SHOW);

//**Toggle the show/hide's button caption

GetDlgItem(IDC_SHOW_HIDE) -> SetWindowText(bVisible? &quot;Show&quot; : &quot;Hide&quot;);
}

void CButtonsDlg::OnEnableDisable()
{
// TODO: Add your control notification handler code here

//** Obtain the current state of the Left button

BOOL bState = GetDlgItem(IDC_LEFT) -> IsWindowEnabled();

//** Toggle the stat of each control

GetDlgItem(IDC_LEFT) -> EnableWindow(!bState);
GetDlgItem(IDC_CENTER) -> EnableWindow(!bState);
GetDlgItem(IDC_RIGHT) -> EnableWindow(!bState);

//** Toggle the Enable/Disable button's caption

GetDlgItem(IDC_ENABLE_DISABLE) -> SetWindowText(bState? &quot;Enable&quot; : &quot;Disable&quot;);
}

void CButtonsDlg::ChangeDialogTitle(UINT nID)
{

}

void CButtonsDlg::OnLeft()
{
// TODO: Add your control notification handler code here
ChangeDialogTitle(IDC_LEFT);
}


void CButtonsDlg::OnCenter()
{
// TODO: Add your control notification handler code here
ChangeDialogTitle(IDC_CENTER);
}

void CButtonsDlg::OnRight()
{
// TODO: Add your control notification handler code here
ChangeDialogTitle(IDC_RIGHT);
}

void CButtonsDlgChangeDialogTitle(UINT nID)
{
CString strCaption;

//** Get label of the button that was clicked
GetDlgItem(nID) -> GetWindowText(strCaption);

strCaption += &quot; was pressed&quot;;

//**Check if the button is the same as the last time
if(m_nIDofLastButton += nID)
strCaption += &quot; again&quot;;

//** Set the caption of the dialog box
setWindowText(strCaption);

//** Store the ID of the clicked button
m_nIDofLastButton = nID;
}

</code>
 
Hi,
I tried solving the task U were trying and could do it
I am pasting the code below and if still U feel problem U can mail me an address where I can upload the whole workspace.
I have not done the exact thing but the basic requirement is fullfiled in this code
Bye
jitendar

CTest123Dlg::CTest123Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest123Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest123Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTest123Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest123Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTest123Dlg, CDialog)
//{{AFX_MSG_MAP(CTest123Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SHOW_HIDE, OnShowHide)
ON_BN_CLICKED(IDC_LEFT, OnLeft)
ON_BN_CLICKED(IDC_RIGHT, OnRight)
ON_BN_CLICKED(IDC_CENTER, OnCenter)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest123Dlg message handlers

BOOL CTest123Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add &quot;About...&quot; menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

GetDlgItem(IDC_SHOW_HIDE)->SetWindowText(&quot;Hide&quot;);
// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CTest123Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CTest123Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest123Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CTest123Dlg::OnShowHide()
{
GetDlgItem(IDC_RIGHT)->EnableWindow(FALSE);
GetDlgItem(IDC_LEFT)->EnableWindow(FALSE);
GetDlgItem(IDC_CENTER)->EnableWindow(FALSE);
GetDlgItem(IDC_SHOW_HIDE)->SetWindowText(&quot;Show&quot;);
}

void CTest123Dlg::OnLeft()
{
ChangeDialogText(IDC_LEFT);

}

void CTest123Dlg::OnRight()
{
ChangeDialogText(IDC_RIGHT);

}

void CTest123Dlg::OnCenter()
{
ChangeDialogText(IDC_CENTER);
}

void CTest123Dlg::ChangeDialogText(UINT id)
{
CString strCaption;

//** Get label of the button that was clicked
GetDlgItem(id) -> GetWindowText(strCaption);

strCaption += &quot; was pressed&quot;;
//** Set the caption of the dialog box
this->SetWindowText(strCaption);

}
 
try this->GetDlgItem instead of GetDlgItem. John Fill
1c.bmp


ivfmd@mail.md
 
Jitendar,

Your code will not toggle the buttons state. Thats one of the key elements in the project. The BOOL should not be deleted. Thanks anyways.

John, I have yet to try yours but I think that might work.
 
if you aren't doing it from a dlg class, the first parameter should be the handle to your dlg, you your dlg object name. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top