HOWTO: Hide the view
rwagner -- rwagner@genre.com Thursday, December 19, 1996 Environment: Visual C++ 4.2-flat, Windows 95 I would like to hide the view in a full fledged document/view MFC OLE server app to certain users. I tried with success to override CMainFrame::PreCreateWindow with the following code, listed below. It worked for me, because setting the height of the main frame (cs.cy) to twice what ::GetSystemMetrics(SM_CYMENU) returns gives me the height of the titlebar plus the height of the menu. Not so when the user has the win 95 desktop set up with 'large fonts'. Users complain that half the menu bar is chopped off. I'm looking for a better way to do this, and on experimenting I found that various other overrides did not give me the desired effects. If I reduced the view height to zero in the view class, I would get the same sized main frame with the background of the desktop showing through where the view used to be! Any ideas out there on how to do this? -------------------- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE | WS_SYSMENU | WS_MINIMIZEBOX; cs.style&=~(LONG)FWS_ADDTOTITLE; cs.dwExStyle = WS_EX_CONTEXTHELP | WS_EX_TOPMOST; cs.cy = ::GetSystemMetrics(SM_CYMENU) * 2; cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 2; cs.y = (0); cs.x /= 2; return CFrameWnd::PreCreateWindow(cs); ------------------------- Cheers, Rob...
Joe Willcoxson -- joew@statsoft.com Friday, December 20, 1996 [Mini-digest: 3 responses] >Environment: Visual C++ 4.2-flat, Windows 95 > >I would like to hide the view in a full fledged document/view MFC OLE >server app to certain users. > >I tried with success to override CMainFrame::PreCreateWindow with the >following code, listed below. It worked for me, because setting the height >of the main frame (cs.cy) to twice what ::GetSystemMetrics(SM_CYMENU) >returns gives me the height of the titlebar plus the height of the menu. > >Not so when the user has the win 95 desktop set up with 'large fonts'. >Users complain that half the menu bar is chopped off. I'm looking for a >better way to do this, and on experimenting I found that various other >overrides did not give me the desired effects. If I reduced the view >height to zero in the view class, I would get the same sized main frame >with the background of the desktop showing through where the view used to >be! You don't say whether your app is SDI or MDI. From your example I'm assuming SDI. One way is to make it MDI and not create the frame/view combo unless necessary. If that's not desireable, you can simply do GetActiveView()->ShowWindow(SW_HIDE) or something equivalent which should hide the window, however, your message implied the desktop would show through. I think that's because frames default to having a NULL brush for their backgound. You simply need to create the main frame with a window class that has a solid brush and then the desktop won't show through when your view is not visible. You are probably using AppWizard code which calls LoadFrame which registers a WNDCLASS using AfxRegisterWndClass which defaults to a NULL background brush. Another possibility is handling the WM_ERASEBKGND message and filling the background yourself. If you step through the window creation code that MS supplies you will see what I'm talking about, and you'll learn something as well. -- Gloria in excelsius Deo Joe Willcoxson (joew@statsoft.com), Senior Software Engineer Visit us: http://www.statsoft.com, Visit me: http://users.aol.com/chinajoe #define STD_DISCLAIMER "I speak only for myself" __cplusplus spoken here; -----From: TedYou're assuming that SM_CYMENU == SM_CYCAPTION. This is not a valid assumption. For your height, use "GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION)". And heaven help you if your users change their settings after the window's been created, and you don't catch the WM_INICHANGED message and resize your window accordingly...... ---------- From: rwagner@genre.com[SMTP:rwagner@genre.com] Sent: Thursday, December 19, 1996 4:10 PM To: mfc-l@netcom.com Subject: HOWTO: Hide the view Environment: Visual C++ 4.2-flat, Windows 95 I would like to hide the view in a full fledged document/view MFC OLE server app to certain users. I tried with success to override CMainFrame::PreCreateWindow with the following code, listed below. It worked for me, because setting the height of the main frame (cs.cy) to twice what ::GetSystemMetrics(SM_CYMENU) returns gives me the height of the titlebar plus the height of the menu. Not so when the user has the win 95 desktop set up with 'large fonts'. Users complain that half the menu bar is chopped off. I'm looking for a better way to do this, and on experimenting I found that various other overrides did not give me the desired effects. If I reduced the view height to zero in the view class, I would get the same sized main frame with the background of the desktop showing through where the view used to be! Any ideas out there on how to do this? -------------------- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE | WS_SYSMENU | WS_MINIMIZEBOX; cs.style&=~(LONG)FWS_ADDTOTITLE; cs.dwExStyle = WS_EX_CONTEXTHELP | WS_EX_TOPMOST; cs.cy = ::GetSystemMetrics(SM_CYMENU) * 2; cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 2; cs.y = (0); cs.x /= 2; return CFrameWnd::PreCreateWindow(cs); ------------------------- Cheers, Rob... -----From: "Dan Kirby" Hi, I don't think you're calculations are quite right. I took a few minutes and created an AppWiz SDI application and created a menu handler for the CMainFrame that did: { int nHeight=GetSystemMetrics(SM_CYMENU)+GetSystemMetrics(SM_CYCAPTION)+GetSystem Metrics(SM_CYSIZEFRAME); CRect rect; GetWindowRect(&rect); SetWindowPos(&wndTopMost, rect.left, rect.top, rect.Width(), nHeight, 0); } And this appeared to work fine. Notice that I used different constants for GetSystemMetrics(). --dan ---------- > From: rwagner@genre.com > To: mfc-l@netcom.com > Subject: HOWTO: Hide the view > Date: Thursday, December 19, 1996 4:09 PM > > > > > > Environment: Visual C++ 4.2-flat, Windows 95 > > I would like to hide the view in a full fledged document/view MFC OLE > server app to certain users. > > I tried with success to override CMainFrame::PreCreateWindow with the > following code, listed below. It worked for me, because setting the height > of the main frame (cs.cy) to twice what ::GetSystemMetrics(SM_CYMENU) > returns gives me the height of the titlebar plus the height of the menu. > > Not so when the user has the win 95 desktop set up with 'large fonts'. > Users complain that half the menu bar is chopped off. I'm looking for a > better way to do this, and on experimenting I found that various other > overrides did not give me the desired effects. If I reduced the view > height to zero in the view class, I would get the same sized main frame > with the background of the desktop showing through where the view used to > be! > > Any ideas out there on how to do this? > -------------------- > cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE > | WS_SYSMENU | WS_MINIMIZEBOX; > cs.style&=~(LONG)FWS_ADDTOTITLE; > cs.dwExStyle = WS_EX_CONTEXTHELP | WS_EX_TOPMOST; > cs.cy = ::GetSystemMetrics(SM_CYMENU) * 2; > cs.cx = ::GetSystemMetrics(SM_CXSCREEN) / 2; > cs.y = (0); > cs.x /= 2; > return CFrameWnd::PreCreateWindow(cs); > ------------------------- > > Cheers, > Rob... > >
| Вернуться в корень Архива |