Two Plus Two Poker Forums

Two Plus Two Poker Forums (https://forumserver.twoplustwo.com/)
-   Computer and Technical Help (https://forumserver.twoplustwo.com/48/computer-technical-help/)
-   -   Programatically Resizing Windows MFC C++ (https://forumserver.twoplustwo.com/48/computer-technical-help/programatically-resizing-windows-mfc-c-1191809/)

Jeff_B 04-10-2012 01:10 PM

Programatically Resizing Windows MFC C++
 
http://i39.tinypic.com/qnw6fd.jpg

I have a window like above.
Its a dialog and is called by doing
classname dlg(inValue);
dlg.DoModal();


when inValue is 1 I need to move label 3 and the text box to where label 2 is and the buttons up and make the screen smaller.


In order to this, I am writing code in the
OnInitDialog() event handler.


The problem I having is that I am using SetWindowPos and have ZERO idea of what to pass it.

From the image above, the label2 is at 67, 74 and is sized 24 x 8.

Since I want Label 3 to replace label 2, I figured a call like

Code:

GetDlgItem(IDC_LABEL3)->SetWindowPos(NULL, 67, 74, 24, 8, SWP_NOSIZE);
GetDlgItem(IDC_EDIT3)->SetWindowPos(NULL, 102, 74, 91, 14, SWP_NOSIZE);

would place the edit box 3 and label 3 correctly.

When I call it though, it does not go to the correct position.

My question is, how can I accurately determine which parameters to pass to SetWindowPos ? Or is there a better way to do this? I am also confused about the first parameter of SetWindowPos and am guessing thats where the problem lies.

I realize I can guess and adjust the parameters when I see it running but surely there must be an easier way. I need to do this for a bunch of screens so doing this would be far too time consuming.

jukofyork 04-10-2012 02:37 PM

Re: Programatically Resizing Windows MFC C++
 
Try this:

Code:

GetDlgItem(IDC_LABEL3)->SetWindowPos(NULL, 67, 74, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
GetDlgItem(IDC_EDIT3)->SetWindowPos(NULL, 102, 74, 0, 0, SWP_NOSIZE|SWP_NOZORDER);

If you are using SWP_NOSIZE then no need to use the 3rd and 4th paramters, and if you want it to ignore the 1st then you need to OR in the SWP_NOZORDER flag.

If it's still moving to the wrong position then you need to find out what it is moving relative to (eg: parent window, client area, window including border, screen/display coordinates, etc).

If you still can't figure out why it's moving to the wrong positon then there should be an MFC function to get the current coordinates (eg: like GetWindowPos() or GetWindowRect(), etc) and you can then add the offset in pixels from the value returned.

Juk :)

_dave_ 04-10-2012 03:45 PM

Re: Programatically Resizing Windows MFC C++
 
SetWindowPos documents: standard win32: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

MFC (I guess you're using this one by virtue of not having a hwnd parameter, I guess the hwnd is inferred by the opject you're invoking it through? I don't know ++/mfc!) http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

The 1st parameter (in the mfc version) is how to change the z-ordering of things, it says optional in the docs so I guess NULL is valid but it's possibly not so Juk's addition of SWP_NOZORDER flag might fix it? - fake edit: in fact, [optional] is only mentioned in the win32 docs, prob needs a valid flag and the ignore z flag to make work properly in mfc?

Quote:

When I call it though, it does not go to the correct position
It would be worth mentioning where it does move to, if at all, imo.

greg nice 04-10-2012 03:51 PM

Re: Programatically Resizing Windows MFC C++
 
you could just hide the labels and boxes and only show the ones necessary depending on inValue


All times are GMT -4. The time now is 07:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.

Copyright © 2008-2020, Two Plus Two Interactive