Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I migrate a C++/MFC 2005 project to VS2010 and there is a class with this call:

C++
CWnd::Create((LPCSTR)wndstr, "GridClass", dwStyle, grid_rect, pParentWnd, /*nID*/NULL, NULL);

/* .... */

int nID( ::GetDlgCtrlID( this->m_hWnd ) );


There are expect (VS2005) that nID is 0, but in VS2010 the GetDlgCtrlID-call returns a non null value. Does anyone know something about this? Is there a known way to create an object from a CWnd-based class with a null-value CtrlID?
Posted
Comments
Sergey Alexandrovich Kryukov 17-Oct-11 12:49pm    
Why 0?
--SA
Member 8261538 18-Oct-11 3:44am    
I hope my comment for Solution 2 clears that point.

Excuse me, who told you it should be NULL?

First at the code sample for this API:
http://msdn.microsoft.com/en-us/library/0yhc9kx4%28v=VS.100%29.aspx[^].

The meaning of ID is explained here:
http://www.codeguru.com/forum/showthread.php?t=344170[^].

—SA
 
Share this answer
 
Comments
Member 8261538 17-Oct-11 13:17pm    
Thank you for answering. The point is when I debug my application under VS2005 the return value from ::GetDlgCtrlID( this->m_hWnd ) is NULL. There are many places in the code where expected that the CtrlID from some special dynamic created Ctrls is null. The meaning of ID is familiar to me.
According to the documentation[^] on MSDN a return value of zero indicates an error.
 
Share this answer
 
Comments
Member 8261538 18-Oct-11 3:36am    
Thanks, but why i get an error (return 0) when i compile the application with VS2005 and with VS2010 the needed error is missing? (new mfc - i know) Is there a way to create this CWnd Object with an error CtrlID?

::GetDlgCtrlID(HWND) returns for the created CWnd-object an ctrlid like '35396' and when is try to use it ( in a loop with ::GetNextWindow() ) the application crashes.

I know this is not the best way to provide the use of this cwnd-objects but this is realy old historically grown code and there are many playces where i need that error for this controls.
Richard MacCutchan 18-Oct-11 5:05am    
1. No idea why you get an error, but some testing with your debugger should help. Also always check return values from API calls and use GetLastError() function to help diagnose why it failed.

2. Again if the application is crashing then you need to trace through the code to determine what your application is doing wrong.

3. I am not sure what you mean by the last sentence as you do not explain what your program is trying to do.

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