|
Does EasySize work on FormViews?
I've used it in a dialog, and it works perfectly.
I'm trying now to use it in a FormView, and something just doesn't work when I declare the EASYSIZE macro for the controls.
Any ideas?
|
|
|
|
|
It works for me in the formview, but the form doesn't repaint itself correctly. Any controls that I put in the EASYSIZE map show up, but the form itself doesn't. Let me know if you come up with anything
[insert witty comment here]
bdiamond
|
|
|
|
|
the reply of AliRafiee had refered a solution,his idea is great!!!
|
|
|
|
|
Any ideea how to hide some controls after defining them to "easysize"?
I have a big PictureControl that resizes width and height, and some buttons under it. I wanna use MoveWindow() of course to hide the blank spot when i hide the buttons, but the big PicControl now resizes to keep the distance from the bottom, natural. So ... how do i hide some items, w/o leaving a empty space there ?
|
|
|
|
|
EASYSIZE seems to work with all dialogs i have tried it on with the exception of the "Sample Text" control in a dialog derived from CFontDialog. (This control ID is defined in FONT.DLG as stc5).
Any idea why CFontDialog behaves in this peculiar way??
gjr
|
|
|
|
|
Hi Marc.R,
I think your article and your code is great. Its very useful and very easy to use (ie the name of the article). I've had several instances when I needed to be able to resize controls in proportion to the size of the dialog. For example, if I have 2 list controls next to each other or equal dimension and I resize the dialog, I needed them to become larger but still be the same size as each other.
With that, I started to try to understand your code. After some trial'n'error during the learning process, I finally added another option to the resizing. Initially I called it ES_KEEPPROPORTION, but I then saw some messages on here, and ES_KEEPRATIO seemed more logical.
I don't know how to message you directly, so I'll add a link here and if you wish, you may modify your own code or not. I thought it may be useful to some of the other readers.
EasySize with ES_KEEPRATIO
I've tested it as much as I could. Good luck in using it, and I hope it comes in handy.
Jubjub
|
|
|
|
|
Just the same as Marc has set out the other resizing types :
BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)
EASYSIZE(IDC_TITLE,ES_BORDER,ES_BORDER,ES_KEEPRATIO,ES_KEEPRATIO,0)
END_EASYSIZE_MAP
The above willl set the left side of IDC_TITLE to its current position in relation to the left border of the dialog. But the right side of IDC_TITLE will change. The width of IDC_TITLE will resize in accordance to it ratio of size to the dialog.
eg.
Width of the Dialog is 100;
Width of the IDC_TITLE 20;
Rect of IDC_TITLE CRect (0, 0, 20, 30)
Now if you resize the dialog and make it twice as wide, the new rect will be
Rect of IDC_TITLE CRect (0, 0, 40, 30)
The width of IDC_TITLE will be twice that it was before. The same goes for the height, if you resize the height. If you resize the control by 20%. Then the width and height of IDC_TITLE will increase by 20%.
If you want the left size to move in a resize, then :
BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)
EASYSIZE(IDC_TITLE,ES_KEEPRATIO,ES_BORDER,ES_BORDER,ES_KEEPRATIO,0)
END_EASYSIZE_MAP
In this case, on resizing, the right side of IDC_TITLE will stay the same distance from the right of the dialog, and the left size will resize, keeping the ratio correct.
If on the other hand, you have 2 controls next to each other, IDC_TITLE and IDC_LOGO.
Rect of IDC_TITLE CRect (0,0,20,30) // width of 20
Rect of IDC_LOGO CRect (20,0,30,30) // width of 10
********* ********
* title * * logo *
********* ********
BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)
EASYSIZE(IDC_TITLE,ES_BORDER,ES_BORDER,ES_KEEPRATIO,ES_KEEPRATIO,0)
EASYSIZE(IDC_LOGO,IDC_TITLE,ES_BORDER,ES_KEEPRATIO,ES_KEEPRATIO,0)
END_EASYSIZE_MAP
The above code will do the following. IDC_TITLE will resize and keep its size in proportion to the dialog. IDC_LOGO's left side will move relative to the right side of IDC_TITLE. IDC_LOGO will then resize itself in proportion to the dialog, after its left side moves.
eg.
the dialogs width is resized (twice the width now).
the new sizes of the controls will be :
ORIGINAL
Rect of IDC_TITLE CRect (0,0,20,30) // width of 20
Rect of IDC_LOGO CRect (20,0,30,30) // width of 10
NEW
Rect of IDC_TITLE CRect (0,0,40,30) // width of 40 (doubled)
Rect of IDC_LOGO CRect (40,0,60,30) // width of 20 (doubled)
Hope this helps
If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson
|
|
|
|
|
hi . thanks you code
if I have 4 control ,
like this ,this 4 control is same size .
|----------------------|
| #### #### #### #### |
|----------------------|
when i resize the dialog horizontally .
can i use ES_KEEPRATIO to keep the 4 control all has equal size?
thanks
|
|
|
|
|
hello,your link is not available,can you provide a new one?
|
|
|
|
|
I cannot access this link. Is your code still available?
|
|
|
|
|
I'm afraid I've moved OS and don't have access to that anymore.
"If you're too careful, your whole life can become a f---in' grind." - Mike McD ( Rounders)
|
|
|
|
|
Very intuitive interface.
None
|
|
|
|
|
Is this message handler a VC7 thing? If so, can I get the same functionality from something in VC6?
|
|
|
|
|
nevermind - figured it out. For those who wish to know, to get access to a larger pool of message handlers, change the message filter in the class info pane of the classwizard to "Window" (or something higher up the inheritance tree).
|
|
|
|
|
|
I dug around for a while looking for an easy way to do this, and yours definitely lives up to the name. Cool code. Thanks!
|
|
|
|
|
|
would you please show me a resizer dialog with only one CEdit control directly without class.I wanna know how to resize and move a control in dialog .thanks !
|
|
|
|
|
I liked the idea of what you did, and it does work quite well. However, the code looked really ugly, missing linebreaks and all, so I went over it a little, introduced a couple of sub-macros etc. This does not add any extra functionality, but might make future extension/bugfixing easier, and should be interesting for anyone who wants to know what their program actually does.
The code is available for download here: ftp://ftp.pyogenesis.net/pub/fknauf/c++/EasySize.h
|
|
|
|
|
This is worth!!!!!!!!!!!
suggested fixes: (this will avoid flashing of the screen and sizing will occur accurately and initialization sequence will allow to create the dialog box dynamically)
static bool bEasyUpdate = false;
#define INIT_EASYSIZE\
Invalidate()\
bEasyUpdate = false;\
__ES__RepositionControls(TRUE);\
__ES__RepositionControls(FALSE)
#define UPDATE_EASYSIZE\
if (bEasyUpdate) \
return;\
bEasyUpdate = true;\
if(GetWindow(GW_CHILD)!=NULL)\
__ES__RepositionControls(FALSE);\
bEasyUpdate = false;
#define END_EASYSIZE_MAP\
Invalidate ();\
}
|
|
|
|
|
Hi Sadru,
I dont' understand because to me this will not avoid flashing of the screen.
Look my code
#ifndef __EASYSIZE_H_
#define __EASYSIZE_H_
#define ES_BORDER 0xffffffff
#define ES_KEEPSIZE 0xfffffffe
#define ES_HCENTER 0x00000001
#define ES_VCENTER 0x00000002
#define DECLARE_EASYSIZE \
void __ES__RepositionControls(BOOL bInit);\
void __ES__CalcBottomRight(CWnd *pThis, BOOL bBottom, int &bottomright, int &topleft, UINT id, UINT br, int es_br, CRect &rect, int clientbottomright);
static bool bEasyUpdate = false;
#define INIT_EASYSIZE \
Invalidate();\
bEasyUpdate = false;\
__ES__RepositionControls(TRUE);\
__ES__RepositionControls(FALSE)
#define UPDATE_EASYSIZE \
if (bEasyUpdate) \
return;\
bEasyUpdate = true;\
if(GetWindow(GW_CHILD)!=NULL)\
__ES__RepositionControls(FALSE);\
bEasyUpdate = false;
#define EASYSIZE_MINSIZE(mx,my,s,r) if(r->right-r->left < mx) { if((s == WMSZ_BOTTOMLEFT)||(s == WMSZ_LEFT)||(s == WMSZ_TOPLEFT)) r->left = r->right-mx; else r->right = r->left+mx; } if(r->bottom-r->top < my) { if((s == WMSZ_TOP)||(s == WMSZ_TOPLEFT)||(s == WMSZ_TOPRIGHT)) r->top = r->bottom-my; else r->bottom = r->top+my; }
#define BEGIN_EASYSIZE_MAP(class) \
void class::__ES__CalcBottomRight(CWnd *pThis, BOOL bBottom, int &bottomright, int &topleft, UINT id, UINT br, int es_br, CRect &rect, int clientbottomright) {\
if(br==ES_BORDER) bottomright = clientbottomright-es_br;\
else if(br==ES_KEEPSIZE) bottomright = topleft+es_br;\
else { CRect rect2;\
pThis->GetDlgItem(br)->GetWindowRect(rect2); pThis->ScreenToClient(rect2);\
bottomright = (bBottom?rect2.top:rect2.left) - es_br;}}\
void class::__ES__RepositionControls(BOOL bInit) { CRect rect,rect2,client; GetClientRect(client);
#define END_EASYSIZE_MAP \
Invalidate ();\
}
#define EASYSIZE(id,l,t,r,b,o) \
static int id##_es_l, id##_es_t, id##_es_r, id##_es_b;\
if(bInit) {\
GetDlgItem(id)->GetWindowRect(rect); ScreenToClient(rect);\
if(o & ES_HCENTER) id##_es_l = rect.Width()/2; else {\
if(l==ES_BORDER) id##_es_l = rect.left; else if(l==ES_KEEPSIZE) id##_es_l = rect.Width(); else {\
GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_l = rect.left-rect2.right;}}\
if(o & ES_VCENTER) id##_es_t = rect.Height()/2; else {\
if(t==ES_BORDER) id##_es_t = rect.top; else if(t==ES_KEEPSIZE) id##_es_t = rect.Height(); else {\
GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_t = rect.top-rect2.bottom;}}\
if(o & ES_HCENTER) id##_es_r = rect.Width(); else { if(r==ES_BORDER) id##_es_r = client.right-rect.right; else if(r==ES_KEEPSIZE) id##_es_r = rect.Width(); else {\
GetDlgItem(r)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_r = rect2.left-rect.right;}}\
if(o & ES_VCENTER) id##_es_b = rect.Height(); else { if(b==ES_BORDER) id##_es_b = client.bottom-rect.bottom; else if(b==ES_KEEPSIZE) id##_es_b = rect.Height(); else {\
GetDlgItem(b)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_b = rect2.top-rect.bottom;}}\
} else {\
int left,top,right,bottom; BOOL bR = FALSE,bB = FALSE;\
if(o & ES_HCENTER) { int _a,_b;\
if(l==ES_BORDER) _a = client.left; else { GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2); _a = rect2.right; }\
if(r==ES_BORDER) _b = client.right; else { GetDlgItem(r)->GetWindowRect(rect2); ScreenToClient(rect2); _b = rect2.left; }\
left = _a+((_b-_a)/2-id##_es_l); right = left + id##_es_r;} else {\
if(l==ES_BORDER) left = id##_es_l;\
else if(l==ES_KEEPSIZE) { __ES__CalcBottomRight(this,FALSE,right,left,id,r,id##_es_r,rect,client.right); left = right-id##_es_l;\
} else { GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2); left = rect2.right + id##_es_l; }\
if(l != ES_KEEPSIZE) __ES__CalcBottomRight(this,FALSE,right,left,id,r,id##_es_r,rect,client.right);}\
if(o & ES_VCENTER) { int _a,_b;\
if(t==ES_BORDER) _a = client.top; else { GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2); _a = rect2.bottom; }\
if(b==ES_BORDER) _b = client.bottom; else { GetDlgItem(b)->GetWindowRect(rect2); ScreenToClient(rect2); _b = rect2.top; }\
top = _a+((_b-_a)/2-id##_es_t); bottom = top + id##_es_b;} else {\
if(t==ES_BORDER) top = id##_es_t;\
else if(t==ES_KEEPSIZE) { __ES__CalcBottomRight(this,TRUE,bottom,top,id,b,id##_es_b,rect,client.bottom); top = bottom-id##_es_t;\
} else { GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2); top = rect2.bottom + id##_es_t; }\
if(t != ES_KEEPSIZE) __ES__CalcBottomRight(this,TRUE,bottom,top,id,b,id##_es_b,rect,client.bottom);}\
GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,FALSE);\
}
#endif //__EASYSIZE_H
|
|
|
|
|
Have you solved the flashing problem?
|
|
|
|
|
Hi,
I'm sittign on this problems for several hours now and I'm not able to resize 5 Editboxes over a Dialog. Could you write a solution for this problem?
|
|
|
|
|
great!
can we save the new size and positions of dialog and controls in registry?
if i open twice , i want get the new sized dialog....
|
|
|
|
|
Hi,
you can do that :
void CMyDlg::OnDestroy()
{
CDialog::OnDestroy();
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
AfxGetApp()->WriteProfileBinary("Settings","WindowPos",(LPBYTE)&wp,sizeof(wp));
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
LPBYTE lpData;
UINT nSize = 0;
AfxGetApp()->GetProfileBinary("Settings","WindowPos",&lpData,&nSize);
LPWINDOWPLACEMENT pwp = (LPWINDOWPLACEMENT)lpData;
if(pwp)SetWindowPlacement(pwp);
delete pwp;
return TRUE;
}
good luck
ALI
|
|
|
|
|