Results 1 to 5 of 5

Thread: Subclassing WM_SYSCOMMAND and SC_MINIMIZE

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    40

    Subclassing WM_SYSCOMMAND and SC_MINIMIZE

    I have need for my application when minimized/Restored to cause a second application to follow. To capture the minimize event, I hooked WM_SYSCOMMAND and wait for SC_MINIMIZE to come along, then send a message to the second application to minimize. Works well, lasts a long time ... But wait, I just discovered that clicking any MDI form menu on my application minimizes the second application. How rude! Any ideas where the unexpected/unwanted WM_SYSCOMMAND/SC_MINIMIZE message comes from, and how to work around this showstopping problem? TIA, Bob.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2017
    Posts
    326

    Re: Subclassing WM_SYSCOMMAND and SC_MINIMIZE

    Can you attach a small demo project that replicates the issue? I tried recreating your problem based on your scant and vague description but I could not reproduce the bug. A more detailed explanation of the problem plus the relevant code and/or a concise demo of the issue would really help us identify the culprit faster.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,248

    Re: Subclassing WM_SYSCOMMAND and SC_MINIMIZE

    Why wouldn't you just monitor Form_Resize, and then examine Me.WindowState? KISS principle.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    40

    Resolved Re: Subclassing WM_SYSCOMMAND and SC_MINIMIZE

    Strange, someone (Antonio maybe?) posted a reply suggesting I hook WM_WINDOWPOSCHANGED, then use the GetWindowPlacement API to determine the WindowState. I rushed off to try it, it worked perfectly. When I got back here, his posting was gone. Subject closed, question answered. Thanks.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,246

    Re: Subclassing WM_SYSCOMMAND and SC_MINIMIZE

    Quote Originally Posted by K4CY View Post
    Strange, someone (Antonio maybe?) posted a reply suggesting I hook WM_WINDOWPOSCHANGED, then use the GetWindowPlacement API to determine the WindowState. I rushed off to try it, it worked perfectly. When I got back here, his posting was gone. Subject closed, question answered. Thanks.
    Yes, I deleted the answer because the first time that I read the question (a bit too fast) I thought that the problem was that something was minimizing the window in another way not using the WM_SYSCOMMAND.
    But then after I read Victor reply and re read the original question, now paying more attention, I saw that the problem was that something was sending unwanted WM_SYSCOMMAND's. That's different.
    I thought anyway that my suggestion would work, but you must be doing something wrong with the WM_SYSCOMMAND, perhaps you were not properly testing for the SC_MINIMIZE parameter, so I decided to wait and see and I deleted the message.

    Anyway Elroy's suggestion would do the same and it is simpler. Sometimes we are so used to use APIs that forget that VB can do some thing.

    Code:
    Private Sub Form_Resize()
        If Me.WindowState = vbMinimized Then
            ' the form was minimized
        End If
    End Sub
    Glad that you solved it anyway.
    Last edited by Eduardo-; Jun 27th, 2020 at 09:53 PM.

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