PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Problem with my Add-Ins working with the IDE in MDI mode-VBForums
Results 1 to 4 of 4

Thread: Problem with my Add-Ins working with the IDE in MDI mode

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,627

    Problem with my Add-Ins working with the IDE in MDI mode

    Ok, I keep getting angst that my Add-Ins won't work with the IDE in MDI mode. Therefore, I'm going to throw the primary problem back to you guys.

    Basically, the problem is that, the only way I was able to get everything to work the way I wanted, I used the Owner/Owned relationshop of Top-Level forms. To summarize, here are some of the features that this Owner/Owned relationship allows, with respect to the "Owned" form:

    • It's always on top of its Owner (i.e. z-order).
    • It's not an always-on-top form.
    • It closes when the Owner closes.
    • You can get this Owned form showing without ever letting it get the focus.

    And I need all of those features to make things work correctly.

    And now, I can illustrate the problem without resorting to an Add-In. We can illustrate the problem with a typical MDI project, which I've attached. This attached project has three forms: MDIForm1, Form1, Form2. The Form1 is an MDIChild. But Form2 is just a regular (non-MDIChild) form. Once running, if you click the MDIForm1, it will show Form1. And, when Form1 is shown, the Form2 is loaded.

    Now, here's the challenge: You can't tamper with code in either the MDIForm1 nor Form1. Just imagine that the MDIForm1 is the IDE, and that Form1 is a designer form within the IDE. So, you can see that you couldn't tamper with their code, as that's IDE compiled code.

    But, I've had Form1 load Form2. So, you've got an opportunity to do stuff. You can do whatever you like in the Form2's load event. Specifically, I need to show Form2, without it ever getting the focus, not even for a few CPU ticks (as this seems to cause problems for the IDE). I also need to make sure it's always on top of Form1 (z-order). And, I need to make sure Form2 closes if/when Form1 closes.

    The idea of making Form2 as Always-On-Top may be attractive to you. However, I'll tell you that I was never able to do that without that form getting the focus (even if just for a moment, which causes problems).

    So, there it is. Basically, I need an Owner/Owned relationship for an MDIChild form (as the Owner).

    Also, one more thing. I don't think using the Parent/Child features is a good idea. I can definitely see the IDE enumerating the children of a designer form to get various things done. And, if an extra child showed up, it probably wouldn't be good.

    I'm not thrilled about using a timer to do this. However, if there's no other way, I'll use it.

    I'll be quite interested in what people come up with.

    Elroy

    EDIT1: You can use Form1's hWnd if you like. You'll probably need to to make sure Form2 stays on top of Form1.
    Attached Files Attached Files
    Last edited by Elroy; May 7th, 2019 at 09:27 AM.
    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.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    382

    Re: Problem with my Add-Ins working with the IDE in MDI mode

    I think you could accomplish that by using ShowWindow(SW_SHOWNA), which shows Form2 on top, but without activating it. I tried the code below, and Form2 does appear on top without taking the focus from Form1. However, once I close the MDI Form, Form2 is not closed. I could solve this problem, but I don't think it would be an issue for Add-ins.

    Here is Form2 code:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SW_HIDE = 0
    4. Private Const SW_SHOWNORMAL = 1
    5. Private Const SW_SHOWMINIMIZED = 2
    6. Private Const SW_SHOWMAXIMIZED = 3
    7. Private Const SW_MAXIMIZE = 3
    8. Private Const SW_SHOWNOACTIVATE = 4
    9. Private Const SW_SHOW = 5
    10. Private Const SW_MINIMIZE = 6
    11. Private Const SW_SHOWMINNOACTIVE = 7
    12. Private Const SW_SHOWNA = 8
    13. Private Const SW_RESTORE = 9
    14. Private Const SW_SHOWDEFAULT = 10
    15. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    16.  
    17. Private Sub Form_Load()
    18.     ' This is the only place you can add new code.
    19.     ' Add a timer, subclass this form2, or whatever you like.
    20.     ShowWindow Me.hwnd, SW_SHOWNA
    21. End Sub

    Furthermore, if for some reason Form2 went behind the MDI, which happens when I minimize/restore the MDI, calling ShowWindow like above fixes the issue.

    Edited to add: I missed the part "And, I need to make sure Form2 closes if/when Form1 closes."
    Last edited by qvb6; May 7th, 2019 at 10:40 AM.

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,627

    Re: Problem with my Add-Ins working with the IDE in MDI mode

    Hi qvb6,

    Yes, using ShowWindow with SW_SHOWNOACTIVATE definitely gets it shown without activating it (or letting it get the focus). However, that's only part of the problem.

    How do I make sure it stays on top of Form1?

    How do I make sure it closes when Form1 closes?

    Do I just inform Form2 of its owner, and then have a timer periodically check if Form1 is still loaded and/or got on top of it (with respect to z-order)? Is a perpetually running timer in an Add-In going to be ok for people using the IDE's MDI mode?

    Elroy

    EDIT1: I'll have to look at SW_SHOWNA.

    EDIT2: It appears that SW_SHOWNA and SW_SHOWNOACTIVATE work precisely the same for my purposes, as my overlain form (equivalent to Form2) is never minimized. It's either shown normalized, hidden, or unloaded.
    Last edited by Elroy; May 7th, 2019 at 11:12 AM.
    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
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    382

    Re: Problem with my Add-Ins working with the IDE in MDI mode

    One solution to make a form hovers like Intellisense or Tooltip window is to intercept WM_MOUSEACTIVATE, and return MA_NOACTIVATE/MA_NOACTIVATEANDEAT to cancel the mouse click, then figure out what the user selected in the hover form and insert it into the text. This way the form doesn't even get the focus in the first place, and so no visual glitches.

    Closing Form2 when Form1 is closed can be achieved by hooking and looking for WM_CLOSE or WM_DESTROY. I am not sure if WM_CLOSE is sent every time the window is closed. Maybe it does if the user clicked the Close button, but perhaps not from IDE code when it wants to close the window.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width