Re: Need help with modify notify windowstate and sysmenu
The crux lies in the scope where you declare a function.
If you want API calls available throughout everywhere in your program, you put the declaration in a module and make it a
Public Function WahateverAPICall(...)
Now it is known Public to all modules and forms of your program.
The last code I gave you has the functions declared Private, so they are only known within the module or form where they are.
For your purpose I'd best put all API and related Constant declarations in one module and use Public instead of Private, so as you have all the related names known everywhere in your program.
The second error of hMenu you get, because you don't dim a variable of this name before attempting to use it. You should know this already, don't you?
dim hMenu as Integer
hMenu = GetSystemMenuInfo(Me.hWnd, 0)
1 Attachment(s)
Re: Need help with modify notify windowstate and sysmenu
Thanks! I have copied your code but I'm afraid to say I am having the same trouble as I had. I don't know why or where the errors are coming from, hopefully you can take a look on the following attachment I have included which it would be easier for you to take a look because you may have the better knowedge than I do. :)
I did my best to find any other situations to get API call with properly call name but everything seen to be failed or messed.
Hope you guys can help me out to find out what went wrong and why the errors code I have received which the API call didn't works in the properly way.
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Mark, you did not do everything I told you, that's why you still get these errors with the GetSystemMenu.
Go to the Module3 you have created beautyfully.
And there find every word which spells 'Private' and change it to 'Public'.
I explained at length about the meaning of those keywords for the scope of a function. When it is declared Private, it is only known within the Module where it is. If you want to call it from outside, say from Form1 you declare it 'Public' so it is known everywhere in your project, ok?
The second error with hWnd is easy to come by:
Change the expression Me.hWnd to Me.Handle
I missed that: the hWnd of VB6 is now called Handle in .NET
Because these are some mere changes of text I think you can perform the corrections by yourself:
A few changes from Private to Public in Module3
1 Change of hMenu = GetSystemMenuInfo(Me.hWnd, 0) in Form1 LANG_French_Click() where you change Me.hWnd to Me.Handle
Only another advice, because I'm already afraid to spot where this is going to. You will add the code to the French_Click, and then you will add the same code again to the English_Click. Please, reflect and remember what I told you before about programming: You write one routine which does it for ALL languages and call it from a dozen of other click events.
Look at the code we had so far. Everywhere a text of a certain language is loaded, only ONE routine does the job and takes the text from the file which is named in the Public variable INIFile. You don't need to write the very same code over and over again.
Re: Need help with modify notify windowstate and sysmenu
Thanks, I have rename the codes the one you gave me. But 'GetSystemMenuInfo' did not solve it. I have receive the same error "Name 'GetSystemMenuInfo' is not declared"
Do you know why and what did I need to do to get it to solve??
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Ok. Post the sample as it is again.
I'm sure it's some simple and stupid mistake.
Have you checked if the function GetSystemMenuInfo IS DECLARED PUBLIC?
1 Attachment(s)
Re: Need help with modify notify windowstate and sysmenu
Ok, here it the sample file.
I'd appreciate the help you have done and I do not blame on anyone who make mistake as it can happens sometimes like I make mistakes so don't worry about it :thumb:
Yes I did checked all the function of GetSystemMenuInfo which they're declared public.
Hopefully you can recover why GetSystemMenuInfo cause the error.
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Ok. You'll have to wait until tomorrow, though.
I've only Visual Studio 2003 here at home and it won't read the project for some reason. I will check it tomorrow in the office, ok?
Re: Need help with modify notify windowstate and sysmenu
Yeah, that's fine. Hopefully you can be able to sort it out by tomorrow.
I'm looking forward once again. :thumb:
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
Well, now that was easy:
The name is GetSystemMenu, not GetSystemMenuInfo.
So in Form1 you write: hMenu = GetSystemMenu(Me.Handle, 0)
Again, let me advise you:
Don't continue writing code in the LANG_French_Click() event handler. That's silly.
Look, you shall keep the event handler as simple as possible.
What it does:
1. Select the language by setting which ini file is to be used further on
2. calling ReadLanguagesUnicode() which should do ALL of the settings, ok?
What you do (or should do, I cannot predict what you actually will do :rolleyes: ):
Go to the Module2. It contains all procedures for setting menu items and everything.
Start writing a new sub named
Public Sub ReadSystemMenuItems()
There we gonna put the code to read the system menu items from the current ini file. The code is the SAME for english and french, understand?
To run this routine we set a call at the very end of ReadLanguagesUnicode, right before its End Sub, like
Call ReadSystemMenuItems
So NO additional code is to go to the event handlers, right?
Did you get what I'm trying to explain?
Re: Need help with modify notify windowstate and sysmenu
Ok, I have changed the code what you suggestion me to do so do I have to copy all of the code from ReadLanguagesUnicode and put on Public Sub ReadSystemMenuItems() function??
I have writing the code Call ReadSystemMenuItems in my LANG_French_Click() to read system menu but nothing are displaying or working. I hope that we can get system menu to start reading the language by if I select the menu item language, E.G french. Then system menu attempt to read the text from module3.
Hopefully we can get this to work and get through.
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
No, no, no. You seem to have misunderstood fully.
You leave all the code as it was.
To keep the overview we write a new function in Module2
Public Sub ReadSystemMenuItems()
Therein we will write all the code necessary to read the system menu items from the current language ini file.
To run the code, we put a Call ReadSystemMenuItems as a last statement into the ReadLanguagesUnicode() procedure (which we don't change in any other respect, because it works good).
Therefore you dont have to put ANY new code into your Click events, which is what we want to achieve. NO additional code to the event handlers.
Have you understood the concept?
If not, tell me, then I will prepare the last version you sent so as to my proposals.
Re: Need help with modify notify windowstate and sysmenu
Sorry, but that what you have told me to put Public Sub ReadSystemMenuItems() on module 2. So i did it, here it the code:
Code:
Imports System.IO
Module Module2
Public Language As String
Public IniFile As String
'this should hold
Public UniCodeFile As String
Public Sub ReadSystemMenuItems()
End Sub
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
Language = GetFromFile("ControlsLanguage", "Language", "")
Form1.Text = GetFromFile("ControlsLanguage", "Title", "")
Form1.LANG_English.Checked = (Language = "English")
Form1.LANG_French.Checked = (Language = "French")
Dim mi As MenuItem
For Each mi In Form1.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 Form1.Controls
If ctl.GetType Is ms.GetType Then
ts = ctl
For Each ti In ts.Items
ReadUnicodeToolItems(ti)
Debug.Print(ti.Name)
ReadItems(ti)
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
There are some confusion what you have asked me to do so yes I do understood the concept.
Hopefully we can get this resolve :)
Thanks,
Mark
Re: Need help with modify notify windowstate and sysmenu
So it works right? Why don't you post the latest code before he asks.
Re: Need help with modify notify windowstate and sysmenu
The above start looks good. Thats what I suggested.
My fearful Nonono was in response to your question
Quote:
do I have to copy all of the code from ReadLanguagesUnicode and put on Public Sub ReadSystemMenuItems() function?
Ok. Now we can start write the ReadSystemMenuItems() code
And to get the function called we put the call as a last statement into ReadLanguagesUnicode()
Code:
Sub ReadLanguagesUnicode()
....
'all of the previously established code stays here and just before the end we call
ReadSystemMenuItems
End Sub
In fact we do not even need the Call statement. Just writing down the name of the sub will call it there.
That is the frame for our work. Now we can think about implementing the Item reading.
Ok, so far?
Re: Need help with modify notify windowstate and sysmenu
As an aftetrthought, it was more elegant If you'd put the
Code:
Public Sub ReadSystemMenuItems()
End Sub
at the end of the module, right after the last sub.
The logical structure of module 2 is in better order then, see?
First come the main procedure, followed by all the ReadItem-procedures which are called by the main procedure.