Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 04-10-2012, 01:10 PM   #1
Pooh-Bah
 
Jeff_B's Avatar
 
Join Date: Jul 2005
Location: I need Patience NOW
Posts: 3,914
Programatically Resizing Windows MFC C++



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.
Jeff_B is online now   Reply With Quote
Old 04-10-2012, 02:37 PM   #2
Carpal \'Tunnel
 
jukofyork's Avatar
 
Join Date: Sep 2004
Location: York, UK.
Posts: 10,996
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
jukofyork is online now   Reply With Quote
Old 04-10-2012, 03:45 PM   #3
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK
Posts: 9,999
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.
_dave_ is offline   Reply With Quote
Old 04-10-2012, 03:51 PM   #4
Carpal \'Tunnel
 
greg nice's Avatar
 
Join Date: Aug 2004
Location: "ban" in NVG = ban for you. AMHIK
Posts: 7,925
Re: Programatically Resizing Windows MFC C++

you could just hide the labels and boxes and only show the ones necessary depending on inValue
greg nice is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -4. The time now is 10:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright 2008-2010, Two Plus Two Interactive