CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Posts
    515

    How to create MDI child with borders

    How can I create MS Word 'print layout' like interface. The attached picture says it all. Basically I want a shaded area around my document just like word so it gives a feel of the 'page'.Name:  word_like_interface.jpg
Views: 1229
Size:  99.8 KB

    I was hoping I can override some function somewhere and along that lines tried playing around with below but that didn't help.
    Code:
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
        if( !CFrameWndEx::PreCreateWindow(cs) )
            return FALSE;
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs
    
    
        cs.cx = 250; // just playing around with size 
        cs.cy = 250;
    
    
    
    
        return TRUE;
    }
    Any ideas how can I do that?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to create MDI child with borders

    Use Spy++ to obtain this window class (which is _WwG in the case of Word 2003) and its properties.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to create MDI child with borders

    There isn't a windows style for this. What you are seeing is all done by custom Paint code.

  4. #4
    Join Date
    Aug 2006
    Posts
    515

    Re: How to create MDI child with borders

    It would seem that it is just a matter of creating smaller view inside the frame and than maybe I can handle no client area messages to further customize but apparently the view automatically occupies all the client area. I was hoping the following override will do the trick
    Code:
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	lpcs->cx = 500; // again playing with numbers
    	lpcs->cy = 400;
    
    	lpcs->x = 50;
    	lpcs->y = 50;
    
    	return CFrameWndEx::OnCreateClient(lpcs, pContext);
    }
    Again no use.

    I also tried to override Create()
    Code:
    BOOL CToolsView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    
    
    	return CRichEditView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
    }
    and here rect is passed which is all 0,0,0,0 and I tried to change but it has no effect.

  5. #5
    Join Date
    Aug 2006
    Posts
    515

    Re: How to create MDI child with borders

    Quote Originally Posted by VictorN View Post
    Use Spy++ to obtain this window class (which is _WwG in the case of Word 2003) and its properties.
    I did that but the properties doesn't tell me much. It's style is WS_CHILDWINDOW, WS_VISIBLE, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, I am more after how to create this.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to create MDI child with borders

    Quote Originally Posted by zspirit View Post
    I did that but the properties doesn't tell me much. It's style is WS_CHILDWINDOW, WS_VISIBLE, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, I am more after how to create this.
    Well, every window is created using one of the APIs like ::CreateWindow, ::CreateWindowEx, ...

    Note however, that this _WwG window is NOT a View (not derived from MFC CView class), And as OReubens already wrote you:
    Quote Originally Posted by OReubens View Post
    There isn't a windows style for this. What you are seeing is all done by custom Paint code.
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to create MDI child with borders

    or to put it in other terms with MFC.

    This is a regular CView or CScrollView where YOU provide the entire client area painting.
    For getting something similar to what you are seeing in word, this would amount to something along the lines of:
    Code:
    CMyView::OnDraw(CDC* pDC)
    {
       PaintEntireViewInGray(pDC);
       PaintTheWhitePaper(pDC);
       PaintTheShadowAroundTheWhitePaper(pDC);
       PaintTextInsideWhitePaper(pDC, "As you can see the document is enclosed in a shaded border area. How can I do this?", "Calibri", 14);
    }
    Now all you have to do is fill in the details of those 4 functions. (And yes, this'll take time to develop).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured