dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: A question regarding SetWindowPos

  1. #1
    Join Date
    Jul 2005
    Posts
    1,030

    A question regarding SetWindowPos

    The last argument for SetWindowPos nFlags could be SWP_SHOWWINDOW. But we can also call ShowWindow with SW_SHOW. Is there any difference between SW_SHOW and SWP_SHOWWINDOW in using them? Thanks.

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: A question regarding SetWindowPos

    Quote Originally Posted by LarryChen View Post
    The last argument for SetWindowPos nFlags could be SWP_SHOWWINDOW. But we can also call ShowWindow with SW_SHOW. Is there any difference between SW_SHOW and SWP_SHOWWINDOW in using them? Thanks.
    Regarding to Microsoft's MSDN you should use SWP_xxxxx constants as the last parameter of SetWindowPos. SW_xxx constants are for the ShowWindow function.

    Regards
    PA

  3. #3
    Join Date
    Jul 2005
    Posts
    1,030

    Re: A question regarding SetWindowPos

    Quote Originally Posted by ProgramArtist View Post
    Regarding to Microsoft's MSDN you should use SWP_xxxxx constants as the last parameter of SetWindowPos. SW_xxx constants are for the ShowWindow function.

    Regards
    PA
    Thanks for your reply. Basically my question is that since we might use SetWindowPos with SWP_SHOWWINDOW, why'd we need to call ShowWindow with SW_SHOW? Thanks.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,651

    Re: A question regarding SetWindowPos

    It's two different functions why should you mix up the constants that are used in combination with them? Do you apply the same logic to return values as well?
    Last edited by S_M_A; November 29th, 2011 at 03:31 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,456

    Re: A question regarding SetWindowPos

    Quote Originally Posted by LarryChen View Post
    Thanks for your reply. Basically my question is that since we might use SetWindowPos with SWP_SHOWWINDOW, why'd we need to call ShowWindow with SW_SHOW? Thanks.
    You do not need to call "ShowWindow with SW_SHOW" direct after "SetWindowPos with SWP_SHOWWINDOW" has been called.
    Victor Nijegorodov

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,651

    Re: A question regarding SetWindowPos

    As I understand it he asks if he can use SWP_SHOWWINDOW with ShowWindow
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,456

    Re: A question regarding SetWindowPos

    Quote Originally Posted by S_M_A View Post
    As I understand it he asks if he can use SWP_SHOWWINDOW with ShowWindow
    Well, it's very hard to understand what he means reading his OP...
    but the second post sounds a bit more clear for me. Although i may be wrong.
    Victor Nijegorodov

  8. #8
    Join Date
    Jul 2005
    Posts
    1,030

    Re: A question regarding SetWindowPos

    Sorry, I didn't state my question well. Basically when we want to display a window, we typically call SetWinowPos to set the size, position, etc for the window. Then I realize there is a parameter SWP_SHOWWINDOW with SetWindowPos. It seems like for me that it indicates to show the window. Okey, at this point, here comes my question. Since we can use SetWindowPos to show the window, why'd we need to call ShowWindow with SW_SHOW? Hopefully I explain my question well this time. Thanks.

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

    Re: A question regarding SetWindowPos

    It's not clear why you're implying a relationship between SetWindowPos and ShowWindow. They do different things. Are you saying you call SetWindowPos with SWP_SHOWWINDOW and you still need to call ShowWindow to see the window?

  10. #10
    Join Date
    Jul 2005
    Posts
    1,030

    Re: A question regarding SetWindowPos

    Quote Originally Posted by GCDEF View Post
    It's not clear why you're implying a relationship between SetWindowPos and ShowWindow. They do different things. Are you saying you call SetWindowPos with SWP_SHOWWINDOW and you still need to call ShowWindow to see the window?
    If SetWindowPos is called with SWP_SHOWWINDOW, does it show the window? If it does, is there any difference if I call ShowWindow with SW_SHOW to show the window?

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

    Re: A question regarding SetWindowPos

    Quote Originally Posted by LarryChen View Post
    If SetWindowPos is called with SWP_SHOWWINDOW, does it show the window? If it does, is there any difference if I call ShowWindow with SW_SHOW to show the window?
    Try it and see.

  12. #12
    Join Date
    Jul 2005
    Posts
    1,030

    Re: A question regarding SetWindowPos

    Quote Originally Posted by GCDEF View Post
    Try it and see.
    I tried it and couldn't really see any difference. I wonder if there is any difference in deep? Thanks.

  13. #13
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Re: A question regarding SetWindowPos

    SetWindwPos function can change size, position, z-order, can show/hide a window, and/or can activate a top-level window, all in a single call.
    For some particular nFlags values it can behave like other functions.

    In our case
    Code:
       UINT nFlags = SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE;
       m_wnd.SetWindowPos(NULL, 0, 0, 0, 0, nFlags);
    has the same effect like
    Code:
       m_wnd.ShowWindow(SW_SHOW);
    If you simply want to make visible a hidden window, usually use ShowWindow which is simpler.

    I would like to recommend paying attention to SetWindowPos and ShowWindow documentation, make some simple tests and see yourself which are the samenesses and differences.

    Note: you can also discover other functions like MoveWindow, BringWindowToTop, etc which can be "simulated" with SetWindowPos.
    Using one or another is up to your concrete needs, Windows programming knowledge and... taste
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)