How to create a hidden MainFrame
Brodie Thiesfield -- brodie@hpccm800.aus.hp.com
Wednesday, May 01, 1996
Win95 / WinNT 3.51 / VC++ 2.2
Hiya all,
I'm trying to create a main window which is hidden, as the correct size
for the client area isn't able to be determined until a little bit
later. However I don't want the window created at the incorrect size
to start with, and then immediately following resized to the correct
size when I know what it is. I felt that I could create the window
hidden, resize it when I know and then show it. However I can't create
it hidden. The application is pretty much a standard MFC SDI app - a
CWinApp, CMainFrame, View and Document.
I've tried overriding both CMainFrame::PreCreateWindow and OnCreate
taking the WS_VISIBLE bit off the style of the window, however the window
is always created visible.
Can anyone tell me what I'm doing wrong here??
Thanks,
Brodie.
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
TRACE0("Frame::PreCreateWindow()\n");
cs.cx = 1000; // if this window is visible, ensure we see it created
cs.cy = 1000;
cs.style &= ~WS_VISIBLE;
return bRetVal = CFrameWnd::PreCreateWindow(cs);
}
MICHAEL@datatree.com
Thursday, May 02, 1996
[Mini-digest: 7 responses]
>Win95 / WinNT 3.51 / VC++ 2.2
>
>Hiya all,
>
>I'm trying to create a main window which is hidden, as the correct size
>for the client area isn't able to be determined until a little bit
>later. However I don't want the window created at the incorrect size
>to start with, and then immediately following resized to the correct
>size when I know what it is. I felt that I could create the window
>hidden, resize it when I know and then show it. However I can't create
>it hidden. The application is pretty much a standard MFC SDI app - a
>CWinApp, CMainFrame, View and Document.
>
>I've tried overriding both CMainFrame::PreCreateWindow and OnCreate
>taking the WS_VISIBLE bit off the style of the window, however the window
>is always created visible.
>
>Can anyone tell me what I'm doing wrong here??
>
>Thanks,
>Brodie.
>
>
>
>BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
>{
> TRACE0("Frame::PreCreateWindow()\n");
>
> cs.cx = 1000; // if this window is visible, ensure we see it created
> cs.cy = 1000;
> cs.style &= ~WS_VISIBLE;
>
> return bRetVal = CFrameWnd::PreCreateWindow(cs);
>}
>
In VC++ 4.1 you simply comment out the InitInstance
lines:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
In VC++ 2.2 this should be the same as:
// create a new (empty) document
OnFileNew();
You should also change
pMainFrame->ShowWindow(m_nCmdShow);
to
pMainFrame->ShowWindow(SW_HIDE);
If this doesn't hide your app, purchase VC++ 4.x and
go for it!
----------------------------------
Michael L. Thal
Data Tree Corporation
voice: (619) 231-3300
fax: (619) 231-3301
-----From: Don.Irvine@net-tel.co.uk
> I've tried overriding both CMainFrame::PreCreateWindow and OnCreate
> taking the WS_VISIBLE bit off the style of the window, however the window
> is always created visible.
Is your 'InitInstance' function doing a ShowWindow on your mainframe ?
Don
-----From: "Frederic Steppe"
I see three possible solutions :
1. Try to resize the frame before it is displayed. Reading the sources, the
last point seems to be the first view's OnInitialUpdate member function.
That's the best way to ensure portability.
2. Set your app's m_nCmdShow member to SW_HIDE before loading the frame. The
main frame should then create and activate you application, but hidden. Call
your frame's ShowWindow procedure with SW_SHOW to show it. Works only for the
app's main window (ok for SDI applications or MDI main frame).
3. Beginning you application, I guess you make a call to your document
template's OpenDocumentFile function, which loads the frame, creates a
document, and creates the first view. If you make this call (could be when
processing the command line parameters, in this case process it yourself),
just try to set the parameter bMakeVisible to FALSE. When you know the exact
size of your frame, do something like that to activate the first view (after
you resized the frame, of course) :
void CMyFrameWnd::MyActivate()
{
InitialUpdateFrame(NULL, TRUE);
}
-----From: marghal@elwood.pionet.net (Al Margheim)
Brodie,
I just finished a program similar to yours that starts out hidden. All you
have to do is override the CMainFrame::ActivateFrame function and set
nCmdShow to SW_HIDE. Here's my ActivateFrame code:
void CMainFrame::ActivateFrame(int nCmdShow)
{
nCmdShow = SW_HIDE;
CFrameWnd::ActivateFrame(nCmdShow);
}
I suppose in your case you'd want to add a flag that would prevent nCmdShow
from being set to SW_HIDE after your window is the correct size.
Al Margheim
-----From: Dale Wilson
Try this...
bRetVal = CFrameWnd::PreCreateWindow(cs);
cs.style &= ~WS_VISIBLE;
return bRetVal
Dale
-----From: mikeblas@interserv.com
Call the base class implementation _first_.
.B ekiM
--
TCHAR szDisc[] = _T("Where do you want to work today?");
-----From: pdown@shout.net (Patrick Down)
After playing around with the way MFC starts up the application
I found that CFrameWnd::ActivateFrame was getting called with
SW_SHOW. This was actually done in the depths of CWinApp::OnFileNew
which is called by default when the app is started up without any
parameters. I created a little test application with VC++ 4.1 ( Sorry,
I don't have 2.2 but I would imagine that this part hasn't changed
much. )
First, I created a BOOL variable in CMainFrame called m_StartUp.
I set it to TRUE in the CMainFrame constructor. Then I overrode
ActivateFrame with the following code:
void CMainFrame::ActivateFrame(int nCmdShow)
{
if(m_StartUp)
CFrameWnd::ActivateFrame(SW_HIDE);
else
CFrameWnd::ActivateFrame(nCmdShow);
m_StartUp = FALSE;
}
This worked for me.
Munene Kiruja -- mun@mordor.com
Saturday, May 04, 1996
[Mini-digest: 2 responses]
Brodie Thiesfield wrote:
>
> Win95 / WinNT 3.51 / VC++ 2.2
>
> Hiya all,
>
> I'm trying to create a main window which is hidden, as the correct size
> for the client area isn't able to be determined until a little bit
> later. However I don't want the window created at the incorrect size
> to start with, and then immediately following resized to the correct
> size when I know what it is. I felt that I could create the window
> hidden, resize it when I know and then show it. However I can't create
> it hidden. The application is pretty much a standard MFC SDI app - a
> CWinApp, CMainFrame, View and Document.
>
> I've tried overriding both CMainFrame::PreCreateWindow and OnCreate
> taking the WS_VISIBLE bit off the style of the window, however the window
> is always created visible.
>
> Can anyone tell me what I'm doing wrong here??
>
> Thanks,
> Brodie.
>
> BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
> {
> TRACE0("Frame::PreCreateWindow()\n");
>
> cs.cx = 1000; // if this window is visible, ensure we see it created
> cs.cy = 1000;
> cs.style &= ~WS_VISIBLE;
>
> return bRetVal = CFrameWnd::PreCreateWindow(cs);
> }
·WS_VISIBLE Creates a window that is initially visible.
The key here is INITIALLY. It looks like the framework calls ShowWindow behind
your back so nuking WS_VISIBLE from the style doesn't help. If I am right, your
setting cx and cy to 1000 should take effect in teh window you end up with. Seems
the best thing to do would be to set the desired size in PreCreate.
If you read the help on OnCreate, you will see a microsoft guarantee that
OnCreate is run before the window becomes visible. This is another place to set
the size.
If you still don't know the size of your main window during OnCreate I'd suggest
you look into overriding OnFileNew - which is what starts the chain of events
that cause your window to be displayed - and fix it there.
-----From: Tommy Hui
Hi Brodie,
The cause of the behaviour is that MFC later does a ShowWindow(m_nCmdShow)
(m_nCmdShow is saved from the WinMain argument, which is typically
SW_SHOWNORMAL) after the window is created. To stop this behaviour, change
CWinApp::m_nCmdShow to something like SW_HIDE. See the reference for
ShowWindow() to see what other argument flags it takes.
Tommy
| Вернуться в корень Архива
|