|
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
|
|
|
|
|
boulwiss wrote:
if(pwp)SetWindowPlacement(pwp);
delete pwp;
WTF!
if (pwp)<br />
{<br />
SetWindowPlacement(pwp);<br />
delete pwp;<br />
pwp = NULL;<br />
}
-----------------------
New and improved: kwakkelflap.com
My second CP article: MAP files[^]
"Hey, Eddie, can I pour you a beer?"
"A little early, isn't it, Richy?"
"For a beer?"
"No, for stupid questions."
|
|
|
|
|
Wouter Dhondt wrote:
boulwiss wrote:
if(pwp)SetWindowPlacement(pwp);
delete pwp;
WTF!
What's your point?
What's wrong with boulwiss's code?
Cheers, Marc Click to see my *real* signature
|
|
|
|
|
Marc Richarme wrote:
What's your point?
What's wrong with boulwiss's code?
Only that you are deleting pwp if it's NULL that's all .
-----------------------
New and improved: kwakkelflap.com
My second CP article: MAP files[^]
"Hey, Eddie, can I pour you a beer?"
"A little early, isn't it, Richy?"
"For a beer?"
"No, for stupid questions."
|
|
|
|
|
Wouter Dhondt wrote:
Only that you are deleting pwp if it's NULL that's all .
Freeing a NULL pointer is legal - both with free() and delete .
K.I.S.S.
Cheers, Marc Click to see my *real* signature
|
|
|
|
|
Hmm, yeah. I'm that used to always check my pointers that I never do such things...
-----------------------
New and improved: kwakkelflap.com
My second CP article: MAP files[^]
"Hey, Eddie, can I pour you a beer?"
"A little early, isn't it, Richy?"
"For a beer?"
"No, for stupid questions."
|
|
|
|
|
It should have the delete inside the if statement:
if (pwp)
{
SetWindowPlacement(pwp);
delete pwp;
}
not outside...
|
|
|
|
|
how to use EasySize in in FormVIew?;P
|
|
|
|
|
Hey, first of all Great job!! Works good and very easy to integrate.
I have a problem when I try to minimize/maximize the Dialog.... the control items, especially buttons get displaced. Would appreciate any help.
Thanks.
|
|
|
|
|
yes! it's same to me
Oh, cOcOkO, yOu ArE mY oNe!
|
|
|
|
|
I had the same problem: I got a good resizing while resizing the window by its borders, but it didn't work properly when maximizing or minimizing: buttons dissaperared, wrong sizes... weird.
But Bob Farrel's message below gave me the answer. I quote it here:
"I learned that the ordering of the EASYSIZE() macros in the EasySize map is very important. They are executed in the order they are listed in the map, so if a control "A" is dependent on control "B", then "B" must be listed first."
I corrected the order problem, and now minimize and maximize are woking perfectly!
|
|
|
|
|
hi, it's a great job
i transfomed the code to reduce the number of lines insertd by the macro.
you can download the source here : http://3iconsulting.free.fr/easysize.zip
ALI AYACH
-- modified at 3:55 Friday 4th May, 2007
|
|
|
|
|
Look my sheet define
/////////////////////////////////
// TabCtrl init draws here
/////////////////////////////////
m_tab.AddPage( "SheetStyle",&m_templateSheetStyle,IDD_DLG_STYLE_SHEET);
m_tab.AddPage( "PageStyle", &m_templatePageStyle, IDD_DLG_STYLE_PAGE);
m_tab.AddPage( "ActionStyle", &m_templateActionStyle, IDD_DLG_STYLE_ACTION);
m_tabStyleSheet.Show();
BEGIN_EASYSIZE_MAP(CPhotoPackagerDlg)
EASYSIZE(IDD_DLG_STYLE_SHEET,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,0)
END_EASYSIZE_MAP
But there has a error .....
|
|
|
|
|
the IDD_DLG_STYLE_SHEET is not an identifier of the sheet
ALI AYACH
|
|
|
|
|
Wise sol'n, congrulats.
However, I think, there sould be one more option which will allow to give & keep a width (or height) ratio: ES_KEEPRATIO
Eg: Say you have two controls which share the width of the dialog half by half. And this 1/2 ratio wont change during sizing.
For the moment you can accomplish this via the help of an extra dummy invisible control. But not a cute trick!
|
|
|
|
|
I agree, this is the one thig that I would love to see in this solution. Otherwise it works great.
|
|
|
|
|
Hi There;
Cool-looking code. I downloaded the sample project, works fine. I put it into my own CDialog project, and get an unhandled exception as the INIT_EASYSIZE call just before the return TRUE; at the end of OnInitDialog().
After a little thought (while I was typing this), I realized that the m_hWnd which was failing belonged to an IDC_STATIC control. I changed the ID to a unique one, and EasySize worked fine.
Just thought I'd post this in case anyone else had the same problem. Thanks again for the code!
Thomas
|
|
|
|
|
Congratulations on your good work!
And I do have a question though: does your solution work on CFormViews?
Cheers!
|
|
|
|
|