Jump to content

[Solved] Can't set icon to a Status Bar


Recommended Posts

Good evening everyone :)
First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
Now, let me explain what I'm trying to understand.

I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.

Where am I stucked?

For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
For the two forms, which indeed have sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
Practically, I can't set icons to these two Status Bars, and I don't know why.
I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
I recreated exactly what my script does:

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $frmSubForm, _
       $txtSubFormField, _
       $sbSubFormStatusBar, _
       $objSB_IconError = _WinAPI_LoadShell32Icon(109), _
       $objSB_IconInformation = _WinAPI_LoadShell32Icon(277)

#Region ### START Koda GUI section ### Form=
    $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication")
    $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm)
    $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE))
    GUICtrlSetOnEvent(-1, "GenerateSubForm")
    GUICtrlSetFont(-1, 10, 400, 0, "Arial")
    _GUICtrlStatusBar_SetSimple($sbMainStatusBar)
    _GUICtrlStatusBar_SetText($sbMainStatusBar, "")
    GUISetState(@SW_SHOW, $frmMainForm)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd


Func ExitApplication()
    Exit
EndFunc

Func GenerateSubForm()
    #Region ### START Koda GUI section ### Form=
        $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm)
        GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm")
        $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20)
        $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE))
        GUICtrlSetOnEvent(-1, "CheckSubFormField")
        GUICtrlSetFont(-1, 10, 400, 0, "Arial")
        $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm)
        _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar)
        _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "")
        GUISetState(@SW_SHOW, $frmSubForm)
        GUISetState(@SW_DISABLE, $frmMainForm)
    #EndRegion ### END Koda GUI section ###
EndFunc

Func DeleteSubForm()
    ; Declared Globally => $frmSubForm
    GUIDelete($frmSubForm)
    GUISetState(@SW_ENABLE, $frmMainForm)
EndFunc

Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText)
    _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon)
    _GUICtrlStatusBar_SetText($sbStatusBar, $strText)
    ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF)
EndFunc

Func CheckSubFormField()
    ; Declared Globally => $txtSubFormField
    If GUICtrlRead($txtSubFormField) = "" Then
        ; Declared Globally => $sbStatusBar
        WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.")
    Else
        WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.")
    EndIf
EndFunc

The text is set, but icon is not.
Could someone please tell me why?
Thanks everyone in advance :) 

Best Regards.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

4 hours ago, AutoBert said:

That's a very easy way to set icons in a statusbar.

@AutoBert

I already managed to set icons in my Status Bar, but, in this particular situation, I can't do it, and I don't know why...

If you try to run the code in the first post, what result do you get?

Thanks.

 

Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...