Re: Need help with modify notify windowstate and sysmenu
Thanks, it's ok so far I have put the code ReadSystemMenuItems on line at the end of sub ReadLanguagesUnicode statement. I have also placed Public Sub ReadSystemMenuItems() at the end of module2 statement also with Call ReadSystemMenuItems() but suddely, I have receive the error:
Code:
StackOverflowExeption was unhandled
An unhandled exception of type 'System.StackOverflowException' occurred in Project1.exe
what's wrong?? I thought everything was almost done? :confused:
Mark
Re: Need help with modify notify windowstate and sysmenu
It seems you have put a call to itself IN itself. Looks like you have written:
Code:
Public Sub ReadSystemMenuItems
Call ReadSystemMenuItems
End Sub
This will call itself endlessly and overflow the stack.
This call has nothing to do there. I didn't mean you to put it there. :)
If you are in doubt what you did, append the Module2.vb for me to see.
I was already thinking of how to implement your code, then, when I noticed that you have taken out the [OPTIONS] section and changed the ini file convention. Why did you do that? But no matter, we can put up with it.
Since the system menu has the items
Restore, Move, Size, Minimize, Maximize and Close
and is always the same, we could create a section like that:
code]
[SystemMenu]
1=Restore
2=Move
3=Size
4=Minimize
5=Maximize
7=Close
[/code]
The #6 item is the separator and wo don't change it.
In the french file you the have to put the apropriate french words.
If you agree with this structure, we can write the code for ReadSystemMenuItems().
Re: Need help with modify notify windowstate and sysmenu
Ok, here it the module2 code:
Code:
Option Explicit On
Imports System.IO
Module Module2
Public Language As String
Public IniFile As String
'this should hold
Public UniCodeFile As String
Function ReadCompleteFile() As Boolean
Dim sr As New StreamReader(IniFile)
If sr Is Nothing Then
MsgBox("File " + IniFile + " file not found", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "Languge file not found!")
Exit Function
End If
UniCodeFile = sr.ReadToEnd
sr.Close()
ReadCompleteFile = True
End Function
Function GetFromFile(ByVal SectionName As String, ByVal ValueName As String, ByVal DefaultVal As String) As String
Dim sp As Integer 'section position
Dim se As Integer 'string end
Dim vp As Integer 'value position
Dim sec As String 'entire section
Dim vst As String
'
GetFromFile = DefaultVal
sp = InStr(UniCodeFile, "[" + SectionName + "]")
If sp = 0 Then Exit Function Else sec = Mid$(UniCodeFile, sp + Len(SectionName) + 2)
se = InStr(sec, "[")
If se Then sec = Left$(sec, se - 3)
'
vp = InStr(sec, vbCrLf + ValueName + "=")
If vp = 0 Then Exit Function Else vst = Mid$(sec, vp + 2)
se = InStr(vst, vbCrLf)
If se Then vst = Left$(vst, se - 1)
'
GetFromFile = Mid$(vst, InStr(vst, "=") + 1)
End Function
Sub ReadLanguagesUnicode()
If Not ReadCompleteFile() Then Exit Sub
Dim mi As MenuItem
For Each mi In Form2.MainMenu1.MenuItems
ReadUnicodeMenuItems(mi)
Next
' next section is for other controls, beginning with alternate ToolStripMenu
' but also usable with other types of controls
Dim ctl As Control
Dim ms As New MenuStrip
Dim ts As MenuStrip
Dim ti As ToolStripItem
For Each ctl In Form2.Controls
If ctl.GetType Is ms.GetType Then
ts = ctl
For Each ti In ts.Items
ReadUnicodeToolItems(ti)
Debug.Print(ti.Name)
ReadItems(ti)
ReadSystemMenuItems()
Next
End If
Next
End Sub
Private Sub ReadUnicodeMenuItems(ByRef MItem As MenuItem)
Dim mi As MenuItem
If MItem.Tag <> "" Then MItem.Text = GetFromFile("ControlsLanguage", MItem.Tag, MItem.Text)
For Each mi In MItem.MenuItems
ReadUnicodeMenuItems(mi)
Next
End Sub
Private Sub ReadUnicodeToolItems(ByRef TItem As ToolStripMenuItem)
Dim sep As New ToolStripSeparator
TItem.Text = GetFromFile("ControlsLanguage", TItem.Name, "")
For Each Child As Object In TItem.DropDownItems
If Not Child.GetType Is sep.GetType Then ReadUnicodeToolItems(Child)
Next
End Sub
Private Sub ReadItems(ByVal Parent As ToolStripMenuItem)
Dim sep As New ToolStripSeparator
Parent.Text = ReadIniFile(IniFile, "ControlsLanguage", Parent.Name, "")
For Each Child As Object In Parent.DropDownItems
If Not Child.GetType Is sep.GetType Then ReadItems(Child)
Next
End Sub
Public Sub ReadSystemMenuItems()
Call ReadSystemMenuItems()
End Sub
End Module
You could write the code which I would be happy to agree with this structure :)
Hopefully after that, I can start to call ReadSystemMenuItems.
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Quote:
Originally Posted by mark103
Ok, here it the module2 code:
Code:
Public Sub ReadSystemMenuItems()
Call ReadSystemMenuItems()
End Sub
End Module
Look. :) It's exactly like I predicted. You call the same procedure from within itself. That MUST produce an error.
Ok. As you agree with the structure I put forward, I will work out a code to put in our new Sub. :)
Only I will do so tomorrow, I'm simply too tired tonight.
See you. ;)
1 Attachment(s)
Re: Need help with modify notify windowstate and sysmenu
Hello Mark.
I have made an effort to put the system menu under control.
I better send the complete project.
Look into the .ini files. I only have dummy item names because I cant remember the proper french expressions.
It looks like:
[SystemMenu]
0=Restore
1=Move
... and so on
There is no 5 because this is the seperator and will produce an error when trying to change.
Also despite my own proposal I have put the ReadSystemMenuItems() into module3 because all the definitions for the system menu are already there.
Only thing I have not found out: when changing the item texts, the icons on the left side seem to get lost. Still have to do a little research there.
Re: Need help with modify notify windowstate and sysmenu
Thanks, this is awesome :D Hopefully we can find a way how to place the icon next to the text. Can you help if I can change the font type of bold to Regular text style??
Hopefully I can make the look better ;)
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
I would try out the SetMenuItemBitmaps() on monday. Haven't VB2005 here for the weekend.
Have you got an icon you want to use?
1 Attachment(s)
Re: Need help with modify notify windowstate and sysmenu
Mark,
a little more research has revealed a solution which makes SetMenuItemBitmaps() obsolete.
It was a mistake in using the MENUITEMINFO.fMask value which killed away the icons and the fontbold.
I have attached a new Module3.vb code which leaves font and icon untouched when changing the text.
Another thing:
In Module2, in Function ReadCompleteFile you better put an On Error Resume Next as very first Line, like:
Code:
Function ReadCompleteFile() As Boolean
On Error Resume Next
Dim sr As New StreamReader(IniFile)
....
Otherwise you get an error when changing the folder or folder name of the project.
The On Error Resume Next lets you step into the error handler instead and assume the default language to english. This only ever can happen the first time the program is run from a different folder, but it CAN happen. So this prevents the program from crashing then.
Re: Need help with modify notify windowstate and sysmenu
Thanks for your help WoF! This is awesome and I'd love this work you have given me. But hey, I wondering how I could change the font style, E.G change the style for 'Close' and 'Restore' which I would like to change from Bold to Regular. How I can do that, what's the proper way to do??
Thanks for the help, you have been awesome :D
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Thanks for the flowers. :)
I haven't yet researched to a deeper extend, but there exists an API call ModifyMenu. If I find time tonight I shall take a look how it could be accomplished to change an item's font. Should be possible but I don't know many details about menu structures. I would have expected the font to be specified in the MENUITEMINFO struct, but it isn't...
I see what I can find out.
Re: Need help with modify notify windowstate and sysmenu
No problem WoF :)
Let me know when you have found situations.
It would be useful when someone see this and then post.
Thanks,
Mark
2 Attachment(s)
Re: Need help with modify notify windowstate and sysmenu
I reply here to your PM, where we have resolved the MenuItem changing meanwhile.
I can't experience your problem with menu size changing at my place.
I'm attaching 2 images to show the french and english system menus.
The sizes are still the same even after me changing 20 times from french to english.
There is no choice as to attach the project again, cause mine seems to be different then. :)
Re: Need help with modify notify windowstate and sysmenu
Seems like you're doing things the hard way. Look at this thread:
http://www.codeguru.com/forum/showth...03#post1698503
Re: Need help with modify notify windowstate and sysmenu
Thanks for your advise my dear friends WoF and dglienna. Following on dglienna's earlier post on my previous thread, I did not awake that resource file is actually the better place for me to use with more support on it. I found the code which it would be much useful to get access to the resource:
Code:
Imports System.Globalization
Imports System.ComponentModel
Imports System.Resources
Imports System.Threading
Private Sub Text1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.Click
Me.Text1.Text = (My.Resources.RuntimeStrings_fr.text1)
End Sub
Private Function MenuItems(ByVal locale_name As String, ByVal checked_button As ToolStripMenuItem, ByVal unchecked_button As ToolStripMenuItem) As Frm1
If Not Me.Created Then Return Nothing
' Make a CultureInfo.
Dim culture_info As New CultureInfo(locale_name)
' Make the thread use this locale.
Thread.CurrentThread.CurrentUICulture = culture_info
Thread.CurrentThread.CurrentCulture = culture_info
Dim frm As New Frm1
frm.Location = Me.Location
Return frm
End Function
How do I write on Private Function to grab the system menu info and replace the texts that come on resource file??
It bit the same as the old work on my project that WoF have already post it. So sorry about changing it again but I didn't realised it what I want.
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Found the proper code as it works but how I could read each of different system menu items, E.G Restore, Move Size, Minimize, Maximum and Close.
The working code is:
Code:
a = (My.Resources.RuntimeStrings_en1.English)
The code on above shows that it grab the system menu items and display the info from the resource to replace all of the system menu items texts.
What way I could grab each of those system menu items from grab the info on resource and replace the texts instead??
Something would be like this:
Code:
a = MenuItems1(My.Resources.RuntimeStrings_en1.English)
a = MenuItems2(My.Resources.RuntimeStrings_en1.English)
a = MenuItems3(My.Resources.RuntimeStrings_en1.English)
a = MenuItems4(My.Resources.RuntimeStrings_en1.English)
a = MenuItems5(My.Resources.RuntimeStrings_en1.English)
a = MenuItems6(My.Resources.RuntimeStrings_en1.English)
Hope you guys can help me with this and it will be resolve :)
Thanks,
Mark