Are all my windows orphans? GetParent() failure

Started by
9 comments, last by MattS423 19 years, 10 months ago
OK, so the user is supposed to click a button, and a dialog box pops up.They then enter a number in an edit box, and then I take that number, do a search on it, and select a peice of data in a list box the parent of this pop-up box. Here's some code to try to explain this:

case IDC_BUTTON_FIND:
		
    Ret = DialogBox(hInst,MAKEINTRESOURCEIDD_DIALOG_FIND),
                    hwndDlg,FindDialogProc);

break;
That makes the dialog box pop up quite nicely. Now for the Dialog procedure. You click the OK button (IDOK) and it grabs the number from the Edit box (IDC_EDIT_IDCODE) and does some stuff with it, then selects a specific player in a list box. Source Code:

// Parent is an HWND

case IDOK:
			
			Parent = GetParent(hwndFindDlg); //FAILS!

//The debugger tells me that at this point, Parent == NULL

			IDCode = GetDlgItemInt(hwndFindDlg,IDC_EDIT_IDCODE,NULL,TRUE);
            if(!FindPlayer(IDCode,FoundPlayerIndex))
			{
				EndDialog(hwndFindDlg,1);
				SetFocus(Parent);
				break;
			}
			
			PlayerListBox = GetDlgItem(Parent,IDC_LIST_PLAYERS);
			Sel = SendMessage(PlayerListBox,LB_SELECTSTRING,-1,
				(LPARAM)Players[FoundPlayerIndex].Name);

			SendMessage(PlayerListBox,LB_SETCURSEL,Sel,0);

			EndDialog(hwndFindDlg,1);
			SetFocus(Parent);
			
			

			break;

This is all well and good, except for one little thing....GetParent() ALWAYS fails. After I call it, Parent == NULL. Because of this, I can't do anything with that list box...because i cant do a GetDlgItem() without the parent window handle. Is there any reason for this? Why doesn't it work? Help? Thanks alot --Matt [edited by - MattS423 on June 2, 2004 10:11:49 PM]
Programmers of the world, UNTIE!
Advertisement
By the way, GetLastError() returns 0 when called immediately after the GetParent() function.
Programmers of the world, UNTIE!
What is the value of hwndFindDlg?
hWndFindDlg was declared in the dialog porcedure prototype...like so
INT_PTR CALLBACK FindDialogProc( HWND hwndFindDlg, UINT uMsg,				WPARAM wParam, LPARAM lParam) 


The debugger says that hWndFindDlg = 0x00260654
All i make of that is that it''s not NULL.

i''m pretty sure it''s valid.
Programmers of the world, UNTIE!
Presumably, hwndDlg is also a parameter, but...
If hwndDlg is NULL when you call CreateDialog, then the parent would be NULL as well. It wouldn''t hurt to check it. Just throwing out suggestions.
At the point of calling the DialogBox() function, hwndDlg was NOT equal to NULL.

Also, DialogBox() returns 1.

Any other ideas?

[edited by - MattS423 on June 2, 2004 10:16:25 PM]
Programmers of the world, UNTIE!
Also, when i call MessageBox() from that dialog porcedure, I can''t seem to set the focus on the message box....probably a related issue.
Programmers of the world, UNTIE!
So am i just dealing with the Windows of Penzance here?
Programmers of the world, UNTIE!
quote:Original post by MattS423
So am i just dealing with the Windows of Penzance here?


So, are you suggesting that your windows have been ''piloted''?

Sorry, but I''m pretty much out of ideas.
Have you tried GetOwner ()? (Or something in that direction)

[edit: which doesn't exist in C++. ]


--
You're Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net's DirectX FAQ. (not as cool as the Graphics and Theory FAQ)

[edited by - Pipo DeClown on June 4, 2004 4:25:33 PM]

This topic is closed to new replies.

Advertisement