Solved

Full screen MFC application

Posted on 2004-10-07
7
1,607 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 85
string initialization in java 11 110
sum13 challenge 24 90
scoreUp challenge 14 56
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

21 Experts available now in Live!

Get 1:1 Help Now