Advertisement
08wckster08

Untitled

May 4th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; GLOBAL SETTINGS ===============================================================================================================
  2.  
  3. #NoEnv
  4. #SingleInstance Force
  5. SetBatchLines -1
  6.  
  7. OnMessage(0x0201, "WM_LBUTTONDOWN")
  8.  
  9. ; ===============================================================================================================================
  10. Gui, Add, GroupBox,     x10  y10   w200 h80  Section                           , % "Radio"
  11. Gui, Add, Radio,        x18  ys+20           Checked                           , % "Radio1 "
  12. Gui, Add, Radio,        x18  y+5                                               , % "Radio 2"
  13. Gui, Add, Radio,        x18  y+5             +0x8000000                        , % "Radio 3"
  14. ; ===============================================================================================================================
  15. Gui, Add, GroupBox,     x215 y10   w200 h80  Section                           , % "Checkbox"
  16. Gui, Add, Checkbox,     x223 ys+20           Checked                           , % "Checkbox 1"
  17. Gui, Add, Checkbox,     x223 y+5                                               , % "Checkbox 2"
  18. Gui, Add, Checkbox,     x223 y+5             +0x8000000                        , % "Checkbox 3"
  19. ; ===============================================================================================================================
  20. Gui, Add, GroupBox,     x10  y95   w200 h100 Section                           , % "Text"
  21. Gui, Add, Text,         x18  ys+20 w180 h21  0x200                             , % "Text 1"
  22. Gui, Add, Text,         x18  y+5   w180 h21  0x201 border                      , % "Text 2"
  23. Gui, Add, Text,         x18  y+5   w180 h21  0x202                             , % "Text 3"
  24. ; ===============================================================================================================================
  25. Gui, Add, GroupBox,     x215 y95   w200 h100 Section                           , % "Edit"
  26. Gui, Add, Edit,         x223 ys+20 w180      hwndEdit1                         ,
  27. DllCall("user32.dll\SendMessage", "Ptr", Edit1, "UInt", 0x1501, "Ptr", True, "Str", "Placeholder", "Ptr")
  28. Gui, Add, Edit,         x223 y+5   w180      0x800                             , % "Edit 2"
  29. Gui, Add, Edit,         x223 y+5   w180      hwndEdit3                         , % "Edit 3"
  30. CtlColors.Attach(Edit3, "FA675F", "FFFFFF")
  31. ; ===============================================================================================================================
  32. Gui, Add, GroupBox,     x420 y10   w200 h185 Section                           , % "TreeView"
  33. Gui, Add, TreeView,     x428 ys+20 w180 r9
  34. P1     := TV_Add("First parent")
  35. P1C1   := TV_Add("Parent 1's first child", P1)
  36. P2     := TV_Add("Second parent")
  37. P2C1   := TV_Add("Parent 2's first child", P2)
  38. P2C2   := TV_Add("Parent 2's second child", P2)
  39. P2C2C1 := TV_Add("Child 2's first child", P2C2)
  40. ; ===============================================================================================================================
  41. Gui, Add, GroupBox,     x625 y10   w200 h185 Section                           , % "MonthCalc"
  42. Gui, Add, MonthCal,     x633 ys+20
  43. ; ===============================================================================================================================
  44. Gui, Add, GroupBox,     x830  y10    w200 h490 Section                         , % "Rect / Frame / Etched / Sunken"
  45. Gui, Add, Text,         x838  ys+20  w75  h1   0x4                             ; Horizontal Line (small)   >   SS_BLACKRECT
  46. Gui, Add, Text,         x838  y+2    w75  h5   0x4                             ; Horizontal Line (big)     >   SS_BLACKRECT
  47. Gui, Add, Text,         x838  y+2    w1   h75  0x4                             ; Vertical   Line (small)   >   SS_BLACKRECT
  48. Gui, Add, Text,         x841  yp     w5   h75  0x4                             ; Vertical   Line (big)     >   SS_BLACKRECT
  49. Gui, Add, Text,         x948  ys+20  w75  h7   0x7                             ; Horizontal Frame          >   SS_BLACKFRAME
  50. Gui, Add, Text,         x948  y+2    w7   h75  0x7                             ; Vertical   Frame          >   SS_BLACKFRAME
  51. Gui, Add, Text,         x838  ys+115 w75  h1   0x5                             ; Horizontal Line (small)   >   SS_GRAYRECT
  52. Gui, Add, Text,         x838  y+2    w75  h5   0x5                             ; Horizontal Line (big)     >   SS_GRAYRECT
  53. Gui, Add, Text,         x838  y+2    w1   h75  0x5                             ; Vertical   Line (small)   >   SS_GRAYRECT
  54. Gui, Add, Text,         x841  yp     w5   h75  0x5                             ; Vertical   Line (big)     >   SS_GRAYRECT
  55. Gui, Add, Text,         x948  ys+115 w75  h7   0x8                             ; Horizontal Frame          >   SS_GRAYFRAME
  56. Gui, Add, Text,         x948  y+2    w7   h75  0x8                             ; Vertical   Frame          >   SS_GRAYFRAME
  57. Gui, Add, Text,         x838  ys+210 w75  h1   0x6                             ; Horizontal Line (small)   >   SS_WHITERECT
  58. Gui, Add, Text,         x838  y+2    w75  h5   0x6                             ; Horizontal Line (big)     >   SS_WHITERECT
  59. Gui, Add, Text,         x838  y+2    w1   h75  0x6                             ; Vertical   Line (small)   >   SS_WHITERECT
  60. Gui, Add, Text,         x841  yp     w5   h75  0x6                             ; Vertical   Line (big)     >   SS_WHITERECT
  61. Gui, Add, Text,         x948  ys+210 w75  h7   0x9                             ; Horizontal Frame          >   SS_WHITEFRAME
  62. Gui, Add, Text,         x948  y+2    w7   h75  0x9                             ; Vertical   Frame          >   SS_WHITEFRAME
  63. Gui, Add, Text,         x838  ys+305 w75  h1   0x10                            ; Horizontal Line (small)   >   SS_ETCHEDHORZ
  64. Gui, Add, Text,         x838  y+8    w1   h75  0x11                            ; Vertical   Line (small)   >   SS_ETCHEDVERT
  65. Gui, Add, Text,         x948  ys+305 w75  h7   0x12                            ; Horizontal Frame          >   SS_ETCHEDFRAME
  66. Gui, Add, Text,         x948  y+2    w7   h75  0x12                            ; Vertical   Frame          >   SS_ETCHEDFRAME
  67. Gui, Add, Text,         x838  ys+400 w75  h1   0x1000                          ; Horizontal Line (small)   >   SS_SUNKEN
  68. Gui, Add, Text,         x838  y+8    w1   h75  0x1000                          ; Vertical   Line (small)   >   SS_SUNKEN
  69. Gui, Add, Text,         x948  ys+400 w75  h7   0x1000                          ; Horizontal Frame          >   SS_SUNKEN
  70. Gui, Add, Text,         x948  y+2    w7   h75  0x1000                          ; Vertical   Frame          >   SS_SUNKEN
  71. ; ===============================================================================================================================
  72. Gui, Add, GroupBox,     x10  y200  w405 h140 Section                           , % "ListView"
  73. Gui, Add, ListView,     x18  ys+20 w185 r5   LV0x1                             , % "LV 1|LV 2|LV 3"
  74. loop 5
  75.     LV_Add("", "Entry 1", "Entry 2", "Entry 3")
  76. loop 3
  77.     LV_ModifyCol(A_Index, 60)
  78. Gui, Add, ListView,     x223 yp    w185 r5                                     , % "LV 1|LV 2|LV 3"
  79. loop 6
  80.     LV_Add("", "Entry 1", "Entry 2", "Entry 3")
  81. loop 3
  82.     LV_ModifyCol(A_Index, 60)
  83. ; ===============================================================================================================================
  84. Gui, Add, GroupBox,     x420 y200  w405 h140 Section                           , % "ListBox"
  85. Gui, Add, ListBox,      x428 ys+20 w180 r8                                     , % "LB 1|LB 2|LB 3|LB 4|LB 5|LB 6|LB 7|LB 8"
  86. Gui, Add, ListBox,      x633 yp    w180 r8                                     , % "LB 1|LB 2|LB 3||LB 4|LB 5|LB 6|LB 7|LB 8|LB 9"
  87. ; ===============================================================================================================================
  88. Gui, Add, GroupBox,     x10  y345  w200 h100 Section                           , % "DropDownList"
  89. Gui, Add, DropDownList, x18  ys+20                                             , % "DDL 1|DDL 2|DDL 3"
  90. Gui, Add, DropDownList, x18  y+5                                               , % "DDL 1||DDL 2|DDL 3"
  91. Gui, Add, DropDownList, x18  y+5             +0x8000000                        , % "DDL 1||DDL 2|DDL 3"
  92. ; ===============================================================================================================================
  93. Gui, Add, GroupBox,     x215 y345  w200 h100 Section                           , % "ComboBox"
  94. Gui, Add, ComboBox,     x223 ys+20                                             , % "CB 1|CB 2|CB 3"
  95. Gui, Add, ComboBox,     x223 y+5                                               , % "CB 1||CB 2|CB 3"
  96. Gui, Add, ComboBox,     x223 y+5             +0x8000000                        , % "CB 1||CB 2|CB 3"
  97. ; ===============================================================================================================================
  98. Gui, Add, GroupBox,     x420 y345  w200 h100 Section                           , % "Slider"
  99. Gui, Add, Slider,       x428 ys+25 w180                                        , % "33"
  100. Gui, Add, Slider,       x428 y+1   w180      ToolTip -Theme                    , % "66"
  101. ; ===============================================================================================================================
  102. Gui, Add, GroupBox,     x625 y345  w200 h100 Section                           , % "Progress"
  103. Gui, Add, Progress,     x633 ys+25 w150                                        , % "25"
  104. Gui, Add, Progress,     x633 y+5   w150      BackgroundC0C0C0                  , % "50"
  105. Gui, Add, Progress,     x633 y+5   w150      -Smooth                           , % "75"
  106. Gui, Add, Progress,     x+10 ys+25 h58       CE93500 BackgroundC0C0C0 Vertical , % "50"
  107. ; ===============================================================================================================================
  108. Gui, Add, GroupBox,     x10  y450  w270 h50  Section                           , % "Button"
  109. Gui, Add, Button,       x18  ys+20 w80       0x1                               , % "Button 1"
  110. Gui, Add, Button,       x+5  yp    w80                                         , % "Button 2"
  111. Gui, Add, Button,       x+5  yp    w80       +0x8000000                        , % "Button 3"
  112. ; ===============================================================================================================================
  113. Gui, Add, GroupBox,     x285 y450  w270 h50  Section                           , % "DateTime"
  114. Gui, Add, DateTime,     x293 ys+20                                             , % "LongDate"
  115. ; ===============================================================================================================================
  116. Gui, Add, GroupBox,     x560 y450  w170 h50  Section                           , % "Custom (ClassSysIPAddress32)"
  117. Gui, Add, Custom,       x568 ys+20 w150 r1   ClassSysIPAddress32 hwndhIPControl
  118. IPCtrlSetAddress(hIPControl, "127.0.0.1")
  119. ; ===============================================================================================================================
  120. Gui, Add, GroupBox,     x735 y450  w90  h50  Section                           , % "Image"
  121. Gui, Add, Picture,      x750 ys+15           Icon1                             , % "cmd.exe"
  122. ; ===============================================================================================================================
  123. Gui, Add, StatusBar
  124. SB_SetParts(150, 150, 150)
  125. ; ===============================================================================================================================
  126. Gui, Show, AutoSize
  127. Gui, +LastFound
  128. WinSet, Redraw
  129. return
  130.  
  131. ; ===============================================================================================================================
  132.  
  133. WM_LBUTTONDOWN(wParam, lParam)
  134. {
  135.     MouseGetPos,,, MouseWin, ClassNN, 1
  136.     MouseGetPos,,,, CtrlHwnd, 2
  137.     SB_SetText("ClassNN:  " ClassNN, 1)
  138.     SB_SetText("Control hWnd:  " CtrlHwnd, 2)
  139.     SB_SetText("Gui hWnd:  " MouseWin, 3)
  140. }
  141.  
  142. IPCtrlSetAddress(hControl, ipaddress) ; http://ahkscript.org/docs/commands/GuiControls.htm#Custom
  143. {
  144.     static WM_USER := 0x400
  145.     static IPM_SETADDRESS := WM_USER + 101
  146.  
  147.     ; Pack the IP address into a 32-bit word for use with SendMessage.
  148.     ipaddrword := 0
  149.     Loop, Parse, ipaddress, .
  150.         ipaddrword := (ipaddrword * 256) + A_LoopField
  151.     DllCall("user32.dll\SendMessage", "Ptr", hControl, "UInt", IPM_SETADDRESS, "Ptr", 0, "Ptr", ipaddrword, "Ptr")
  152. }
  153.  
  154. Class CtlColors ; by just me
  155. {
  156.     static Attached := {}
  157.     static HandledMessages := {Edit: 0, ListBox: 0, Static: 0}
  158.     static WM_CTLCOLOR := {Edit: 0x0133, ListBox: 0x134, Static: 0x0138}
  159.     static HTML := {AQUA: 0xFFFF00, BLACK: 0x000000, BLUE: 0xFF0000, FUCHSIA: 0xFF00FF, GRAY: 0x808080, GREEN: 0x008000
  160.                 , LIME: 0x00FF00, MAROON: 0x000080, NAVY: 0x800000, OLIVE: 0x008080, PURPLE: 0x800080, RED: 0x0000FF
  161.                 , SILVER: 0xC0C0C0, TEAL: 0x808000, WHITE: 0xFFFFFF, YELLOW: 0x00FFFF}
  162.     static SYSCOLORS := {Edit: "", ListBox: "", Static: ""}
  163.     static ErrorMsg := ""
  164.     static InitClass := CtlColors.ClassInit()
  165.  
  166.     __New() {
  167.         if (This.InitClass == "!DONE!") {
  168.             This["!Access_Denied!"] := True
  169.             return False
  170.         }
  171.     }
  172.  
  173.     __Delete() {
  174.         if This["!Access_Denied!"]
  175.             return
  176.         This.Free()
  177.     }
  178.  
  179.     ClassInit() {
  180.         CtlColors := New CtlColors
  181.         return "!DONE!"
  182.     }
  183.  
  184.     CheckBkColor(ByRef BkColor, Class) {
  185.         This.ErrorMsg := ""
  186.         if (BkColor != "") && !(This.HTML.HasKey(BkColor)) && !(RegExMatch(BkColor, "^[[:xdigit:]]{6}$")) {
  187.             This.ErrorMsg := "Invalid parameter BkColor: " . BkColor
  188.             return False
  189.         }
  190.         BkColor := BkColor = "" ? This.SYSCOLORS[Class] : This.HTML.HasKey(BkColor) ? This.HTML[BkColor]
  191.                 : "0x" . SubStr(BkColor, 5, 2) . SubStr(BkColor, 3, 2) . SubStr(BkColor, 1, 2)
  192.         return True
  193.     }
  194.  
  195.     CheckTxColor(ByRef TxColor) {
  196.         This.ErrorMsg := ""
  197.         if (TxColor != "") && !(This.HTML.HasKey(TxColor)) && !(RegExMatch(TxColor, "i)^[[:xdigit:]]{6}$")) {
  198.             This.ErrorMsg := "Invalid parameter TextColor: " . TxColor
  199.             return False
  200.         }
  201.         TxColor := TxColor = "" ? "" : This.HTML.HasKey(TxColor) ? This.HTML[TxColor]
  202.                 : "0x" . SubStr(TxColor, 5, 2) . SubStr(TxColor, 3, 2) . SubStr(TxColor, 1, 2)
  203.         return True
  204.     }
  205.  
  206.     Attach(HWND, BkColor, TxColor := "") {
  207.         static ClassNames := {Button: "", ComboBox: "", Edit: "", ListBox: "", Static: ""}
  208.  
  209.         if (This.SYSCOLORS.Edit = "") {
  210.             This.SYSCOLORS.Static := DllCall("user32.dll\GetSysColor", "Int", 15, "UInt")
  211.             This.SYSCOLORS.Edit := DllCall("user32.dll\GetSysColor", "Int", 5, "UInt")
  212.             This.SYSCOLORS.ListBox := This.SYSCOLORS.Edit
  213.         }
  214.         This.ErrorMsg := ""
  215.         if (BkColor = "") && (TxColor = "") {
  216.             This.ErrorMsg := "Both parameters BkColor and TxColor are empty!"
  217.             return False
  218.         }
  219.         if !(CtrlHwnd := HWND + 0) || !(DllCall("user32.dll\IsWindow", "UPtr", HWND, "UInt")) {
  220.             This.ErrorMsg := "Invalid parameter HWND: " . HWND
  221.             return False
  222.         }
  223.         if (This.Attached.HasKey(HWND)) {
  224.             This.ErrorMsg := "Control " . HWND . " is already registered!"
  225.             return False
  226.         }
  227.         Hwnds := [CtrlHwnd], Classes := ""
  228.         WinGetClass, CtrlClass, ahk_id %CtrlHwnd%
  229.         This.ErrorMsg := "Unsupported control class: " . CtrlClass
  230.         if !(ClassNames.HasKey(CtrlClass))
  231.             return False
  232.         ControlGet, CtrlStyle, Style, , , ahk_id %CtrlHwnd%
  233.         if (CtrlClass = "Edit")
  234.             Classes := ["Edit", "Static"]
  235.         else if (CtrlClass = "Button") {
  236.             if (CtrlStyle & 0x8) || (CtrlStyle & 0x2)
  237.                 Classes := ["Static"]
  238.             else
  239.                 return False
  240.         }
  241.         else if (CtrlClass = "ComboBox") {
  242.             VarSetCapacity(CBBI, 40 + (A_PtrSize * 3), 0), NumPut(40 + (A_PtrSize * 3), CBBI, 0, "UInt")
  243.             DllCall("user32.dll\GetComboBoxInfo", "Ptr", CtrlHwnd, "Ptr", &CBBI)
  244.             Hwnds.Insert(NumGet(CBBI, 40 + (A_PtrSize * 2, "UPtr")) + 0)
  245.             Hwnds.Insert(Numget(CBBI, 40 + A_PtrSize, "UPtr") + 0)
  246.             Classes := ["Edit", "Static", "ListBox"]
  247.         }
  248.         if !(IsObject(Classes))
  249.             Classes := [CtrlClass]
  250.         if !(This.CheckBkColor(BkColor, Classes[1]))
  251.             return False
  252.         if !(This.CheckTxColor(TxColor))
  253.             return False
  254.         for I, V In Classes {
  255.             if (This.HandledMessages[V] = 0)
  256.                 OnMessage(This.WM_CTLCOLOR[V], "CtlColors_OnMessage")
  257.             This.HandledMessages[V] += 1
  258.         }
  259.         Brush := DllCall("gdi32.dll\CreateSolidBrush", "UInt", BkColor, "UPtr")
  260.         for I, V In Hwnds
  261.             This.Attached[V] := {Brush: Brush, TxColor: TxColor, BkColor: BkColor, Classes: Classes, Hwnds: Hwnds}
  262.         DllCall("user32.dll\InvalidateRect", "Ptr", HWND, "Ptr", 0, "Int", 1)
  263.         This.ErrorMsg := ""
  264.         return True
  265.     }
  266.  
  267.     Change(HWND, BkColor, TxColor := "") {
  268.         This.ErrorMsg := "", HWND += 0
  269.         if !(This.Attached.HasKey(HWND))
  270.             return This.Attach(HWND, BkColor, TxColor)
  271.         CTL := This.Attached[HWND]
  272.         if !(This.CheckBkColor(BkColor, CTL.Classes[1]))
  273.             return False
  274.         if !(This.CheckTxColor(TxColor))
  275.             return False
  276.         if (BkColor <> CTL.BkColor) {
  277.             if (CTL.Brush) {
  278.                 DllCall("gdi32.dll\DeleteObject", "Prt", CTL.Brush)
  279.                 This.Attached[HWND].Brush := 0
  280.             }
  281.             Brush := DllCall("gdi32.dll\CreateSolidBrush", "UInt", BkColor, "UPtr")
  282.             This.Attached[HWND].Brush := Brush, This.Attached[HWND].BkColor := BkColor
  283.         }
  284.         This.Attached[HWND].TxColor := TxColor, This.ErrorMsg := ""
  285.         DllCall("user32.dll\InvalidateRect", "Ptr", HWND, "Ptr", 0, "Int", 1)
  286.         return True
  287.     }
  288.  
  289.     Detach(HWND) {
  290.         This.ErrorMsg := "", HWND += 0
  291.         if (This.Attached.HasKey(HWND)) {
  292.             CTL := This.Attached[HWND].Clone()
  293.             if (CTL.Brush)
  294.                 DllCall("gdi32.dll\DeleteObject", "Prt", CTL.Brush)
  295.             for I, V In CTL.Classes {
  296.                 if (This.HandledMessages[V] > 0) {
  297.                     This.HandledMessages[V] -= 1
  298.                     if This.HandledMessages[V] = 0
  299.                         OnMessage(This.WM_CTLCOLOR[V], "")
  300.                 }
  301.             }
  302.             for I, V In CTL.Hwnds
  303.                 This.Attached.Remove(V, "")
  304.             DllCall("user32.dll\InvalidateRect", "Ptr", HWND, "Ptr", 0, "Int", 1)
  305.             CTL := ""
  306.             return True
  307.         }
  308.         This.ErrorMsg := "Control " . HWND . " is not registered!"
  309.         return False
  310.     }
  311.  
  312.     Free() {
  313.         for K, V In This.Attached
  314.             DllCall("gdi32.dll\DeleteObject", "Ptr", V.Brush)
  315.         for K, V In This.HandledMessages {
  316.             if (V > 0) {
  317.                 OnMessage(This.WM_CTLCOLOR[K], "")
  318.                 This.HandledMessages[K] := 0
  319.             }
  320.         }
  321.         This.Attached := {}
  322.         return True
  323.     }
  324.  
  325.     IsAttached(HWND) {
  326.         return This.Attached.HasKey(HWND)
  327.     }
  328. }
  329.  
  330. CtlColors_OnMessage(HDC, HWND) {
  331.     Critical
  332.     if CtlColors.IsAttached(HWND) {
  333.         CTL := CtlColors.Attached[HWND]
  334.         if (CTL.TxColor != "")
  335.             DllCall("gdi32.dll\SetTextColor", "Ptr", HDC, "UInt", CTL.TxColor)
  336.         DllCall("gdi32.dll\SetBkColor", "Ptr", HDC, "UInt", CTL.BkColor)
  337.         return CTL.Brush
  338.     }
  339. }
  340.  
  341. ; ===============================================================================================================================
  342.  
  343. GuiClose:
  344. GuiEscape:
  345. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement