Sign in to follow this  
brechtjah

MoveWindow() function

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this