Re: Need help with modify notify windowstate and sysmenu
No, wait. This was again VB6 talking.
Here is the code which should work under VB.NET
Code:
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" ( _
ByVal hMenu As Integer, _
ByVal un As Integer, ByVal b As Boolean, _
ByRef lpmii As MENUITEMINFO _
) As Integer
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" ( _
ByVal hMenu As Integer, _
ByVal uItem As Integer, ByVal fByPosition As Integer, _
ByRef lpmii As MENUITEMINFO _
) As Integer
Private Const MIIM_TYPE = &H10
Private Type MENUITEMINFO
cbSize As Integer
fMask As Integer
fType As Integer
fState As Integer
wID As Integer
hSubMenu As Integer
hbmpChecked As Integer
hbmpUnchecked As Integer
dwItemData As Integer
dwTypeData As String
cch As Integer
End Type
Private Sub SysMenuChange()
Dim hMenu As Integer
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
Yet I wrote the code of the previous post in VB6, where it works. I still have to test under .NET
Re: Need help with modify notify windowstate and sysmenu
Ok, the code works in VB.NET.
You can integrate it in your sample program from before.
But I would take out the subclassing and would not remove the close button, as long as we have not solved this issue.
Anyway I think your problem was only to change text of existing menu items, not to add new items to the system menu.
Re: Need help with modify notify windowstate and sysmenu
Thanks! Do I have to put on my windows form or just create module??
I'd much appreciate your help ;)
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
From pure intuition I would put it in a module, keeping all API functions private to the module, exposing only a Public function which would change a SysMenu entry.
Like:
Public Sub ChangeSysMenuItem(ItemNumber as Long, NewCaption as String)
Re: Need help with modify notify windowstate and sysmenu
Thanks, but there are errors code that I'm using vb6 code on .NET :confused:
Code:
Private Structure MENUITEMINFO
Error code I have receive "Structure 'MENUITEMINFO' must contain at least one instance member variable or Event declaration"
Code:
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 Structure
Error code I have receive "Declaration expected"
Code:
hMenu = GetSystemMenu(Me.hWnd, 0)
Error code I have receive on GetSystemMenu"Name 'GetSystemMenu' is not declared."
Error code I have receive on GetSystemMenu "Structure 'MENUITEMINFO' must contain at least one instance member variable or Event declaration"
Error code I have receive on Me.hWnd "Me' is not valid within a Module"
Code:
mii.cbSize = Len(mii)
Error code I have receive on mii.cbSize "cbSize' is not a member of 'System.Windows.Forms.MenuItem'"
Code:
Private Const MIIM_TYPE = &H10
Error code I have receive on MIIM_TYPE "Variable declaration without an 'As' clause; type of Object assumed."
Code:
mii.dwTypeData = "new caption"
Error code I have receive on mii.dwTypeData "dwTypeData' is not a member of 'System.Windows.Forms.MenuItem'."
Code:
mii.fMask = MIIM_TYPE
Error code I have receive on 'fMask' "fMask' is not a member of 'System.Windows.Forms.MenuItem"
What can we do to get those bugs to fix??
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Sorry I somehow copied and pasted something half ready.
Here is the complete code again. The structure must contain Dim statements as you can see, and be of integers instead of longs.
Also the missing function and constant are declared.
In case you had put that together with the other project you had, the missing declaration of GetSystemMenu() was in the form but private.
Nevertheless put the below code in a module and forget the previous post. Don't know how that happened...
Code:
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" ( _
ByVal hMenu As Integer, _
ByVal un As Integer, ByVal b As Boolean, _
ByRef lpmii As MENUITEMINFO _
) As Integer
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" ( _
ByVal hMenu As Integer, _
ByVal uItem As Integer, ByVal fByPosition As Integer, _
ByRef lpmii As MENUITEMINFO _
) As Integer
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hWnd As Integer, ByVal bRevert As Integer _
) As Integer
Private Const MIIM_TYPE = &H10
Private Structure MENUITEMINFO
Dim cbSize As Integer
Dim fMask As Integer
Dim fType As Integer
Dim fState As Integer
Dim wID As Integer
Dim hSubMenu As Integer
Dim hbmpChecked As Integer
Dim hbmpUnchecked As Integer
Dim dwItemData As Integer
Dim dwTypeData As String
Dim cch As Integer
End Structure
Private Sub SysMenuChange()
Dim hMenu As Integer
Dim mii As New MENUITEMINFO
hMenu = GetSystemMenu(Me.Handle, 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
Re: Need help with modify notify windowstate and sysmenu
Thanks, last I have receive
Code:
Private Const MIIM_TYPE = &H10
Error code I have receive on MIIM_TYPE "Variable declaration without an 'As' clause; type of Object assumed."
What can I do to ignore those error??
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
If you would have typed it, you get AS automatically
Code:
Private Const MIIM_TYPE As Long = &H10
and a Hex number is a Long in this case
Re: Need help with modify notify windowstate and sysmenu
Ah, thanks for your advise! I have forgot to put As Long next to MIIM_TYPE which I have put As Object where I nearly got myself correct. Your advise have make me a better experience to learn more ;)
At least, I would like to know how to call a module in vb.net?
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Your subroutines and functions are now defined when you try to use them. You don't call a module.
Re: Need help with modify notify windowstate and sysmenu
Ok, so how do I call API function from my menu item??
Sorry I am new on this and hope I will learn from this in the near future ;)
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Now you can use the API's that are defined GetSystemMenu() is one, right? Now it should be ok to use. Check for it to see.
Re: Need help with modify notify windowstate and sysmenu
Quote:
Originally Posted by dglienna
Now you can use the API's that are defined GetSystemMenu() is one, right? Now it should be ok to use. Check for it to see.
Yeah, i am asking what is the code to call API??
Hopefully it will works! :thumb:
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
You had it:
Code:
hMenu = GetSystemMenu(Me.hWnd, 0)
Re: Need help with modify notify windowstate and sysmenu
Thanks, sorry I didn't know the code was API call.
Code:
Public Sub test_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles test_Click
hMenu = GetSystemMenuInfo(Me.hWnd, 0)
I have receive another error code on hMenu:: "Name 'GetSystemMenuInfo' is not declared"
I have receive another error code on GetSystemMenuInfo: "Name 'hMenu' is not declared"
Why do I have to receive those errors?? :(
Thanks,
Mark