Maximizing MainFrame

Hi everyone,

I use VC++ 6.0. I have an MDI application that I want to be able to
dynamiaclly maximize
in such a way that user would not be able to get to the desktop. My goals
are:
1. MainFrame should be maximized.
2. Minimize and Restore buttons should be either greyed out or removed.
3. User should not be able to move the application window.
4. The [x] close button in the top right corner should be visible.

I have to use SetWindowLong() as oppose to Create() because this all has to
happen
dynamically many times in application's lifetime. My goal 1 ("maximized" is
easy to achieve).
Once my window is maximized goals 2 and 3 become mutually exclusive. I can
easily remove
Minimize and Restore buttons. Here's the code I use:

extern CMainFrame* pMF;
// get window handle
HWND hMF = pMF->GetSafeHWND();

// remove Minimize and Restore buttons
LONG nWindowLong = GetWindowLong(hMF, GWL_STYLE);
nWindowLong &= ~WS_MINIMIZEBOX;
nWindowLong &= ~WS_MAXIMIZEBOX;
SetWindowHandle(hMF, GWL_STYLE, nWindowLong);

// maximize it
pMF->ShowWindow(SW_SHOWMAXIMIZED);

After this code my window is maximized and it has only one [x] close button.
The problem is that
it can be dragged away. On the other hand if I comment out the line with
WS_MAXIMIZEBOX
my window is no longer movable (as I want) but it has the Restore button (as
I don't want).
I found that setting WS_EX_DLGMODALFRAME or WS_EX_TOPMOST bits in
nWindowLong
gets me pretty close to the desired behavior only this time the whole top of
the window
(blue header with Window caption and [x] Close button) is missing. The first
thing I see on top of the
screen is MainFrame Menu.
Is there a way to achive what I want?

Thanks a lot in advance for your help.

Ilya.


0
i.burda (1)
10/15/2004 2:17:32 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
636 Views

Similar Articles

[PageSpeed] 54

> Hi everyone,
>
> I use VC++ 6.0. I have an MDI application that I want to be able to
> dynamiaclly maximize
> in such a way that user would not be able to get to the desktop. My goals
> are:

You cannot stop the user from doing that.

> 1. MainFrame should be maximized.

have a look at
cs.style = cs.style | WS_MAXIMIZE;

in your "PreCreateWindow".

> 2. Minimize and Restore buttons should be either greyed out or removed.

as above, just do it before your window is created, (for looks).

> 3. User should not be able to move the application window.

cannot be done, trust me you can make it harder but you cannot really do it.

> 4. The [x] close button in the top right corner should be visible.

Alt-f4 would still work.

>
> I have to use SetWindowLong() as oppose to Create() because this all has 
> to
> happen
> dynamically many times in application's lifetime. My goal 1 ("maximized" 
> is
> easy to achieve).
> Once my window is maximized goals 2 and 3 become mutually exclusive. I can
> easily remove
> Minimize and Restore buttons. Here's the code I use:

Just call it when ever you want.

>
> Thanks a lot in advance for your help.
>
> Ilya.
>

I thnink you are trying to design a spyware/spam application. As i cannot 
see any reason why you are trying to, (forcefuly), stop the user frm 
closing/chaning their view.

-- 
http://www.myoddweb.com
http://www.myoddweb.com/forum 


0
10/15/2004 10:12:30 AM
Hi,

I have flags in my main frame for enabling minimize, close and non maximized (normal) and I handle the logic in
OnSysCommand() like this:

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) 
// System menu commands that can be disabled are handled here. (SC_CLOSE, SC_RESTORE, SC_MINIMIZE).
// Note that it isn't enough to disable or remove the SC_CLOSE command since a WM_SYSCOMMAND is still
// sent for Alt+F4.
{
	switch (nID & 0xfff0){
	case SC_MINIMIZE:
		if (!m_bAllowMinimize)
			return;
		break;
	case SC_RESTORE:
		if (!m_bAllowNonMaximized)
			return;
		break;
	case SC_CLOSE:
		if (!m_bAllowClose)
			return;
		break;
	}
	
	CFrameWnd::OnSysCommand(nID, lParam);
}

This way Alt+F4 and doubleclicking on the window bar (for maximize/normal) also is disabled.

I use this to enable/disable (gray) the close button:

void CMainFrame::InitCloseButton(void)
{
	CMenu *sysmenu=GetSystemMenu(FALSE);
	sysmenu->EnableMenuItem(SC_CLOSE,
		m_bAllowClose? (MF_BYCOMMAND | MF_ENABLED):(MF_BYCOMMAND | MF_GRAYED));
}

This doesn't disable or remove the maximize/normal and minimize buttons. I didn't care about that. Perhaps you can
disable dragging in OnSysCommand() (SC_MOVE) after you have maximized the window and removed the buttons. I havn't tried
that.

/Ruben


On Fri, 15 Oct 2004 02:17:32 GMT, "Ilya Burda" <i.burda@verizon.net> wrote:

>Hi everyone,
>
>I use VC++ 6.0. I have an MDI application that I want to be able to
>dynamiaclly maximize
>in such a way that user would not be able to get to the desktop. My goals
>are:
>1. MainFrame should be maximized.
>2. Minimize and Restore buttons should be either greyed out or removed.
>3. User should not be able to move the application window.
>4. The [x] close button in the top right corner should be visible.
>
>I have to use SetWindowLong() as oppose to Create() because this all has to
>happen
>dynamically many times in application's lifetime. My goal 1 ("maximized" is
>easy to achieve).
>Once my window is maximized goals 2 and 3 become mutually exclusive. I can
>easily remove
>Minimize and Restore buttons. Here's the code I use:
>
>extern CMainFrame* pMF;
>// get window handle
>HWND hMF = pMF->GetSafeHWND();
>
>// remove Minimize and Restore buttons
>LONG nWindowLong = GetWindowLong(hMF, GWL_STYLE);
>nWindowLong &= ~WS_MINIMIZEBOX;
>nWindowLong &= ~WS_MAXIMIZEBOX;
>SetWindowHandle(hMF, GWL_STYLE, nWindowLong);
>
>// maximize it
>pMF->ShowWindow(SW_SHOWMAXIMIZED);
>
>After this code my window is maximized and it has only one [x] close button.
>The problem is that
>it can be dragged away. On the other hand if I comment out the line with
>WS_MAXIMIZEBOX
>my window is no longer movable (as I want) but it has the Restore button (as
>I don't want).
>I found that setting WS_EX_DLGMODALFRAME or WS_EX_TOPMOST bits in
>nWindowLong
>gets me pretty close to the desired behavior only this time the whole top of
>the window
>(blue header with Window caption and [x] Close button) is missing. The first
>thing I see on top of the
>screen is MainFrame Menu.
>Is there a way to achive what I want?
>
>Thanks a lot in advance for your help.
>
>Ilya.
>

0
ruben1 (50)
10/15/2004 10:50:50 AM
Reply:

Similar Artilces:

Maximized vs minimized
I have a macro that copies data from disc drive A: and copies it to th current open spreadsheet. All works fine, except when it's done i minimizes the window. What code could I add to maximize the active window? Something like: ActiveWindow.WindowState = ???????? Thank You, Michae -- Message posted from http://www.ExcelForum.com Michael Try, Application.WindowState = xlMaximized Cheers John "daniels012 >" <<daniels012.1b7dva@excelforum-nospam.com> wrote in message news:daniels012.1b7dva@excelforum-nospam.com... > I have a macro that copies data from di...

Maximizing MainFrame
Hi everyone, I use VC++ 6.0. I have an MDI application that I want to be able to dynamiaclly maximize in such a way that user would not be able to get to the desktop. My goals are: 1. MainFrame should be maximized. 2. Minimize and Restore buttons should be either greyed out or removed. 3. User should not be able to move the application window. 4. The [x] close button in the top right corner should be visible. I have to use SetWindowLong() as oppose to Create() because this all has to happen dynamically many times in application's lifetime. My goal 1 ("maximized" is easy to achi...

How can I keep a maximized form maximized?
Hi All, I have a form I want maximized. I added DoCmd.Maximize to the form Open event. I set the property sheet for no min max buttos, but a minimize button still shows up next to the close button (which I have to have. Is there a majic spell I can use in VB to hide the min button? Second to making it go away, can I trap it and stop it from happening? Thanks, Max Hi Max, Are you sure you set the option minimize and maximize to none because if you did you shouldn't see neither option. Reading your post it looks like you have opted for only showing the minimize op...

Report is maximizing weird
I setup my report previews so that they maximize on load. I had it working fine but I must have done something wrong because now the form Maximizes funny. It fills up the database window but you can still see the caption. It seems Access thinks its maximized because I can't maximize it any further by hitting the maximize button, yet when I minimize it then maximize it, it correts itself. This causes a problem because right now, the page selector at the bottom is hidden because it isn't maximized correctly and I have to min/max in order to see it. Thanks, -- TIA On Report...

Maximizer
I am trying to send emails with Maximizer 7 but Outlook keeps giving me a 509 syntax error - can anyone help? ...

Resize when maximize
I have dialog based application with textbox and button i need when maximize the dialog the textbox automatically resized in dialog....i hope i explained what i need This might help you: http://www.codeproject.com/dialog/ResizableLib.asp Tom "Raed Sawalha" <RaedSawalha@discussions.microsoft.com> wrote in message news:74A27EF5-FC27-4B96-B306-7F4FC3E26175@microsoft.com... >I have dialog based application with textbox and button i need when >maximize > the dialog the textbox automatically resized in dialog....i hope i > explained > what i need ...

Text file from mainframe system
We are working on extracting a data file from an IBM mainframe system to merge it into a .csv Excel file. The options for saving the file are either ASCII or carriage- return indicator at the end of each line. What is Excel looking for at the end of each line for it to merge the data into the spreadsheet correctly? We have tried both options and it merges all info into one row. How are you merging your data into excel? For most DOS/windows programs, the end of line character is crlf (carriage-return/Line-feed). It's really two different characters (hex 0D, followed by hex 0A)....

maximizing Child View
HI all I am New user for VC, and i have just install MVS.NET. i try to make test application. and try MFC application. but wizard make child window not maximized . Will some one help me how to do it.? and how to hendel child window in MFC. Thanks. Amrit There is a ton of information including the answer to this question in this FAQ. http://ai.kaist.ac.kr/~ymkim/Program/mfc_faq.html Tom "Amrit" <cadd@wlink.com.np> wrote in message news:OYLUU11JJHA.920@TK2MSFTNGP05.phx.gbl... > HI all > I am New user for VC, and i have just install MVS.NET. > > i try to ...

Child window is not displayed when parent window is maximized
Hi, I developing an ActiveX control, i have made Microsoft PPT.exe window as the child of my OCX window using SetParent function. Now when my IE window is minimized and maximized, then OCX window is refreshed but the PPT window which is child window of OCX window is not displayed on maximization of IE window. Same behavior is there when some other window overlaps the OCX window. Thanks Vibhor Mahajan ...

message, MDIChildFrame switch from Maximize->Restore Restore->Maximize
Hello, I need the information: if the user switch the MdiChildFrame from Restore-Mode to Maximize, with a titlebar-button or doubleclick on the titlebar. And the same back to restore-modus. The messages - SysCommand, - WindowPosChanged, - Size does not realy work. SysCommand don't has info about dblclick on titlebar ... and so on. Is there a message with this information. Thanks Frank Iversen What do you mean OnSysCommand doesn't have info about dblclick on the title bar. It sends a SC_MAXIMIZED to the MDIChildWnd. void CChildFrame::OnSysCommand(UINT nID,LPARAM lPa...

How to maximize the window?
Myfile.xls will be opened at 3 pm, which is scheduled task, whenever this file is opened, this excel is not maximizing the window, does anyone have any suggestions on how to set excel to be maximized the window, when this application is opened. Thanks in advance for any suggestions Eric How to start Excel with different switches http://www.tek-tips.com/faqs.cfm?fid=1371 ju.c "Eric" <Eric@discussions.microsoft.com> wrote in message news:3F0005D3-09A1-412F-B94D-14FAAD945CC8@microsoft.com... > Myfile.xls will be opened at 3 pm, which is scheduled task, whe...

Convert from Maximizer Enterprise
Is it possible to convert a Maximizer enterprise or Max 9 database with 3000+ contacts over to Microsoft CRM 3? We also have several "custom fields" that we would REALLY want to be transferable. Is there any tools for this, or maybe 3rd party services? Anyone have any experience with this? Hi Canadaka, Yes it is possible to convert Maximizer to MS CRM. In fact, we had done a migration from Maximizer 7 and 7.5 to MS CRM and we could do read Custom fields as well. The methodology to write to MS CRM data is much similar to any other migration which is to read through WebServices a...

maximizing dialog
I want my main dialog to maximize as soon as i run the program........is it possible? I also want some of the dialog that i launch subsequently to maximize and should always stay on top.Can you suggest some way.If possible give me some code.Thanks in advance. Jeevan Try this for dialogs: Should also work for the application within InitInstance (just remeber to put m_pMainWnd-> before SetWindowPlacement, and make sure m_pMainWnd is set). int iScreenX = ::GetSystemMetrics(SM_CXFULLSCREEN); int iScreenY = ::GetSystemMetrics(SM_CYFULLSCREEN); WINDOWPLACEMENT WndPlacement; WndPlacemen...

Maximize from taskbar does not work
Hi I view Excel sheets with the IE6 (SP1 with latest patches), everything seems to be alright. But, when the window is minimized and I click on the icon in the taskbar, it maximizes and minimizes immediately again. It works when I right click and select restore, but this solution is not acceptable for our users ;-(. No problems when viewing pdf or doc files with IE. Thanks for any help in this Marcel ...

Maximizing a window
I am attempting to create an MDI app w/ a tabbar which flips to different open views (similar to visual studio.net). I am running into a problem where when switching between tabs/views I can visibily see (very briefly) the new window 'maximizing'. I dont' want the animation of it maximizing to be visible - is there a way to stop this? So that it just *poof* maximizes? Thx -- Adam Clauss cabadam@tamu.edu ...

cannot maximize Windows Live Mail page
Hi, I have Windows 7, and every thing has been working fine until yesterday when my Windows Live Mail stopped showing the right border were you can scroll, minimize , maximize or close . The left border does not go to the end of the screen, so I still can see the icons in the desktop. I cannot maximize the screen because the upper corner is not visible. I tried with the double pointed arrow but the margin does not move. Any info about how to get the full screen?. Thanks Doc Grab the corners of the window and the blue banner to get the screen to the size you want. Do no...

Maximize the window
Hi, I would like to use : AfxGetMainWnd()->ShowWindow(SW_MAXIMIZE); so as to maximize the main window. This works properly in a code for an event handling but it does not work in InitInstance() of the file MyApp.cpp. It generates immediately after compiling (0 error, 0 warning) the error dialog : (...) instruction could not be read (...) click on Ok to terminate (...). Do you know why this code which works in event handling does not work in InitInstance() ? And how can I make it work ? Thanks a lot, Guilhem. ...

Money Registers do not Maximize
When I launch Money 2005 (deluxe version) the register that opens does not maximize itself to the full screen. I have to essentially click on the maximize button and then click it again to make the screen kind of refresh itself. Any solutiions? ...

Receiving registered windows message after mainframe closed
I am stuck and could use any suggestion. My application (MSVC 6 & MFC) uses a mainframe that is hidden soon after it is created & uses a tray icon for user interactions. I have had no problem for quite some time - till I upgraded from WinXP home - SP1 to WinXP rpo XP2. The application crashes on exit in the debug mode. The error is an ASSERT in CWnd::WalkPretranslateTree. This function is checking if any windows wants to translate the message and the last window being checked is my mainframe which has been destroyed by now (the problem occurs after OnNcDestroy in my CMainFrame which...

Workbook not Maximizing
Hi, We have a machine here that has Office 2000 Pro /Win2K pro. The users excel workbooks are not maximizing properly. They will only show with the grey background around them, you can't drag it bigger either. We have reinstalled Office, this has not fixed the issue. Anybody has this happen? Thanks Any chance that that workbook is protected. Check under: tools|protection if you see "unprotect workbook", it's protected. You may need a password to put it back to normal. Judy Garland wrote: > > Hi, > > We have a machine here that has Office 2000 Pro /...

How to MAXIMIZE a window???
In my MyApp::InitInstance, I create a dialog box to ask for user login and password, before calling the DocTemplate. By doing this, it makes my program window always be minimized. It's like this: ---------------------------------------------------------------------- FLogin dialog; if(IDCANCEL == dialog.DoModal()) return FALSE; CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CBiopassCEDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CBiopassCEView)); AddDocTemplate(pDocTemplate); m_pMainWnd-&...

GetWindowRect before maximized
HI, I want to know for a maximized window how you can get window's old rect before it was maximized. Of course I can call getwindowrect in OnSize() but that would be clumsy. Thanks, Vincent Problem solved! GetWindowPlacement() gets the job done! >-----Original Message----- >HI, I want to know for a maximized window how you can get >window's old rect before it was maximized. Of course I >can call getwindowrect in OnSize() but that would be >clumsy. > >Thanks, >Vincent >. > Hello Vincent, What I personally would do is declare the getwindowrect() fu...

Workbooks Opening Maximized
Sometimes when I open workbooks they do not automatically open maximized. It is frustrating. I click on the left hand corner of the workbook and miximize and save the workbook but it still opens the next time with the corners not fully extended in Excel. Help. Excel 2003 XP Thanks, MD -- mdalby ------------------------------------------------------------------------ mdalby's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=7055 View this thread: http://www.excelforum.com/showthread.php?threadid=390202 bump to top of list to see if someone has an answer.....

Find out if maximized
How do I find out if aView has been maximized ? I tried pView->IsZoomed() but that always returned 0 Hi, Use GetWindowPlacement and test the showCmd member of the WINDOWPLACEMENT structure. HTH -- ============ Frank Hickman NobleSoft, Inc. ============ Thanks for the advice,but it doesn't work in my app. I've got an MDI-app. CMainFrame has been maximized but CChildFrame hasn't. Now I open a View. This appears as a 'normal' window.Now I maximize my view and see it really maximizes and covers the whole clientarea of the CMainFrame. Now I right click on its surfa...

? Maximized detection
Hi, I've got a dialog that I have set up with a menubar and statusbar. I have made it so that the user can show or hide either. What I need now is to detect if the dialog is maximized when the user shows/hides either bar so that I can adjust the dialog to still be maximized. thanks. -- Alec S. alec @ synetech . cjb . net How about something like this... BOOL IsMaximized( CWnd* pWnd ) { ASSERT( pWnd && ::IsWindow( pWnd->GetSafeHwnd() ) ); WINDOWPLACEMENT wp; pWnd->GetWindowPlacement( &wp ); return (wp.showCmd == SW_SHOWMAXIMIZED) ? TRUE:...