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

    SetWindowPos problem.

    Hi all,

    I'm using SetWindowPos() to resize my dialog size according to the program state.
    (A state can be received at any point during the program execution.)

    My problem is that the dialog size gets overriden by windows when the following occurs.

    1. The user clicks on the dialog title and hold the left button pressed to reposition the window.
    2. the program receive an event and the dialog size needs to be resized so a call to SetWindowPos is made (At this point the dialog size looks correct)
    3. The user releases the mouse button and the dialog is resized to the previews size!

    Can anyone please help me to overcome this problem?

    Many thanks!!

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

    Re: SetWindowPos problem.

    Is it allowed for a user to change the dialog size (at any time)?
    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
    Dec 2005
    Posts
    445

    Re: SetWindowPos problem.

    No, the users are not allowed to change the dialog size.

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

    Re: SetWindowPos problem.

    Then you can prevent the user from resizing. You can catch WM_SYSCOMMAND and don't do anything for SC_SIZE. Or, better, simply remove the command from the menu.
    Code:
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if(pSysMenu != NULL)
      pSysMenu->RemoveMenu(SC_SIZE, MF_BYCOMMAND);
    Last edited by cilu; December 6th, 2010 at 09:09 AM.
    Marius Bancila
    Home Page
    My CodeGuru articles

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

  5. #5
    Join Date
    Dec 2005
    Posts
    445

    Re: SetWindowPos problem.

    Cilu, thank you for you quick reply.

    I think that I didn't clarify my question good enough.

    The users are unable to resize the dialog but they can still reposition the window (by clicking on the dialog title and moving the window while the left button is pressed , standard Windows ).

    The problem is that if the user clicks on the window title (to move the window) and I call SetWindowPos before the user releases the left button then the dialog size will be restored to the size it was when the user first clicked on the left button...

    1. user click on the window title to reposition the window (left button is pressed).
    2. I call SetWindowPos() to resize the window size (works fine)
    3. The user releases the left button and the dialog size is changed to the size it was before I called SetWindowPos.

    If the user doesn't click on the window title while I call SetWindowPos everything works just fine...

    Please help!
    Last edited by Salvadoravi; December 6th, 2010 at 08:11 AM.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: SetWindowPos problem.

    Quote Originally Posted by Salvadoravi View Post
    No, the users are not allowed to change the dialog size.
    Why don't you change the border style so they can't resize. Or, handle the mouse up button and call SetWindowPos there.

  7. #7
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: SetWindowPos problem.

    What is the event you were reacting at?


    If it is WM_SIZE (::OnSize) you probably better would handle WM_SIZING (::OnSizing) cause the latter would be fired before the sizing already happened, i. e. you would be able to correct the size prior to the window being already drawn.

    If the event neither is any of the above (???) you would need to retrieve the current sizes before calling SetWindowPos though that still could fail as the messages and events actually might come later than you were handling the sizing.

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