laroald Posted October 11, 2004 Share Posted October 11, 2004 I need some help to complete my program for registrate the quality of my last night Sleep. Due to a surgery in my brain I have fundamental problem with my sleep. For optimal treatment it's a big advantage to present a time series for the doctor. 1. At what time I went to bed 2 Switched of the light 3. Felt into Sleep 4. At what time I woke up, and finally 5. When I stood up. Yesterday I managed to link AutoIt to my MySQL database by "sqlcmd.exe " - as I discovered at this forum. A nice experience. Just to lines at the bottom of the script (Dim... and Run.....) Now I have a rather simple problem: As you can see in this amputated script (total 500 lines) - I'm using a tab control. The idea is to make individual buttons for every 10 minutes. After pressing the first button, e.g. I went to bed 23.40, then I want to jump over to the next tabitem "Switched off the light..". I have managed to make a for the first button, 22.00. MsgBox(0,"", "22.00 has been clicked") How can I change this over to activate the tabitem instead? Finally: does anybody have a good idea how I should organize the buttons? The way I do it here is not optimal. A circle, like a whatch, would have been much better. Six buttons pr hour, from 23.00 until 03.00 at the first tab. As soon as I press the first button I would like to get another GUI where the button I pressed is the first one, and then further 12, 18, 24 buttons - for registrate when I swithced of the light. And so on. I hope someone have some tips about these challenges. best regards Lasse Roan ***************************** This script is amputated, but It funk - as long at you're using just the 22.00 -button. #include <C:\Programfiler\AutoIt30\Include\GUIConstants.au3> Opt("GUICoordMode", 1) GUICreate("Quality of sleep", 900,700,) GUISetBkColor(0x00FFFFE0) ; Create the controls GUICtrlCreateLabel("The night before ", 550,11,35 ,24,0x0002) $date = GUICtrlCreateDate ("Date1", 600,5, 150,24,) $Registrert = GUICtrlCreateButton("&Registrert", 230, 650, 120, 40) ; start creation of a tab control GUICtrlCreateTab ( 20, 20, 500, 200) GUICtrlSetFont(-1,9,700) ; to display tab names in bold ; define first tab name $tab0=GUICtrlCreateTabitem ("Went to bed..") ;La meg-knapper: $button_sl220 = GUICtrlCreateButton( "22.00", 55, 50, 60, 24, 0x0001) $button_sl221 = GUICtrlCreateButton( "22.10", 70, 75, 45, 24, 0x0001) $button_sl222 = GUICtrlCreateButton( "22.20", 70, 100, 45, 24, 0x0001) $button_sl223 = GUICtrlCreateButton("22.30", 70, 125, 45, 24, 0x0001) $button_sl224 = GUICtrlCreateButton("22.40", 70, 150, 45, 24, 0x0001) $button_sl225 = GUICtrlCreateButton("22.50", 70, 175, 45, 24, 0x0001) ;$button_sl230 = GUICtrlCreateButton("23.00", 105, 50, 60, 24, 0x0001) ;$button_sl231 = GUICtrlCreateButton("23.10", 120, 75, 45, 24, 0x0001) ;$button_sl232 = GUICtrlCreateButton("23.20", 120, 100, 45, 24, 0x0001) ;$button_sl233 = GUICtrlCreateButton("23.30", 120, 125, 45, 24, 0x0001) ;$button_sl234 = GUICtrlCreateButton("23.40", 120, 150, 45, 24, 0x0001) ;$button_sl235 = GUICtrlCreateButton("23.50", 120, 175, 45, 24, 0x0001) ;etc etc.... ;$button_sl043 = GUICtrlCreateButton("04.30", 380, 125, 45, 24, 0x0001) ;$button_sl044 = GUICtrlCreateButton("04.40", 380, 150, 45, 24, 0x0001) ;$button_sl045 = GUICtrlCreateButton("04.50", 380, 175, 45, 24, 0x0001) ; define second tab name $tab1=GUICtrlCreateTabitem ("Switched off the light..") ;$button_s220 = GUICtrlCreateButton( "22.00", 55, 50, 60, 24, 0x0001) ;$button_s221 = GUICtrlCreateButton( "22.10", 70, 75, 45, 24, 0x0001) ;$button_s222 = GUICtrlCreateButton( "22.20", 70, 100, 45, 24, 0x0001) ;etc etc.... $LaMeg = 0 $LysAv=0; We will assume 0 = first radio button selected, 2 = last button $Sovna= 0 $Vokna= 0 $dato="Natt til idag:" ;GuiShow() GUISetState (@SW_SHOW) ; In this message loop we use vari $msg = 0 While $msg <> -3 $msg = GUIGetMsg() Select Case $msg = -3 Exit Case $msg=$date $dato=GUIRead($date) Case $msg = $button_sl220 $LaMeg ="22.00" MsgBox(0,"", "22.00 has been clicked") Case $msg = $button_sl221 $LaMeg ="22.10" Case $msg = $button_sl222 $LaMeg ="22.20" Case $msg = $button_sl223 $LaMeg ="22.30" Case $msg = $button_sl224 $LaMeg ="22.40" Case $msg = $button_sl225 $LaMeg ="22.50" ;etc.. etc... Dim $sql ="INSERT INTO feil (Navn) VALUES('"&$dato&"')" Run ('sqlcmd.exe /db "Feilreg" /user "root" /append /command "' & $sql & '"','',@SW_MINIMIZE) EndSelect WEnd ;GUIWaitClose() ; wait dialog closing ;denne også nullstillte eg -men det gjekk utan! GUIDelete(); ; will return 1 ExitS_vnregistrering2.au3 Lars RoanBergen, Norway Link to comment Share on other sites More sharing options...
SlimShady Posted October 11, 2004 Share Posted October 11, 2004 (edited) Allright. First change:GUICtrlCreateTab ( 20, 20, 500, 200)to$Tabs = GUICtrlCreateTab ( 20, 20, 500, 200)And add $TCM_SETCURSEL = 0x0000130C somewhere.Aftter doing that, you can activate a tab usingGUISendMsg($Tabs, $TCM_SETCURSEL, 0, 0)Change the 3rd parameter for the tab you want to activate (0 = first tab, 1 = second tab)Attached is a working example. Edited October 11, 2004 by SlimShady Link to comment Share on other sites More sharing options...
jpm Posted October 11, 2004 Share Posted October 11, 2004 Allright. First change:GUICtrlCreateTab ( 20, 20, 500, 200)to$Tabs = GUICtrlCreateTab ( 20, 20, 500, 200)And add $TCM_SETCURSEL = 0x0000130C somewhere.Aftter doing that, you can activate a tab usingGUISendMsg($Tabs, $TCM_SETCURSEL, 0, 0)Change the 3rd parameter for the tab you want to activate (0 = first tab, 1 = second tab)Attached is a working example.<{POST_SNAPBACK}> GuiCtrlSetState ($tabitem,$GUI_SHOW) should work Link to comment Share on other sites More sharing options...
laroald Posted October 11, 2004 Author Share Posted October 11, 2004 (edited) GuiCtrlSetState ($tabitem,$GUI_SHOW) should work <{POST_SNAPBACK}>Thank's for helping me to solve this challenge.I have made this changes. But now I am facing another problem. When I press the first button 22.00 (where I have placed this code; GUISendMsg($Tabs, $TCM_SETCURSEL, 1, 0)-then the buttons at this tab doesn't funk. When I use the final button for registration, the value for "switched the light off" then it keep the standard value; 0.If I jump over to the third tab, registrate a time there, and then goes back to the second folder, then I succeed to registrate a time in the second tab. Any Idea what's wrong?I add the whole file.Thanks!S_vnregistrering.au3 Edited October 11, 2004 by laroald Lars RoanBergen, Norway Link to comment Share on other sites More sharing options...
SlimShady Posted October 11, 2004 Share Posted October 11, 2004 (edited) I tried the GUISendMsg function and noticed that it doesn't work as expected. And I tried GuiCtrlSetState ($tabitem,$GUI_SHOW), that doesn't work at all. But the ControlCommand function works. Here it is: ControlCommand("", "", "SysTabControl321", "TabRight", "") Edited October 11, 2004 by SlimShady Link to comment Share on other sites More sharing options...
laroald Posted October 13, 2004 Author Share Posted October 13, 2004 ControlCommand("", "", "SysTabControl321", "TabRight", "") funks! Perfect. By this way we're loosing the opportunity to jump to other tabs than the next Left/Right. I need a special tab for registrating my use of drug, if I woke up and then fell back to sleep. e.g. $tab3 instead of "TabRight" doesn't work. Two other challenges: -Is it possible to change the background colour of each tab? Because I am using a lot of buttons on each tab, they're in the same position in all the tabs, different colours will distinguish much better the different tabs. -Are there any way to change the font (bold) or the colour of the button I have pressed in the first tab. And then bring this information over to the next tabs. So that I all the time can see which buttons I've already been pressed. Thank you for helping me, Lars Roan, Bergen, NorwayS_vnregistrering.au3 Lars RoanBergen, Norway Link to comment Share on other sites More sharing options...
SlimShady Posted October 13, 2004 Share Posted October 13, 2004 To switch to tab # 3 use the function twice. Example: ControlCommand("", "", "SysTabControl321", "TabRight", "") ControlCommand("", "", "SysTabControl321", "TabRight", "") I tried some things and I found out that: - you can't change the back color of a tab - you can't change the (back) color of a button BUT you can bold the text on a button: GUICtrlSetFont($msg, 9, 800) Link to comment Share on other sites More sharing options...
laroald Posted October 13, 2004 Author Share Posted October 13, 2004 Thanks SlimShady! This is perfect. The same command twice, of course; ControlCommand("", "", "SysTabControl321", "TabRight", "") ControlCommand("", "", "SysTabControl321", "TabRight", "") And yeah, by GUICtrlSetFont($msg, 9, 800) it's possible to bold the text. Now my program is on away to funk well. Thanks to useful advice by kind helpers. Next week I will present this program to the doctor. There are many others who's got problem with their sleep. Let's hope this could be useful also for others. best reg Lars Roan Lars RoanBergen, Norway Link to comment Share on other sites More sharing options...
SumTingWong Posted October 13, 2004 Share Posted October 13, 2004 (edited) You can also use DllCall to select a tab by its index. Example: Global $TCM_SETCURFOCUS = 0x1330 Global $TCM_SETCURSEL = 0x130C $hWnd = ControlGetHandle("", "", "SysTabControl321") DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $hWnd, _ "int", $TCM_SETCURFOCUS, _ "int", 3, _ "long", 0) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $hWnd, _ "int", $TCM_SETCURSEL, _ "int", 3, _ "long", 0) The third param is the zero-based tab index. I think you also need the latest GUI unstable to get the ControlGetHandle function. @Jon, is it possible to add this to ControlCommand? e.g ControlCommand ( "title", "text", "classnameNN", "SelectTab", <tabindex> ) Edited October 13, 2004 by pacman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now