CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    6

    SetWindowPos v CREATESTRUCT

    Ladies and gentleman

    This is really just for education on the nuances of MFC.

    I was playing around with creating windows of different sizes and positions. Although I can achieve this with SetWindowPos, I have tried a number of times with CREATESTRUCT but it has only worked once for me.

    The following work in only one of my projects:

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE;

    cs.style=WS_OVERLAPPED | WS_SYSMENU | WS_BORDER; // no min/max
    cs.x=10;
    cs.y=10;
    cs.cx=100;
    cs.cy=100;
    cs.hMenu=NULL;

    return TRUE;
    }




    In all other projects, I can change the style but not the position and size. The only thing I can imagine is that ia dependent on the initial MFC project set-up and what underlying Application is picked. I have experiment but still can't find one that allows the above code to work again. Am I missing something really obvious.

    As I said I can affect the changes through SetWindowPos but I would like to understand why CREATESTRUCT doesn't always work. I would also be gratefully if someone could explain when you would consider changing the code in:

    BOOL CGridClickView::PreCreateWindow(CREATESTRUCT& cs)
    {
    return CView::PreCreateWindow(cs);
    }


    Ben

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: SetWindowPos v CREATESTRUCT

    You are modifying the stile and size after the called to CFrameWnd::PreCreateWindow. You have to do it before.
    Code:
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
      cs.style=WS_OVERLAPPED | WS_SYSMENU | WS_BORDER; // no min/max
      cs.x=10;
      cs.y=10;
      cs.cx=100;
      cs.cy=100;
      cs.hMenu=NULL;
    
      return CFrameWnd::PreCreateWindow(cs) );
    }
    Did you see the example in MSDN? http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: SetWindowPos v CREATESTRUCT

    The place of calling PreCreateWindow base class method may be not so important if avoid setting the style this way...
    Code:
       cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER; // no min/max
    ...and let the default styles set by the framework then remove only the unwanted ones:
    Code:
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
       if(!CFrameWnd::PreCreateWindow(cs))
          return FALSE;
    
       cs.style &= ~WS_MINIMIZEBOX; // no minimize box
       cs.style &= ~WS_MAXIMIZEBOX; // no maximize box
       return TRUE;
    }
    Anyhow, the OP question isn't very clear.
    What is CGridClickView? Is it derived from CView?
    If yes, then it has no sense to change its size/position here, as long as it is further changed by the framework in order to fit in the parent frame.
    Last edited by ovidiucucu; April 9th, 2012 at 03:07 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Feb 2012
    Posts
    6

    Re: SetWindowPos v CREATESTRUCT

    I have now tried on numerous different Application set-ups and the only set-up that seems to allow sizing and position through CREATESTRUCT is when User Interface Features - Use Classic Menus is selected. My original code then works. This makes me think that selecting menu bars, toolbars or ribbons forces some later automatic sizing to occur after the PreCreateWindow.

    I am just intrigued by the process.

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