Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I cannot use this code

C++
CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
 dialg.DoModal();
 HWND hdlg = FindWindow(NULL,_T("Dialog"));
 SetDlgItemInt(hdlg, IDC_EDIT2, 100, true);
 if(IDOK)
 {
 }
}


SetDlgItemInt function doesnot take 4 arguments and FindWindow cannot convert to HWND to CWnd*. Does anyone know how to declare SetDlgItemInt func and how to handle a dialog window? Thank You
Posted

1 solution

What is happening here is that you're trying to call the FindWindow and SetDlgItemInt APIs.
But these functions also exist as methods of the CWnd class.
Your CMyView class indirectly inherits from CWnd and so it is trying to invoke the CWnd member functions rather than the APIs.
Both versions have slightly different set of parameters.

There are 2 things that you could do to solve this issue.
You could either change the parameters to use the CWnd version.
Or simply scope the functions so that it uses the global scope (APIs come under global scope).

So you're code should look like this -
CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
 dialg.DoModal();
 HWND hdlg = ::FindWindow(NULL,_T("Dialog"));
 ::SetDlgItemInt(hdlg, IDC_EDIT2, 100, true);
 if(IDOK)
 {
 }
}
 
Share this answer
 
Comments
Kay Andrian Fikar 10-Jan-12 22:09pm    
It shows the dialog but the number cant show up..is FindWindow function will return my dialog handle? what will FindWindow return? thanks a lot
Satheesh1546 11-Jan-12 1:39am    
Yes. FindWindow() will return handle to the dialog, whose classname or window name matches. In your case it will return the handle of the window named "Dialog".
Kay Andrian Fikar 11-Jan-12 3:50am    
But as i check, it return always NULL. Ive got my window name exactly from GetWindowText() function. It results NULL as well..Failed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900