MoveWindow() function

Started by
3 comments, last by brechtjah 15 years, 5 months ago
I do not understand why the following code returns 1, even though I see no change on the screen:
bool test;
test = MoveWindow((HWND)ID_static1, 0, 0, 800, 800, true);
I have searched all over Google for a solution, but the topics about MoveWindow() are all different. Please assist : - ) EDIT: recompiled it and now it returns 0.
Advertisement
Quote:Original post by brechtjah
I do not understand why the following code returns 1, even though I see no change on the screen:

bool test;test = MoveWindow((HWND)ID_static1, 0, 0, 800, 800, true);
It succeeds because (HWND)ID_static1 happens to evaluate to a valid window handle, but it's not the one you want - you should always be wary of casts, if you need one it's usually a sign that something isn't expected.
In this case, you want to use the GetDlgItem() function (Assuming you have a dialog with ID_static1 as an item on it). E.g.:
test = MoveWindow(GetDlgItem(hDlg, ID_static1), 0, 0, 800, 800, true);
Where hDlg is the handle to the parent dialog box.

Quote:Original post by brechtjah
I have searched all over Google for a solution, but the topics about MoveWindow() are all different.
Please assist : - )
If in doubt, The MSDN is the most likely to be correct.
But I'm not using dialogs, it's a static control in my main window.
Quote:Original post by brechtjah
But I'm not using dialogs, it's a static control in my main window.
From the Documentation:
Quote:You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifier (as specified by the hMenu parameter in the CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window.
Or, just use the HWND from CreateWindow[Ex] directly.
bool test;
test = MoveWindow(GetDlgItem(hwnd, ID_static1), 0, 0, 800, 800, true);

That worked thanks.

This topic is closed to new replies.

Advertisement