SetWindowPos API - Backward resizing?

441 views Asked by At

I'm using Windows's SetWindowPos API to try to 'crop' a part of a window so a user will only be able to see the RIGHT part of it.

Problem is, I can only 'crop' it, starting from the top left corner, and I would rather cropping a different part of the window which does not 'contain' the top left part.

As seen on the image below, what i'm trying to do is reverse the 'resizing' mechanism in such way that the window will 'hide' the Label1, and only show the Button1.

It is possible that I am not using the correct API for the job, If so, i'd love to be pointed toward the right one.

enter image description here

2

There are 2 answers

0
David Heffernan On

If you have a window handle for the control, then you can place it outside its parent. Pass to SetWindowPos a negative value for the X coordinate.

Of course, the fact that the control cannot be seen does not mean it cannot be interacted with. The user can reach it with the keyboard if it accepts focus. So perhaps a better idea would be to hide and/or disable it. Use ShowWindow and EnableWindow to do that.

Then again, it's quite plausible that you won't be able to get a window handle. Many frameworks use controls that are not windowed. To interact with them you would need to use an automation framework such as UI Automation. Only you can know whether or not the target application supports automation.

1
Joey On

You need to move your controls on the Form for that to work. The window has a position and a size, which is all the window manager cares about. What is visible inside is your application's responsibility.

Your screenshot looks very VB6-ish. Do note that newer technologies, e.g. Windows Forms or WPF offer better support for what you are trying to do here.