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.
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
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.
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'.