views:

93

answers:

2

I recently converted a visual studio 6.0 project to visual studio 2010 and I'm encountering an issue whenever calling GetDlgItem on certain items. The following code is failing.

CWnd *pWnd = (CWnd*) GetDlgItem(IDC_BATCH);
pWnd->GetWindowText(szBatchNum);

I see this code in my resource file for the form that's calling the above code.

IDD_CC_PROCESS DIALOGEX 0, 0, 657, 410
STYLE DS_SETFONT | WS_CHILD
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL         "",IDC_BATCH,"{978C9E23-D4B0-11CE-BF2D-00AA003F40D0}",0x0,85,18,89,16
END

After the call to GetDlgItem() pWnd is NULL. This was not an issue in the 6.0 version of the project. IDC_BATCH seems to be a valid resource on this form. IDC_BATCH points to a "Microsoft Forms 2.0 Label". This seems to be one of the many issues I've encountered while converting the project from 6.0 to 2010.

A: 

Try enumerating the child items of the CWnd from which the GetDlgItem call comes from, and see if the handle even has children. Also you should check the value returned by GetLastError, this should indicate if its an actual error, and what that error is, or if the control really has no children(which then might be an error in the res file) or if the parent control even exists

Necrolis
I iterated through all the child items and it basically matched what I was seeing in Spy++. All the controls on the form were there except for the 2 "Microsoft Forms 2.0 Label" controls. Also GetLastError() did not return any errors.
Cole W
The only other thing I can think of is a mismatch of control ids, your code is pulling from one header and the res file is pulling from something else with different ids
Necrolis
+1  A: 

I don't have any particular knowledge on this issue, but I'd check if the GUID/control has been updated for the version of MFC which ships with VS2010. If the MFC version doesn't recognize the control type by GUID, it may not be able to correctly create the CWnd wrapper object for it. You may need to update the GUID for VS2010, and/or try using native Win32 calls to access it, rather than the MFC wrapper calls.

Hope that helps.

Nick
I'm not really sure how to do either of those. Do you have any information that could help me get started?
Cole W
Search MSDN for the Win32 equivalent functions for what you're trying to do, or look at the MFC source code and emulate it. That's probably the easiest way to handle it, unless you need to do some non-trivial operations on the controls which are implemented in the MFC wrapper.
Nick