Solved

Full screen MFC application

Posted on 2004-10-07
7
1,606 Views
Last Modified: 2013-11-20
Hi everybody,

I'm developping an application with MFC (VC 6.0), and I'd like that the main modal of my application to be in full screen, and I'd like that it works for different screen size.
For the moment I use the  following code:

// Put window on top and expand it to fill screen
      int cx, cy;
    HDC dc = ::GetDC(NULL);
      cx = GetDeviceCaps(dc,HORZRES) +
        GetSystemMetrics(SM_CXBORDER);
    cy = GetDeviceCaps(dc,VERTRES) +
        GetSystemMetrics(SM_CYBORDER);
    ::ReleaseDC(0,dc);

    ::SetWindowPos(m_hWnd, HWND_TOPMOST,
        -(GetSystemMetrics(SM_CXBORDER)+1),
        -(GetSystemMetrics(SM_CYBORDER)+1),
        cx+1,cy+1, SWP_NOZORDER);

But it just expand the window....
Moreover I'd like that this main window (the window which appears when you launch the program) to be not moved by clicking on the menu bar and moving the mouse...  
Hope you see what I mean.
Thanky by advance.
Vincent.
0
Comment
Question by:vinceTrace
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12247897
Do you mean maximised?
If so in the InitInstance
m_pMainWnd->ShowWindow(SW_MAXIMIZED);
0
 

Author Comment

by:vinceTrace
ID: 12248078
In the InitInstance of MyApp.cpp, I have put:

m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);

like this
                ...
                int nResponse = dlg.DoModal();
      m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
                ...

and the window is not maximised and I've an error after I close the application...
Could you tell me what I've done wrong?
Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12248756
In that case you need the ShowWindow(SW_MAXIMIZED) in the OnInitDialog (after the CDialog::OnInitDialog()) of the dialog and remove the line
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:vinceTrace
ID: 12249165
Thanks, now it works. I'd like to know if there is a way to center the window in the screen. For the moment my window is in the left-top corner, and i'd like to change the distance between the items of my window to fit with different screen sizes... A kind of scale change if you see what I mean...
I'd like that a button on the right down corner of my window to be at the right down corner of the screen, even if the user screen is bigger than the original size of my dialog...
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 80 total points
ID: 12249657
Trap the OnSize message (that has the params for the new size).
GetDlgItem(IDC_XXX)->SetWindowPos(NULL, left, top, 0,0, SWP_NOZORDER|SWP_NOSIZE);
will just move a control.

GetWindowRect, GetClientRect and ScreenToClient, ClientToScreen are other functions to look up in help.
0
 
LVL 4

Expert Comment

by:Skonen
ID: 12250748
To center the window on the desktop. Within your OnInitDialog message handler, insert this line:

CenterWindow(CWnd::GetDesktopWindow());
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 45 total points
ID: 12268271
Andy is correct... you will need to write special (custom) code to move and resize the controls... MFC does not provide that capability.  

If there are just a few controls, you can just move and resize them "manually" one-at-a-time in the OnSize handler.  If you have *lots* of controls, you may want to use a scheme where you keep track of the positions and sizes of each control in an array, and then cycle through the array moving and resizing them in turn.

=-=-=-=-=-=-=-=-=-=-=-
By the way, I always caustion programmers against forcing their window to cover the entire screen.  There are *very* few cases where this is advisable, but novice programmers tend to always want to do it.  Sure, your program is very important... to YOU... but your user may have several other programs, web browsers, etc. open and those other programs may be very important ... to HIM :-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now