Re: Setwindowpos()-problem.Moving control is not happening.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: WMP control resizing
    ... > getting the WMP9 activex control in a window and playing movies etc. ... when you want to resize the control in MFC, ...
    (microsoft.public.windowsmedia.sdk)
  • Re: Outlook Custom form - resize event handling
    ... Is Inspector represents the message window itself? ... hook on the form and will resize... ... I used standard Message template and added custom control on ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Distorted dialog title bar after SetWindowPos in OnInitDialog
    ... but you now say that you are using a control that takes over some of the functionality ... A CStatic is a poor choice of window for this purpose; ... report what video card you're using, what version of the driver, etc. ... SetWindowPos with SW_HIDE followed by SW_SHOW doesn't help. ...
    (microsoft.public.vc.mfc)
  • Re: Outlook Custom form - resize event handling
    ... to get its size and resize my control. ... ownership for a WordMail Inspector window. ... What I usually do is to first of all avoid custom forms unless absolutely ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: repainting own panel-component
    ... >> three seconds have passed and that the control needs to be repainted. ... the load when the window is being resized. ... When a resize operation ... stripes remains constant and they get thicker when the control grows, ...
    (comp.lang.pascal.delphi.misc)