Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

163 views
Skip to first unread message

austin

unread,
Nov 28, 2005, 12:39:23 AM11/28/05
to
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);
}

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?? 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.

Scott McPhillips [MVP]

unread,
Nov 28, 2005, 3:48:44 AM11/28/05
to


Your ctrlLeft and ctrlTop variables probably move the control outside of
the dialog dimensions. Check their values. (These variables are not
used in the SWP_NOMOVE case.)

It looks like you have not adjusted the control rectangle coordinates
with ScreenToClient().

--
Scott McPhillips [VC++ MVP]

Joseph M. Newcomer

unread,
Nov 29, 2005, 11:22:46 AM11/29/05
to
See below...

****
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: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

austin

unread,
Dec 2, 2005, 12:10:34 AM12/2/05
to
hi all,

Thanks for all your suggestions. yes, once i converted the window
co-cordinates to that of the client area coordinates, it is doing well.
By the way my project is not using MFC support, so I am going with
GetDlgItem (). Thanks again..

Friends I have another query.
How can we change the title of an AfxMessageBox, as it always takes the
caption alone as input .I cant find the place where to change it's
title.

thanks & regards,
Suresh

Message has been deleted

Aman Anand

unread,
Dec 27, 2022, 2:00:35 AM12/27/22
to
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
SetWindowTextW(_T("Name of The header ")); //To write the header name of the dialog
}
0 new messages