Jump to content
wuruoyu

"File" menu is highlighted when switching tab

Recommended Posts

wuruoyu

When switching tab, the "File" menu is highlighted just like when pressing the "ALT" key on keyboard (especially when I keep holding down the left click on the tab). Is there anyway to avoid the "File" menu being highlighted when switching tab and retain the accelerator "ALT" when press "ALT" key on keyboard. Thanks in advance!

I know this is not the standard way to setup tab control, but have to use this method to fix other issues I have had:

*Seems like ALT is being triggered when GUISetState(@SW_HIDE) or GUISetState(@SW_SHOW) is used in my case

#NoTrayIcon
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <EditConstants.au3>
#include <GUIToolbar.au3>
#include <GUIImageList.au3>
#include <WinAPITheme.au3>

Opt("GUIOnEventMode", 1)

Global $tab, $currentTab, $pageOneGUI, $pageTwoGUI
Global $idInput1P2, $idInput2P2, $idInput3P2

_main()

Func _main()
    $main = GUICreate("main", 368, 363, -1, -1, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    GUISetState()
    
    Local $idFilemenu = GUICtrlCreateMenu("&File")
    Local $idFileitem = GUICtrlCreateMenuItem("Open", $idFilemenu)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    Local $idHelpmenu = GUICtrlCreateMenu("?")
    GUICtrlCreateMenuItem("Save", $idFilemenu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local $idInfoitem = GUICtrlCreateMenuItem("Info", $idHelpmenu)
    Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
    Local $idRecentfilesmenu = GUICtrlCreateMenu("Recent Files", $idFilemenu, 1)

    $ToolbarGUI = GUICreate('', 350, 62, 1, 1, $WS_CHILD, 0, $main)
    $Toolbar = _GUICtrlToolbar_Create($ToolbarGUI, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER)
    $ToolbarImageList = _GUIImageList_Create(32, 32, 5, 1)
    _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\mmc.exe", 0, 1)
    _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\cmd.exe", 0, 1)
    _GUICtrlToolbar_SetImageList($Toolbar, $ToolbarImageList)
    _GUICtrlToolbar_AddString($Toolbar, 'MMC')
    _GUICtrlToolbar_AddString($Toolbar, 'CMD')
    _GUICtrlToolbar_AddButton($Toolbar, 10000, 0, 0)
    _GUICtrlToolbar_AddButton($Toolbar, 10001, 1, 1)
    _GUICtrlToolbar_SetButtonSize($Toolbar, 62, 50)
    _GUICtrlToolbar_SetMetrics($Toolbar, 0, 0, 1, 0)
    _GUICtrlToolbar_SetIndent($Toolbar, 1)
    _SendMessage($Toolbar, $TB_AUTOSIZE)

    GUISwitch($main)

    GUICtrlCreateLabel('', 0, 63, 368, 2, $SS_ETCHEDHORZ)
    GUICtrlCreateButton("button", 248, 313, 100, 20, -1, -1)

    $pageOneGUI = GUICreate("", 352, 198, 9, 93, $WS_CHILD,-1, $main)
    ;GUISetBkColor(0xCCFFCC)
    GUICtrlCreateGroup("Group", 6, 3, 341, 180, -1, -1)
    GUICtrlCreateEdit("this is an edit control", 15, 40, 325, 67, BitOR($ES_READONLY, $WS_VSCROLL), $WS_EX_CLIENTEDGE)
    GUICtrlCreateInput("This is an inputbox", 15, 130, 325, 20, -1, $WS_EX_CLIENTEDGE)

    $pageTwoGUI = GUICreate("", 352, 198, 9, 93, $WS_CHILD,-1, $main)
    ;GUISetBkColor(0xCCFFCC)
    $idInput1P2 = GUICtrlCreateInput("This is an inputbox", 15, 070, 325, 20, -1, $WS_EX_CLIENTEDGE)
    $idInput2P2 = GUICtrlCreateInput("This is an inputbox", 15, 100, 325, 20, -1, $WS_EX_CLIENTEDGE)
    $idInput3P2 = GUICtrlCreateInput("This is an inputbox", 15, 130, 325, 20, -1, $WS_EX_CLIENTEDGE)

    GUISwitch($main)
    $tab = GUICtrlCreateTab(4, 70, 363, 226, -1, -1)
    GUICtrlSetOnEvent($Tab, "_tabChangeDetected")
    GUICtrlCreateTabItem("Page 1")
    GUICtrlCreateTabItem("Page 2")
    GUICtrlCreateTabItem("")
    _WinAPI_SetWindowTheme(GUICtrlGetHandle( $tab ), "", "")

    $currentTab = _GUICtrlTab_GetCurFocus($tab)

    $idTabKeyP2 = GUICtrlCreateDummy()
    GUICtrlSetOnEvent( $idTabKeyP2, "TabKeyP2" )
    Local $aAccelKeys[1][2] = [["{Tab}", $idTabKeyP2]]
    GUISetAccelerators($aAccelKeys)

    GUISetState(@SW_SHOWNOACTIVATE, $ToolbarGUI)
    GUISetState(@SW_SHOW, $main)

    _GUICtrlTab_SetCurFocus($tab, 0)

    While 1
        Sleep(100)
    WEnd
EndFunc   ;==>_main

Func TabKeyP2()
  Switch _WinAPI_GetDlgCtrlID( ControlGetHandle( $pageTwoGUI, "", ControlGetFocus( $pageTwoGUI ) ) )
    Case $idInput1P2
      ControlFocus( $pageTwoGUI, "", $idInput2P2 )
    Case $idInput2P2
      ControlFocus( $pageTwoGUI, "", $idInput3P2 )
    Case $idInput3P2
      ControlFocus( $pageTwoGUI, "", $idInput1P2 )
    Case Else
  EndSwitch
EndFunc

Func _exit()
    Exit
EndFunc   ;==>_exit

Func _tabChangeDetected()
    If _GUICtrlTab_GetCurFocus($tab) <> $currentTab Then
        $currentTab = _GUICtrlTab_GetCurFocus($tab)
        ;MsgBox(0, "", $currentTab)
        Switch $currentTab
            Case 0
                GUISetState(@SW_HIDE,$pageTwoGUI)
                GUISetState(@SW_SHOW,$pageOneGUI)
            Case 1
                GUISetState(@SW_HIDE,$pageOneGUI)
                GUISetState(@SW_SHOW,$pageTwoGUI)
        EndSwitch
    EndIf
EndFunc   ;==>_tabChangeDetected

 

 

Screen Shot 2017-10-13 at 11.05.18 AM.png

Edited by wuruoyu

Share this post


Link to post
Share on other sites
wuruoyu

Bump

Share this post


Link to post
Share on other sites
SmOke_N

I can see this happening when you're using hide method because you're not focusing on that GUI any longer, now it's shifted back to the main gui before focus is again giving to the alternate page GUI.

I'm curious, if you put say Sleep(100) between the hide and show in the tab changed detected function... do you still get the same result?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
wuruoyu

Thank you for your reply, SmOke_N.

I tried adding Sleep(100) between the hide and show, it's the same result.

Share this post


Link to post
Share on other sites
mLipok

Offtopic:  Nice to see you again @SmOke_N 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
SmOke_N

Have you tried using controlhide/show instead?  I can't replicate it, on mine,  it highlights as expected then when the new GUI is given show state the highlight goes away as expected.

 

eg..

Func _tabChangeDetected()
    If _GUICtrlTab_GetCurFocus($tab) <> $currentTab Then
        $currentTab = _GUICtrlTab_GetCurFocus($tab)
        ;MsgBox(0, "", $currentTab)
        Switch $currentTab
            Case 0
                ControlHide($main, "", $pageTwoGUI)
                ControlShow($main, "", $pageOneGUI)
;~                 GUISetState(@SW_HIDE,$pageTwoGUI)
;~                 GUISetState(@SW_SHOW,$pageOneGUI)
            Case 1
                ControlHide($main, "", $pageOneGUI)
                ControlShow($main, "", $pageTwoGUI)
;~                 GUISetState(@SW_HIDE,$pageOneGUI)
;~                 GUISetState(@SW_SHOW,$pageTwoGUI)
        EndSwitch
    EndIf
EndFunc   ;==>_tabChangeDetected

 

Edit:

@mLipok hope you're doing well!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
mLipok
1 hour ago, SmOke_N said:

@mLipok hope you're doing well!

Thanks, apart from lack of sleep and money I do not complain ;)

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
wuruoyu

@SmOke_N Thank you so much for the fix, it works!

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

×