|
-
February 14th, 2008, 12:04 PM
#1
[RESOLVED] Need help with modify notify windowstate and sysmenu
Hi guys
I have a question about changes the system menu and the notify texts on windowstate (like maximum, minimize and close texts on the top right corner). Is it possible to make two different classes module, E.G make one for English and make another one for French. And is it possible to call one of those class by if I selection on one of the menu item one at a time that will convert to other which it would have to be something looking like this:
http://img262.imageshack.us/img262/7185/englishbi7.jpg
http://img144.imageshack.us/img144/2592/frenchte1.jpg
Form1
Code:
Option Explicit
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Const SC_CLOSE As Long = &HF060&
Private Const GWL_WNDPROC As Long = (-4&)
Private Const MF_BYCOMMAND As Long = &H0&
Private Const MF_BYPOSITION As Long = &H400&
Private Const MF_SEPARATOR As Long = &H800&
Private Const MF_CHECKED As Long = &H8&
Private Const MF_GRAYED As Long = &H1&
Private Const MF_BITMAP = &H4&
Private Sub Form_Load()
Dim hMenu As Long, hID As Long
hMenu = GetSystemMenu(Me.hWnd, 0)
'add a item in first pos
InsertMenu hMenu, &H0, MF_BYPOSITION, IDM.a, "First Menu"
'add a checked item before close item
InsertMenu hMenu, SC_CLOSE, MF_BYCOMMAND + MF_CHECKED, IDM.b, "Option &Before Close"
''add separator after close item
InsertMenu hMenu, SC_CLOSE, MF_BYCOMMAND + MF_SEPARATOR, 0&, vbNullString
''add item (after the last item)
InsertMenu hMenu, &HFFFFFFFF, 0&, IDM.c, "&New Close Button"
''add a disabled item
InsertMenu hMenu, &HFFFFFFFF, MF_GRAYED, IDM.d, "&Option MaRiO"
'add a separator
InsertMenu hMenu, &HFFFFFFFF, MF_BYCOMMAND + MF_SEPARATOR, 0&, vbNullString
InsertMenu hMenu, &HFFFFFFFF, MF_BYPOSITION, IDM.e, "&Last Option"
'refresh menu
DrawMenuBar hMenu
'draw icon in pos 13
hID& = GetMenuItemID(hMenu&, 13)
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, Picture1.Picture, Picture1.Picture
'draw icon in first item
hID& = GetMenuItemID(hMenu&, 0)
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, Picture2.Picture, Picture2.Picture
'delete the Close item
DeleteMenu hMenu, SC_CLOSE, MF_BYCOMMAND
'subclass
procOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Module1
Code:
Option Explicit
Public Enum IDM
a = 128
b
c
d
e
End Enum
Public procOld As Long
Private Declare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private Const WM_SYSCOMMAND = &H112
Public Function WindowProc(ByVal hWnd As Long, _
ByVal iMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case iMsg
Case WM_SYSCOMMAND
Select Case wParam
Case IDM.a
MsgBox "'First menu' Cliked"
Case IDM.b
MsgBox "'Option Before Close' Cliked"
Case IDM.c
MsgBox "GoodBye"
Unload Form1
Exit Function
'Case IDM.d: MsgBox "Clik en 'Option MaRiO' Cliked" 'Disabled...
Case IDM.e
MsgBox "'Last Option' Cliked"
End Select
End Select
WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
End Function
Let me know if that is possible to do that?? If so how?? Also I would like to know if that is possible to call and change the notify texts on windowstate the one that come with max, mini and close button on the very top right corner of the screen??
If you know what I means, please can you post the code something would be like this:
Code:
Public Sub English_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles English.Click
Me.NotifyWindowstate.Text = "Maximum"
End Sub
Public Sub French_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles French.Click
Me.NotifyWindowstate.Text = "Maximizar"
End Sub
If not, please can you let me know what other situations that I could do that??
Let me know if that is possible....
Thanks,
Mark
-
February 14th, 2008, 08:59 PM
#2
Re: Need help with modify notify windowstate and sysmenu
Is it possible to do that guys??
-
February 15th, 2008, 09:46 AM
#3
Re: Need help with modify notify windowstate and sysmenu
Mark,
your above code comes from Vb6.0 as can be seen. I got it working in VB6 after commenting out the statements which refer to the pictureboxes I haven't got.
To make this run under VB.NET, several changes are necessary. First, all Long declarations have to be Integer, because in .NET Long is 64 and Integer is 32 bit.
Then, As Any is not allowed. Have to decide for String here, I think, because it's the menu caption passed there.
Third is the AddressOf operator. It will not convert an address to Integer and I, as a .NET novice have no solution for that. Maybe one of the .NET Aces can help here.
Changing the caption of an existing item seems possible too, but is more complicated.
Please refer to the API SetMenuItemInfo() http://allapi.mentalis.org/apilist/S...ItemInfo.shtml
to see a sample of how to use the MenuItemInfo structure.
How this is done in .NET, however, I couldn't figure out. Sorry.
-
February 15th, 2008, 10:44 AM
#4
Re: Need help with modify notify windowstate and sysmenu
Thanks for your advise WoF, the code I post shows example of what I wanted the form to do by if I selection the language to french then change the system menu to french. Is it possible to do that or do I need dll to do that??
As well for notify texts on windowstate the one that come with max, mini and close button on the top right corner of the screen, is it possible to change the texts of the language??
If not, any other situations??
Thanks,
Mark
-
February 15th, 2008, 11:18 AM
#5
Re: Need help with modify notify windowstate and sysmenu
As I sayd, you can do. Only we have to find a solution for the AddressOf operator in Vb.NET and we need to work out how change the menu item caption of an existing menu item.
The general direction is:
Create a MENUITEMINFO struct as a variable.
Call GetMenuItemInfo() API to fill the struct with data.
Change the caption
Call SetMenuItemInfo() API to set the changed data.
If I can find some time, I will make a test, but it looks bad with time this weekend, 
As for 'notify texts' I think you are referring to the ToolTipTexts which appear when you hover the mouse over the buttons. I must admit I have no idea how to change those...
-
February 15th, 2008, 03:17 PM
#6
Re: Need help with modify notify windowstate and sysmenu
Ok, thanks for the info that I can get GetMenuItemInfo to call on my form. I will have to create menuinfoitem to get system menu to call but looks like it would be difficult to create one??
Let me know if you have find the better one 
Thanks,
Mark
-
February 15th, 2008, 07:26 PM
#7
Re: Need help with modify notify windowstate and sysmenu
I'm just studying how subclassing is done in Vb.Net, but don't seem to get the hang of it.
I would be grateful if one of the .NET Gurus could intervene and give a short notice about that.
Obviously, it has to work somehow with the Override statement, but i don't understand how I formulate a proper override statement for the full WndProc.
After that we could think about the GetMenuItemInfo() stuff.
-
February 16th, 2008, 01:33 AM
#8
Re: Need help with modify notify windowstate and sysmenu
Are you talking about changing the languages while the app is running? I thought you were reading them in...
-
February 16th, 2008, 05:22 AM
#9
Re: Need help with modify notify windowstate and sysmenu
 Originally Posted by dglienna
Are you talking about changing the languages while the app is running? I thought you were reading them in...
Yeah I did, but wanted system menu to work together as well. Sorry I forgot to ask when I post language thread age ago!!!
Hope there is situation of changing system menu when I switch from english to french and switch back from french to english.
Thanks,
Mark
-
February 16th, 2008, 06:01 PM
#10
Re: Need help with modify notify windowstate and sysmenu
-
February 16th, 2008, 07:35 PM
#11
Re: Need help with modify notify windowstate and sysmenu
 Originally Posted by dglienna
Wrong mate, they still don't have system menu. Please read my post what I wanted, I don't want a program to write the languages, just want to exchange the language when I switch from english to french then system menu show the french language.
If I can't do that, I'll move on.
Thanks,
Mark
-
February 16th, 2008, 07:54 PM
#12
Re: Need help with modify notify windowstate and sysmenu
Can you read?
This tutorial sparked off from my own ventures to incorporate a particular feature in my own software - which uses mixed language (English & Thai) on a couple of screens to store user data. Certain fields, apart from First & Last Names & parts of address were to be entered in Thai. Now the current language can be easily switched by pressing Alt-Left Shift (or whatever key combination you've set your system to) - but when you consider the same key-combination has to be repeated for over 20 fields on each screen - and this times the number of records you have to enter, then is becomes a dull and humongously tedious venture. This might lead to a lot of typo's too. (In my case the users of my software had to enter over 4000 student records - soooooo... I had to do something to make the lives of those poor guys a little easier.)
-
February 17th, 2008, 08:03 AM
#13
Re: Need help with modify notify windowstate and sysmenu
That's only writing and store the data on the form, not changing the system menu data.
I want to change the text on my system menu data. Don't you know what system menu are??
I have downloaded the attachment from the site and nothing was on it. 
Thanks,
Mark
Last edited by mark103; February 17th, 2008 at 08:25 AM.
-
February 18th, 2008, 09:47 AM
#14
Re: Need help with modify notify windowstate and sysmenu
Please can someone help me please??
-
February 18th, 2008, 11:12 AM
#15
Re: Need help with modify notify windowstate and sysmenu
Ok, Mark, I have worked something out, that will help you changing the caption of system menu items.
Code:
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" ( _
ByVal hMenu As Long, _
ByVal un As Long, ByVal b As Boolean, _
ByRef lpmii As MENUITEMINFO _
) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" ( _
ByVal hMenu As Long, _
ByVal uItem As Long, ByVal fByPosition As Long, _
ByRef lpmii As MENUITEMINFO _
) As Long
Private Const MIIM_TYPE = &H10
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Private Sub SysMenuChange()
Dim hMenu As Long
Dim mii As MENUITEMINFO
hMenu = GetSystemMenu(Me.hWnd, 0)
mii.cbSize = Len(mii)
If hMenu <> 0 Then
GetMenuItemInfo hMenu, 0, True, mii
mii.dwTypeData = "new caption"
mii.fMask = MIIM_TYPE
SetMenuItemInfo hMenu, 0, True, mii
End If
End Sub
To explain a little what SysMenuChange does:
GetMenuItemInfo hMenu, 0, True, mii lets the API fill the MENUITEMINFO structure with info about item 0
Then you set mii.dwTypeData to the new caption string and set mii.fMask like shown
Then SetMenuItemInfo hMenu,0,True, mii sets the new caption for item 0
Like that you can change the caption of any menuitem by number.
As for the ToolTipTexts of the other buttons I still have no idea how to do that...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|