Results 1 to 6 of 6

Thread: [RESOLVED] General tips about menus in MDI apps

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    83

    Resolved [RESOLVED] General tips about menus in MDI apps

    I have a general question I haven't found a good answer to on my own, so hopefully someone has a tip.

    I have an MDI application with many different types of forms. Some can be printed, some can be saved to files, etc. I would prefer that the MDI parent form's menus not be available (disabled) based on what features the displayed form supports...in other words, if it can be printed, the print menu is not grayed out.

    I can think of a few ways to do it, but none of them seem very efficient.

    Can someone point me in the right direction?

    Thanks!

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: General tips about menus in MDI apps

    Since Windows is based on an event driven principle, I would suggest creating your own messages.

    (Bear in mind the below is completely off the top of my head)

    Say for example, you have the following menus:

    File: New, Open, Save, Save As, Exit
    Edit: Find, Find Next, Replace, Replace All, Goto
    Effects: Solarize, Emboss, Glow

    Form1 is a text editor. Form2 is a picture editor.

    Subclass your MDI form, and check for your own messages. For example:
    Code:
    Const ME_TEXTEDITOR = &H2342345234
    Const ME_PICTUREEDITOR = &H1234283434523
    
    ' subclassed..
    Select Case Msg
        Case ME_TEXTEDITOR:
            ' enable File and Edit here
        Case ME_PICTUREEDITOR:
            ' enable File and Effects here
    End Select
    Subclassing is covered in so many threads here, and online, that I won't go over it now..

    As for the child forms. Something like this in Form1 (the text editor) should do the trick:
    Code:
    Private Sub Form_Load()
    SendMessage MDIForm.hWnd, ME_TEXTEDITOR, 0&, 0&
    End Sub
    ..and, of course, in Form2 (the picture editor):
    Code:
    SendMessage MDIForm.hWnd, ME_PICTUREEDITOR, 0&, 0&
    I assume you know what APIs are?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    83

    Re: General tips about menus in MDI apps

    Great...I get the general idea and a few of my ideas were similar, but here's where I run into problems (and I don't think your code deals with it either).

    There will be multiple forms open and I need the menus to change based on what's active. I can't find any events that fire when a MDI child form becomes the active form. Event's like GotFocus only seem to fire on NON-MDI forms or the parent form. Maybe you've steered me to the more specific question of how to change the menus on forms that are already loaded.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: General tips about menus in MDI apps

    The problem you're having is that the GotFocus event for a form doesn't fire if it has controls on it. The first TabStop control on the form recieves the GotFocus event.

    I wrote up a quick example for you. Basically, on my example, the TextBox in the 'text editor' receives the GotFocus event, and the PictureBox does too in the 'picture editor'.

    See attached.

    (PS: You're lucky I found my VS6 CD )

    chem
    Attached Files Attached Files

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    83

    Re: General tips about menus in MDI apps

    Well I'll be darned. The things you learn after all these years. Thanks.

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: General tips about menus in MDI apps

    No probs

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

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