PDA

View Full Version : Dynamic Menus in Visual Basic 6


Phantom
05-26-2003, 10:07 PM
I'm trying to write a program that "controls" Windows Messenger. What I want it to have is a Trillian-like away state. IE, you go into the menu -> set away -> click on an away message.

What I'm asking is how I would make the menu like that by reading a text file (or a .ini file, like Trillian does)...is this possible in such a beginner's language? :-)

oracleguy
05-26-2003, 11:06 PM
VB isn't exactly a beginner's language but to answer your question, you can add menu items during runtime just like controls.

To show you, try adding a Menu Item called mnuItem and set the index to 0.

Now on the Form_Load try this:
Dim x As Integer
For x = 1 To 5
Load mnuItem(x)
mnuItem(x).Caption = "Item " & x
mnuItem(x).Visible = True
Next

You should have no trouble in doing what you want by using this code as a model. You could also store the away messages in the registry too.

Phantom
05-26-2003, 11:10 PM
Well, how would I do it with text? I'm not too great at algorithms...

IE, the away messages specified are:
Eating
Sleeping
Pissing

And in a .txt file or something
Name: Eating
Message: I'm eating

Name: Sleeping
Message: I'm sleeping

Name: Pissing
Message: I'm pissing


How would I loop that so it added Eating, Sleeping, and Pissing to the menu (mnuItem by your example)?

oracleguy
05-27-2003, 09:47 PM
Yeah you could do that.

Phantom
05-27-2003, 09:54 PM
I'm asking how it is done :-)