Advertisement
Guest User

Untitled

a guest
Jun 28th, 2012
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2. #Include, Rini.ahk
  3.  
  4. OnMessage(0x115, "OnScroll") ; WM_VSCROLL
  5. OnMessage(0x114, "OnScroll") ; WM_HSCROLL
  6.  
  7. Gui, +Resize +0x300000 ; WS_VSCROLL | WS_HSCROLL
  8.  
  9. RIni_Read("Config", "Config.ini")
  10. Secs := RIni_GetSections("Config", "|")
  11. Gui, Add, Tab, AltSubmit gTab vTabbing w300 h600, %Secs%
  12. If InStr(Secs, "|")
  13. {
  14.    Loop, Parse, Secs, |
  15.    {
  16.       KeyNum := A_Index
  17.       Section := A_LoopField
  18.       Gui, Tab, %A_Index%
  19.       Keys := RIni_GetSectionKeys("Config",Section)
  20.       Loop, Parse, Keys, `,
  21.       {
  22.          IniRead, Val, Config.ini, %Section%, %A_LoopField%
  23.          Gui, Add, Text,, %A_LoopField%
  24.          If (!Val || Val = 1)
  25.          {
  26.             Gui, Add, CheckBox, v%Section%_%A_LoopField% Checked%Val%
  27.             ConHeight%KeyNum% += 43
  28.          }
  29.          Else
  30.          {
  31.             Gui, Add, Edit, v%Section%_%A_LoopField%, %Val%
  32.             ConHeight%KeyNum% += 46.3
  33.          }
  34.       }
  35.       ConHeight .= ConHeight%KeyNum% "`n"
  36.    }
  37. }
  38. Else
  39. {
  40.    Section := Secs
  41.    Gui, Tab, 1
  42.    Keys := RIni_GetSectionKeys("Config",Section)
  43.    Loop, Parse, Keys, `,
  44.    {
  45.       IniRead, Val, Config.ini, %Section%, %A_LoopField%
  46.       Gui, Add, Text,, %A_LoopField%
  47.       If (!Val || Val = 1)
  48.          Gui, Add, CheckBox, v%Section%_%A_LoopField% Checked%Val%
  49.       Else
  50.          Gui, Add, Edit, v%Section%_%A_LoopField%, %Val%
  51.    }
  52. }
  53. Gui, Tab
  54. Gui, Add, Button, % "vButton gSubmit y" ConHeight1 + 50 " xm", Save Changes
  55. GuiControl, Move, Tabbing, % "H" ConHeight1 + 35
  56. Gui, Show,, Ini Editor
  57. Gui, +LastFound
  58. GroupAdd, MyGui, % "ahk_id " . WinExist()
  59. Return
  60.  
  61. Submit:
  62. Gui, Submit
  63. If InStr(Secs, "|")
  64. {
  65.    Loop, Parse, Secs, |
  66.    {
  67.       Section := A_LoopField
  68.       Keys := RIni_GetSectionKeys("Config",Section)
  69.       Loop, Parse, Keys, `,
  70.          IniWrite, % %Section%_%A_LoopField%, Config.ini, %Section%, %A_LoopField%
  71.    }
  72. }
  73. Else
  74. {
  75.    Section := Secs
  76.    Gui, Tab, 1
  77.    Keys := RIni_GetSectionKeys("Config",Section)
  78.    Loop, Parse, Keys, `,
  79.       IniWrite, % %Section%_%A_LoopField%, Config.ini, %Section%, %A_LoopField%
  80. }
  81. ExitApp
  82.  
  83. GuiSize:
  84.     UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
  85. return
  86.  
  87. GuiClose:
  88. ExitApp
  89.  
  90. #IfWinActive ahk_group MyGui
  91. WheelUp::
  92. WheelDown::
  93. +WheelUp::
  94. +WheelDown::
  95.     ; SB_LINEDOWN=1, SB_LINEUP=0, WM_HSCROLL=0x114, WM_VSCROLL=0x115
  96.     OnScroll(InStr(A_ThisHotkey,"Down") ? 1 : 0, 0, GetKeyState("Shift") ? 0x114 : 0x115, WinExist())
  97. return
  98. #IfWinActive
  99.  
  100. UpdateScrollBars(GuiNum, GuiWidth, GuiHeight)
  101. {
  102.     static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1
  103.    
  104.     Gui, %GuiNum%:Default
  105.     Gui, +LastFound
  106.    
  107.     ; Calculate scrolling area.
  108.     Left := Top := 9999
  109.     Right := Bottom := 0
  110.     WinGet, ControlList, ControlList
  111.     Loop, Parse, ControlList, `n
  112.     {
  113.         GuiControlGet, c, Pos, %A_LoopField%
  114.         if (cX < Left)
  115.             Left := cX
  116.         if (cY < Top)
  117.             Top := cY
  118.         if (cX + cW > Right)
  119.             Right := cX + cW
  120.         if (cY + cH > Bottom)
  121.             Bottom := cY + cH
  122.     }
  123.     Left -= 8
  124.     Top -= 8
  125.     Right += 8
  126.     Bottom += 8
  127.     ScrollWidth := Right-Left
  128.     ScrollHeight := Bottom-Top
  129.    
  130.     ; Initialize SCROLLINFO.
  131.     VarSetCapacity(si, 28, 0)
  132.     NumPut(28, si) ; cbSize
  133.     NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
  134.    
  135.     ; Update horizontal scroll bar.
  136.     NumPut(ScrollWidth, si, 12) ; nMax
  137.     NumPut(GuiWidth, si, 16) ; nPage
  138.     DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1)
  139.    
  140.     ; Update vertical scroll bar.
  141. ;     NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
  142.     NumPut(ScrollHeight, si, 12) ; nMax
  143.     NumPut(GuiHeight, si, 16) ; nPage
  144.     DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &si, "int", 1)
  145.    
  146.     if (Left < 0 && Right < GuiWidth)
  147.         x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left)
  148.     if (Top < 0 && Bottom < GuiHeight)
  149.         y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top)
  150.     if (x || y)
  151.         DllCall("ScrollWindow", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0)
  152. }
  153.  
  154. OnScroll(wParam, lParam, msg, hwnd)
  155. {
  156.     static SIF_ALL=0x17, SCROLL_STEP=10
  157.    
  158.     bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
  159.    
  160.     VarSetCapacity(si, 28, 0)
  161.     NumPut(28, si) ; cbSize
  162.     NumPut(SIF_ALL, si, 4) ; fMask
  163.     if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
  164.         return
  165.    
  166.     VarSetCapacity(rect, 16)
  167.     DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
  168.    
  169.     new_pos := NumGet(si, 20) ; nPos
  170.    
  171.     action := wParam & 0xFFFF
  172.     if action = 0 ; SB_LINEUP
  173.         new_pos -= SCROLL_STEP
  174.     else if action = 1 ; SB_LINEDOWN
  175.         new_pos += SCROLL_STEP
  176.     else if action = 2 ; SB_PAGEUP
  177.         new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP
  178.     else if action = 3 ; SB_PAGEDOWN
  179.         new_pos += NumGet(rect, 12, "int") - SCROLL_STEP
  180.     else if (action = 5 || action = 4) ; SB_THUMBTRACK || SB_THUMBPOSITION
  181.         new_pos := wParam>>16
  182.     else if action = 6 ; SB_TOP
  183.         new_pos := NumGet(si, 8, "int") ; nMin
  184.     else if action = 7 ; SB_BOTTOM
  185.         new_pos := NumGet(si, 12, "int") ; nMax
  186.     else
  187.         return
  188.    
  189.     min := NumGet(si, 8, "int") ; nMin
  190.     max := NumGet(si, 12, "int") - NumGet(si, 16) ; nMax-nPage
  191.     new_pos := new_pos > max ? max : new_pos
  192.     new_pos := new_pos < min ? min : new_pos
  193.    
  194.     old_pos := NumGet(si, 20, "int") ; nPos
  195.    
  196.     x := y := 0
  197.     if bar = 0 ; SB_HORZ
  198.         x := old_pos-new_pos
  199.     else
  200.         y := old_pos-new_pos
  201.     ; Scroll contents of window and invalidate uncovered area.
  202.     DllCall("ScrollWindow", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
  203.    
  204.     ; Update scroll bar.
  205.     NumPut(new_pos, si, 20, "int") ; nPos
  206.     DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
  207. }
  208.  
  209. Tab:
  210. Gui, Submit, NoHide
  211. GuiControl, Move, Tabbing, % "H" ConHeight%Tabbing% + 35
  212. GuiControl, Move, Button, % "Y" ConHeight%Tabbing% + 50
  213. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement