Re: Setwindowpos()-problem.Moving control is not happening.
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 11:22:46 -0500
See below...
On 27 Nov 2005 21:39:23 -0800, "austin" <sureshmylavarapu@xxxxxxxxx> wrote:
>Hi all,
>
>
>I am facing a problem in using SetWindowPos() . I am handling a
>localization project. For this i need to resize and reposition the
>dialog controls. I am calling GetWindowRect () to get the control
>dimensions and after changing them i am trying to call SetWindowPos()
>to place the control to the changed position.
>
>
>The following is the code i am using ..
>
>RECT gControlDimension;
>HWND hCtrl;
>
>//Handle to the Dialog control
>hCtrl = GetDlgItem (hWnd, ID_CURRENT);
>
>//Get the control dimensions
>status1 = GetWindowRect (hCtrl, &gControlDimension);
>ctrlLeft = gControlDimension.left ;
>ctrlRight = gControlDimension.right;
>ctrlTop = gControlDimension.top;
>ctrlBottom = gControlDimension.bottom;
>
>ctrlWidth = ctrlRight - ctrlLeft;
>ctrlHeight = ctrlBottom - ctrlTop;
>
>/*
>
>//Here i am using the logic to change
>ctrlLeft,ctrlRight,ctrlWidth,ctrlHeight.
>//I am not adding that here as it is coming to around 20 lines.
>
>*/
>if (onlyresize)
>{
>
> SetWindowPos ( hCtrl,NULL, ctrlLeft, ctrlTop, ctrlWidth, ctrlHeight,
>SWP_NOMOVE );
>
>}
>else//both resize and move
>{
> SetWindowPos ( hCtrl,NULL, ctrlLeft, ctrlTop, ctrlWidth,
>ctrlHeight, SWP_NOZORDER);
>}
****
SetWindowPos using a control needs the coordinates in Client Coordinates of the parent.
GetWindowRect returns the Screen Coordinates of the control, and you must first do
ScreenToClient to convert them.
Also, try to avoid GetDlgItem. See my essay on Avoding GetDlgItem on my MVP Tips site.
Also, use Hungarian Notation correctly or not at all. The "g" prefix suggests a global
variable. Since it conveys no meaningful information in this context, since you appear to
be using a local variable, its presence is confusing. In HN, the correct prefix would
have been "rc" or "rect". The prefix "ctrl" suggests a control type, but in fact these
are int values. It is bad enough that HN exists at all without having people introduce
usages that are inconsistent with it (however internally consistent it might be in your
app). Better to use no prefixes at all than to use prefixes which are confusing and
misleading.
****
>
>This last check is failing for me. if onlyresize means the window is
>getting resized properly and showing me the output window which is a
>resized one properly.
>But if it needs to move ie in the else part the window is not
>showing.Why so??
****
Because of the failure to transform to client coordinates
*****
>I tried with all the flags, other than SWP_NOMOVE none
>of the other flags are showing me the window at all.I added showwindow
>after Setwindowpos in else part but still the result remains same.
>If I have to use MoveWindow() how can i use it better??
>
>pls let me know where it is going wrong.
>
>Thanks in advance
>suresh.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Prev by Date: Re: How to find Latest n files from a directory using VC++
- Next by Date: Re: How to declare a pointer to a member function of a class?
- Previous by thread: Re: Setwindowpos()-problem.Moving control is not happening.
- Next by thread: Bison(parser) should support multibyte characters
- Index(es):
Relevant Pages
|