Sign in to follow this  
Followers 0
Mikeman27294

Error with images used as tabs.

11 posts in this topic

#1 ·  Posted (edited)

Hey everyone.

As some of you know,I have been looking for an effective way to get a ribbon system running for my programs. In my program, I have a file tab image, but that is not created in the for loop (Where the rest of the tab images are created), as it is not going to have the same image. The problem is, that when I am in the file tab, I cannot select the edit tab. The script also will not change the image of the file button on hover from the home tab, and does not appear to change when I enter the file menu. As for the buttons in each tab, dont mind them, they are just so that I can focus on the ribbon when I am changing tabs, and will see it move without needing to focus on it. Also, dont worry about the tab control, I have found that that part still works perfectly fine, even when the GUI Controls are outside it and it is outside the window.

#Region###STARTUP###
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
Local $Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
Local $sStruct = DllStructCreate("dword;int;ptr;int")
Local $MyArea[4] = [0, 0, 31, 0]
Local $desyesno = MsgBox(4,Default,"Press yes to enable the Design tab, or no to disable it.")
Local $Filehover
If $desyesno = 6 Then
    Global $Tabnums=5
Else
    Global $Tabnums=4
EndIf
Dim $Pic[$Tabnums]
If $Tabnums=5 Then
    Dim $TabText[5]
    $TabText[4] = "Design"
ElseIf $Tabnums=4 Then
    Dim $TabText[4]
EndIf
$TabText[3] = "Program"
$TabText[2] = "View"
$TabText[1] = "Edit"
$TabText[0] = "Home"
$hGUI=GUICreate('MyGUI', 705, 369, 100, 100)
_Vista_ApplyGlassArea($hGUI)
Global $Winpos=WinGetPos("MyGUI")
Global $GlassArea = GUICtrlCreateLabel("", (UBound($Pic)+1)*90, 0, $Winpos[2]-(UBound($Pic)+1)*90, 32) ;area that will be filled with glass
GUICtrlSetBkColor(-1, 0x000000)
Global $DarkGreyArea = GUICtrlCreateGraphic(0, (UBound($Pic)+1)*90, $Winpos[2]-(UBound($Pic)+1)*90, 32) ;work area (to add controls in)
GUICtrlSetBkColor(-1, 0xC5C5C5) ;with light grey area
#region
$File=GUICtrlCreatePic(@ScriptDir & '\tab_filedefault.bmp', 0, 0, 90, 29)
GUICtrlCreateLabel("File", 0, 7, 90, 29, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetcolor(-1, 0xFFFFFF)
#EndRegion
For $i = 0 To $Tabnums-1
    $Pic[$i] = GUICtrlCreatePic(@ScriptDir & '\tab_default.bmp', 90*($i+1), 0, 90, 29)
    GUICtrlCreateLabel($TabText[$i], 90*($i+1), 7, 90, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetcolor(-1, 0x000000)
Next
$Tab = GUICtrlCreateTab(-@DesktopWidth, -@DesktopHeight, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateTabItem('File')
GUICtrlCreateButton('File', 290, 319, 70, 23)
GUICtrlCreateTabItem('Home')
GUICtrlCreateButton('Home', 300, 319, 70, 23)
GUICtrlCreateTabItem('Edit')
GUICtrlCreateButton('Edit', 310, 319, 70, 23)
GUICtrlCreateTabItem('View')
GUICtrlCreateButton('View', 320, 319, 70, 23)
GUICtrlCreateTabItem('Program')
GUICtrlCreateButton('Program', 340, 319, 70, 23)
GUICtrlCreateTabItem('Design')
GUICtrlCreateButton('Design', 350, 319, 70, 23)
GUICtrlCreateTabItem('')
GUISetState()
$Item = -1
$Over = -1
#EndRegion###STARTUP###
While 1
    $Info = GUIGetCursorInfo()
    If @error Then
        If $Over <> -1 Then
            GUICtrlSetImage($Pic[$Over], @ScriptDir & '\tab_default.bmp')
            GUICtrlSetImage($File, @ScriptDir & '\tab_filedefault.bmp')
            $Filehover=0
        EndIf
        GUICtrlSetImage($File, @ScriptDir & '\tab_filedefault.bmp')
        $Filehover=0
        $Over = -1
    Else
        $Index = _Index($Info[4])
        If $Index <> $Over Then
            If $Over <> -1 Then
                GUICtrlSetImage($Pic[$Over], @ScriptDir & '\tab_default.bmp')
                GUICtrlSetImage($File, @ScriptDir & '\tab_filedefault.bmp')
                $Filehover=0
            EndIf
            If ($Index <> -1) And ($Index <> $Item) Then
                GUICtrlSetImage($File, @ScriptDir & '\tab_filedefault.bmp')
                GUICtrlSetImage($Pic[$Index], @ScriptDir & '\tab_hover.bmp')
                $Over = $Index
                $Filehover=0
            Else
                GUICtrlSetImage($File, @ScriptDir & '\tab_filedefault.bmp')
                $Filehover=0
                $Over = -1
            EndIf
            If $Info[4]=6 or $Info[4]=5 And $Filehover=0 Then
                GUICtrlSetImage($File, @ScriptDir & '\tab_filehover.bmp')
                $Filehover=1
            EndIf
        EndIf
    EndIf
    $Msg = GUIGetMsg()
    If $Item = -1 Then
        $Msg = $Pic[0]
        $Item = 1
    EndIf
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic[0] To $Pic[UBound($Pic) - 1]
            If $Msg <> $Pic[$Item] Then
                GUICtrlSetImage($Pic[$Item], @ScriptDir & '\tab_default.bmp')
                GUICtrlSetImage($Msg, @ScriptDir & '\tab_filedefault.bmp')
                GUICtrlSetImage($Msg, @ScriptDir & '\tab_selected.bmp')
                $Item = _Index($Msg)
                GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item+1, 0)
                $Over = -1
            EndIf
        Case $File
            GUICtrlSetImage($Pic[$Item], @ScriptDir & '\tab_default.bmp')
            GUICtrlSetImage($Msg, @ScriptDir & '\tab_fileselected.bmp')
            GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, 0, 0)
            $Filehover=2
            $Item=1
        Case $GlassArea
            dllcall("user32.dll","int","SendMessage","hWnd", $hGUI,"int",0xA1,"int", 2,"int", 0)
    EndSwitch
WEnd
Func _Index($CtrlID)
    For $i = 0 To UBound($Pic) - 1
        If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
            Return $i
        EndIf
    Next
    Return -1
EndFunc   ;==>_Index
Func _Vista_ApplyGlassArea($hWND=$hGUI, $Area=$MyArea, $bColor = 0x000000)
    If @OSVersion <> "WIN_VISTA" And @OSVersion <> "WIN_7" Then
        MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
        Exit
    Else
        If _Vista_ICE() Then
            If IsArray($Area) Then
                DllStructSetData($Struct, "cxLeftWidth", $Area[0])
                DllStructSetData($Struct, "cxRightWidth", $Area[1])
                DllStructSetData($Struct, "cyTopHeight", $Area[2])
                DllStructSetData($Struct, "cyBottomHeight", $Area[3])
                GUISetBkColor($bColor); Must be here!
                $Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($Struct))
                If @error Then
                    Return 0
                Else
                    Return $Ret
                EndIf
            Else
                    MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
            EndIf
        Else
            MsgBox(0, "DWM Not Enabled", "DWM is not enabled!")
        EndIf
    EndIf
EndFunc ;==>_Vista_ApplyGlassArea
 Func _Vista_ICE()
    $ICEStruct = DllStructCreate("int;")
    $Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct))
    If @error Then
        Return 0
    Else
        Return DllStructGetData($ICEStruct, 1)
    EndIf
 EndFunc ;==>_Vista_ICE

Does anybody see a problem there? Anything and I would be greatful.

Also, this uses aero glass so will not run on XP. If you want to run it on XP, you will have to comment out lines:6 to 8,32 to 37, and 141 onwards.

One more thing, if you wanted the images, just let me know and I can upload them here for you.

Thanks.

Edited by Mikeman27294

Share this post


Link to post
Share on other sites



Not even going to bother reading it. Don't use spoilers to post code. If it's indented it's easier to read so use the code tags to maintain indenting.

I'm also surprised a Mod hasn't nailed you yet for that image in your signature. You know the forum rules and I have a hunch that will be deemed to be a violation.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

There we go, I didnt realise that I hadnt done the opening autoit tag properly. As for the picture, I didnt read anywhere saying that it is not allowed, but if it isnt, then I better remove it, and thanks for mentioning that.

Share this post


Link to post
Share on other sites

Images are allowed but that one of yours specifically mentioned games and you know that mentioning games is not allowed.

We recently went so far as to be sure there was no mention of games in the help file for the next release.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oh, I see what the problem is now then, I thought you meant me having an image in my signature. Well again, thanks for pointing that out.

Anway, could anybody suggest anything that might help fix the script?

Edited by Mikeman27294

Share this post


Link to post
Share on other sites

no ideas?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

are the pics really necesarilly for this? can you upload some?

EDIT; you can comment a little you script it make us easier to read... how about this.

dllcall("user32.dll","int","SendMessage","hWnd", $hGUI,"int",0xA1,"int", 2,"int", 0)

What message are you sending?

I already found what

Edited by monoscout999

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You need the images? No problem then. They are attached.

Unfortunately, I dont know how to upload them for direct download, so you will have to download them off my mediafire account. It has the images and the script, in a compressed zipped file. Let me know if it says it is corrupt, and I will try it with a winrar archive.

http://www.mediafire.com/?sgdw0n1omw4e7lj

Edited by Mikeman27294

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The problem must be in the flags you use for checks, im re design your script and so far it is working. The Flags problem always are a headache and to me are a very personal issue when scripting.

My version here:

#include <Array.au3>
#include <winapiex.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
Global $TabDefaultPic = @ScriptDir & '\tab_default.bmp'
Local $Tabnums = 5
Dim $Pic[$Tabnums]
Dim $TabText[$Tabnums]
$TabText[4] = "Design"
$TabText[3] = "Program"
$TabText[2] = "View"
$TabText[1] = "Edit"
$TabText[0] = "Home"
$hGUI = GUICreate('MyGUI', 705, 369, 100, 100)
; Applying glass effect
$tMARGINS = DllStructCreate($tagMARGINS)
DllStructSetData($tMARGINS, 1, 0)
DllStructSetData($tMARGINS, 2, 0)
DllStructSetData($tMARGINS, 3, 32)
DllStructSetData($tMARGINS, 4, 0)
_WinAPI_DwmExtendFrameIntoClientArea($hGUI, $tMARGINS)
$tMARGINS = 0
; Creating Drag area to the
Global $Winpos = WinGetPos("MyGUI")
Global $GlassArea = GUICtrlCreateLabel("", (UBound($Pic) + 1) * 90, 0, $Winpos[2] - (UBound($Pic) + 1) * 90, 32) ;area that will be filled with glass
GUICtrlSetBkColor(-1, 0x000000) ; If you use Black color then the color will be the AERO glass effect
; Creating The Tab
$File = GUICtrlCreatePic(@ScriptDir & '\tab_filedefault.bmp', 0, 0, 90, 29)
$Text = GUICtrlCreateLabel("File", 0, 7, 90, 29, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)
For $i = 0 To $Tabnums - 1
    $Pic[$i] = GUICtrlCreatePic($TabDefaultPic, 90 * ($i + 1), 0, 90, 29)
    $TabText[$i] = GUICtrlCreateLabel($TabText[$i], 90 * ($i + 1), 7, 90, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0x000000)
Next
$Tab = GUICtrlCreateTab(-@DesktopWidth, -@DesktopHeight, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateTabItem('File')
GUICtrlCreateButton('File', 290, 319, 70, 23)
GUICtrlCreateTabItem('Home')
GUICtrlCreateButton('Home', 300, 319, 70, 23)
GUICtrlCreateTabItem('Edit')
GUICtrlCreateButton('Edit', 310, 319, 70, 23)
GUICtrlCreateTabItem('View')
GUICtrlCreateButton('View', 320, 319, 70, 23)
GUICtrlCreateTabItem('Program')
GUICtrlCreateButton('Program', 340, 319, 70, 23)
GUICtrlCreateTabItem('Design')
GUICtrlCreateButton('Design', 350, 319, 70, 23)
GUICtrlCreateTabItem('')
; Show window
GUISetState()
; Declare the CheckFlags
Global $CurrentSelected[2] = [$Text, $File]
Global $OldControl[2] = [$Text, $File]
Global $Over = False
#endregion###STARTUP###
While 1
    $Info = GUIGetCursorInfo()
    If Not @error Then
        If $Over And $Info[4] <> $OldControl[0] Then
            Select
                Case $CurrentSelected[0] = $OldControl[0]
                    $Over = Not $Over
                Case $OldControl[1] = $File
                    GUICtrlSetImage($OldControl[1], @ScriptDir & '\tab_filedefault.bmp')
                    $Over = Not $Over
                Case Else
                    GUICtrlSetImage($OldControl[1], $TabDefaultPic)
                    $Over = Not $Over
            EndSelect
        EndIf
        $Index = _Index($Info[4])
        Switch $Info[4]
            Case $TabText[$Index]
                If Not $Over Then
                    GUICtrlSetImage($Pic[$Index], @ScriptDir & '\tab_hover.bmp')
                    $Over = Not $Over
                    $OldControl[0] = $Info[4]
                    $OldControl[1] = $Pic[$Index]
                EndIf
            Case $Text
                If Not $Over Then
                    GUICtrlSetImage($File, @ScriptDir & '\tab_filehover.bmp')
                    $Over = Not $Over
                    $OldControl[0] = $Info[4]
                    $OldControl[1] = $File
;~                  $CurrentSelected = $File
                EndIf
        EndSwitch
    EndIf
    $Msg = GUIGetMsg()
    $Index = _Index($Msg, False) ;I added a parameter.
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic[$Index]
            Select
                Case $CurrentSelected[1] = $File
                    GUICtrlSetImage($CurrentSelected[1], @ScriptDir & '\tab_filedefault.bmp')
                Case Else
                    GUICtrlSetImage($CurrentSelected[1], $TabDefaultPic)
            EndSelect
            GUICtrlSetImage($Msg, @ScriptDir & '\tab_selected.bmp')
            GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Index + 1, 0)
            $CurrentSelected[0] = $TabText[$Index]
            $CurrentSelected[1] = $Pic[$Index]
        Case $File
            GUICtrlSetImage($CurrentSelected[1], $TabDefaultPic)
            GUICtrlSetImage($Msg, @ScriptDir & '\tab_fileselected.bmp')
            GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, 0, 0)
        Case $GlassArea
            DllCall("user32.dll", "int", "SendMessage", "hWnd", $hGUI, "int", 0xA1, "int", 2, "int", 0)
    EndSwitch
WEnd
Func _Index($CtrlID, $flag = True) ; One parameter is for the hover funtion applied to the labels the other is for GuiGetMsg applied to the pics
    If $flag Then
        For $i = 0 To UBound($TabText) - 1
            If $CtrlID = $TabText[$i] Then Return $i
        Next
    Else
        For $i = 0 To UBound($Pic) - 1
            If $CtrlID = $Pic[$i] Then Return $i
        Next
    EndIf
    Return ""
EndFunc   ;==>_Index

PD: I use the _WinAPI_DwmExtendFrameIntoClientArea() function founded in the WinAPIEx UDF here in the forum.

Edited by monoscout999

Share this post


Link to post
Share on other sites

Thankyou. I have to say that I tried that winapi function once but it didnt work. with $tmargins, are you actually creating an array, and then addin on to it? Thanks.

Anyway, as for the running, it runs nearly seamlessly. The biggest problem is that every now and then, it does not rollover on hover, but it is atleast, much better than my code :). But still, thanks.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thankyou. I have to say that I tried that winapi function once but it didnt work. with $tmargins, are you actually creating an array, and then addin on to it? Thanks.

It is an Structure, is an organized way to handle different variables for a function. Usually functions uses Structures instead arrays. Look in MSDN for that function and you will see the entire description for the function and a link to see the description of the structure.

Anyway, as for the running, it runs nearly seamlessly. The biggest problem is that every now and then, it does not rollover on hover, but it is atleast, much better than my code :). But still, thanks.

The flags checks issue is always an issue in the scripts, how to control the times that a loop pass over certain point, or when it have to do something or not, it is a big headache! ;) Edited by monoscout999

Share this post


Link to post
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
Sign in to follow this  
Followers 0