[MFC] DOC

zhaozj2021-02-16  49

doc_view structure allows windows to maximize the outset Discussion on: enoloo

The general approach is to modify this in c ** app :: initInstance (), modified to this: {// ... m_pmainwnd-> showwindow (sw_showmaximized); m_pmainwnd-> UpdateWindow (); // ...} or Add: {// ... cs.style | = WS_MAXIMIZE; // ...} in CreateStruct & Cs)

This approach can generate a window to maximize, but the window is displayed from normal size to maximize. There is still a practice, you are hide first, then maximize. So how to make the window to maximize the normal opening? Take a look at the procedure from c ** app :: InitInstance (...): {// ... // ProcessShellcommand's first display window if (! ProcessShellcommand (cmdinfo)) Return false; m_pmainwnd-> showwindow (sw_showmaximized); m_pmainwnd-> UpdateWindow (); // ...}

-> CWINAPP :: ProcessShellcommand -> AFXGetApp () -> oncmdmsg (id_file_new, 0, null, null) // If you handle ID_FILE_NEW to call cwinapp :: OnfileNew () -> cdocmanager :: OnFileNew () -> CSingleDocTemplate :: OpenDocumentFile // initialize the current document templates -> CSingleDocTemplate :: CreateNewDocument // // load the resources to create a document and creates the main window (incidentally create a view), but did not show -> CSingleDocTemplate :: CreateNewFrame -> cframeWnd :: INITIALUPDATEFRAME {// ... int ncmdshow = -1; // default cwinapp * PAPP = AFXGetApp (); if (PAPP! = Null&& PAPP-> m_pmainwnd == this) {ncmdshow = PAPP-> M_ncmdshow; // use the parameter from winmain papp-> m_ncmdshow = -1; // set to default after first time} ActivateFrame (ncmdshow); // Here the first display window // ...} -> cframewnd: : (! IsWindowVisible ()) ActivateFrame (int nCmdShow) // nCmdShow is the normal show mode this frame should be in {// translate default nCmdShow (-1) if (nCmdShow == -1) {if nCmdShow = SW_SHOWNORMAL; else IF (isiconic ()) ncmdshow = sw_restore;}

// bring to top before showing bringtotop (ncmdshow);

IF (ncmdshow! = -1) {// show the window as specified showwindow (ncmdshow); // First display window // and finally, bring to top after showing bringtotop (ncmdshow);}} -> ***

As can be seen from the above, the CWINAPP :: ProcessShellcommand function creates a window and displayed, this is the first time the window is displayed, prior: m_pmainwnd-> showwindow (sw_showmaximized); m_pmainwnd-> UpdateWindow ();

How to solve the problem? Let the window maximize the first display?

CCommandLineInfo Cmdinfo; ParseCommandline (CMDInfo);

// Dispatch commands Spectly ON THE command Line // After ParseCommandline, ProcessShellcommand, add this sentence !!! m_ncmdshow = sw_showmaximized; if (! ProcessShellcommand (cmdinfo)) Return False;

// the one and only window has been initialized, so show and update it. M_pmainwnd-> showwindow (sw_showmaximized); m_pmainwnd-> UpdateWindow ();

problem solved.

转载请注明原文地址:https://www.9cbs.com/read-25202.html

New Post(0)