|
Prev: Calculation mystery
Next: Help: Floating Point PRoblem
From: Geo on 17 May 2008 20:02 Hello, I am using Visual Studio 6.0 and I'd like to know how can I block the resizing of a dialog's width when it reaches a certain minimum? I am currently using the CMyDlg::OnSize() message handler to do the following: void CMyDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); CRect rect; GetWindowRect(&rect); if (rect.Width() < 300) { rect.right = rect.left + 300; MoveWindow(&rect, TRUE); } } This works but it is really ugly because say I drag the dialog's right edge to the left, when the width becomes less than the minimum (300) the dialog keeps drawing the right edge at the mouse position then updates it to have a width of 300. How can I fix this to make it behave like the Notepad window for example. If you open Notepad than try to drag its window's right edge all the way, you'll notice that at a ceratin point it will block. This is exactly what I want to achieve. I really appreciate any help for this. Thanks, Geo
From: King Menelaus on 17 May 2008 20:14 Add a handler for WM_GETMINMAXINFO -- for example, void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { CFrameWnd::OnGetMinMaxInfo(lpMMI); lpMMI->ptMinTrackSize.x = 800; lpMMI->ptMinTrackSize.y = 600; } -JJ Geo wrote: > Hello, > > I am using Visual Studio 6.0 and I'd like to know how can I block the > resizing of > a dialog's width when it reaches a certain minimum? > > I am currently using the CMyDlg::OnSize() message handler to do the following: > > void CMyDlg::OnSize(UINT nType, int cx, int cy) > { > CDialog::OnSize(nType, cx, cy); > > CRect rect; > GetWindowRect(&rect); > if (rect.Width() < 300) > { > rect.right = rect.left + 300; > MoveWindow(&rect, TRUE); > } > } > > > This works but it is really ugly because say I drag the dialog's right edge > to the > left, when the width becomes less than the minimum (300) the dialog keeps > drawing the right edge at the mouse position then updates it to have a width > of 300. > > How can I fix this to make it behave like the Notepad window for example. If > you > open Notepad than try to drag its window's right edge all the way, you'll > notice > that at a ceratin point it will block. This is exactly what I want to achieve. > > I really appreciate any help for this. > > Thanks, > > Geo
From: Joseph M. Newcomer on 17 May 2008 22:53 Just one glitch: in VS6, you have to add the message map, declaration, and implementation "by hand" because the wizard is under the delusion that this is not a message a dialog should get. They fixed this obvious stupidity in VS.NET and beyond, even though they didn't fix any of the other dozen or so problems (such as not all messages are shown, reflected message handlers are not shown, etc.) What I do is not limit it to a specific size (which is always a bad idea, because dialogs don't have fixed sizes; any random integer chosen and hardwired means the correct thing will happen only on your machine, with your monitor, your display card, with the current version of the display driver, and with today's settings such as screen resolution, default font, and orbital position of Jupiter with respect to Mars), but instead I create a picture (CStatic) rectangle, set its Visible attribute to false, change its ID to something other than IDC_STATIC (such as IDC_FRAME), create a control variable for it (e.g., c_Frame), and then do soemthing of the following: void CColorPickupDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { // Limits the size to the frame if(c_Frame.GetSafeHwnd() != NULL) { /* has frame */ CRect r; c_Frame.GetWindowRect(&r); ScreenToClient(&r); CalcWindowRect(&r); lpMMI->ptMinTrackSize.x = r.Width(); lpMMI->ptMinTrackSize.y = r.Height(); } /* has frame */ else CDialog::OnGetMinMaxInfo(lpMMI); } when the resize hits the rectangle I drew, it stops. If I want to change the size (such as I've changed the control layouts, or sizes of controls, or added a control), I just resize the invisible IDC_FRAME window, and my resizing will now obey that; no need to change the code at all. joe On Sat, 17 May 2008 17:14:40 -0700, King Menelaus <menelaus(a)nowhere.fake> wrote: >Add a handler for WM_GETMINMAXINFO -- for example, > >void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) >{ > CFrameWnd::OnGetMinMaxInfo(lpMMI); > > lpMMI->ptMinTrackSize.x = 800; > lpMMI->ptMinTrackSize.y = 600; >} > >-JJ > >Geo wrote: >> Hello, >> >> I am using Visual Studio 6.0 and I'd like to know how can I block the >> resizing of >> a dialog's width when it reaches a certain minimum? >> >> I am currently using the CMyDlg::OnSize() message handler to do the following: >> >> void CMyDlg::OnSize(UINT nType, int cx, int cy) >> { >> CDialog::OnSize(nType, cx, cy); >> >> CRect rect; >> GetWindowRect(&rect); >> if (rect.Width() < 300) >> { >> rect.right = rect.left + 300; >> MoveWindow(&rect, TRUE); >> } >> } >> >> >> This works but it is really ugly because say I drag the dialog's right edge >> to the >> left, when the width becomes less than the minimum (300) the dialog keeps >> drawing the right edge at the mouse position then updates it to have a width >> of 300. >> >> How can I fix this to make it behave like the Notepad window for example. If >> you >> open Notepad than try to drag its window's right edge all the way, you'll >> notice >> that at a ceratin point it will block. This is exactly what I want to achieve. >> >> I really appreciate any help for this. >> >> Thanks, >> >> Geo Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Geo on 18 May 2008 18:19 King Menelaus and Dr. Newcomer, Thank you so much for your valuable help and Dr., as usual for your detailed and generous explanation. Geo
|
Pages: 1 Prev: Calculation mystery Next: Help: Floating Point PRoblem |