I'm not sure how to be more clear with my question.
I have this class
class Checkbox
Code: Select all
class Checkbox
{
__New(hParent, sizePos := "", backgroundColor := "", textColor := "", checked := 1, checkChar := "")
{
Gui, %hParent%:Add, Text, +HwndhCB %sizePos% +0x200 +0x0100 +Border +Center
this.Hwnd := hCB
, this.CheckChar := checkChar = "" ? Chr(0x2713) : checkChar
, this.ParentHwnd := hParent
, this.Checked := checked
, click := this.Click.Bind(this)
GuiControl, %hParent%: +g, % hCB, % click
if (backgroundColor || textColor)
ControlColor(hCB, hParent, backgroundColor, textColor)
}
Checked[]
{
get
{
GuiControlGet, checked, % this.ParentHwnd ":", % this.Hwnd
return (checked = this.CheckChar ? true : false)
}
set
{
GuiControl, % this.ParentHwnd ":", % this.Hwnd, % value ? this.CheckChar : ""
}
}
Click()
{
this.Checked := !this.Checked
}
}
In this project I'm working on.
MUGEN Quick VS
Code: Select all
;#NoTrayIcon
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
trigram_for_heaven := Chr(0x2630)
, multiplication_X := Chr(0x2715)
, check_mark := Chr(0x2713)
, titleBar_color := 0x353535
, titleText_color := 0xA5A5A5
, gui_color := 0x454545
, guiControl_color := 0x656565
, highlight_color := 0xFF8000
, defaultValues := {P1Life: 1000, P2Life: 1000, P1Power: 1000, P2Power: 1000, P1AI: true, P2AI: true, Rounds: 1, Stage: Default}
Menu Tray, Icon, .\res\vs.png
Gui, New, +HwndhParent -Caption -DPIScale -Resize, MUGEN Quick VS
Gui, %hParent%:Color, % titleBar_color
Gui, %hParent%:Font, s12 w600 q5 c%titleText_color%, Segoe UI
Gui, %hParent%:Add, Picture, +HwndhMenuButton x0 y0 h34 w34 +0x200, .\res\menu_button.png
Gui, %hParent%:Add, Picture, xp+35 y2 w30 h30 +BackgroundTrans, .\res\vs.png
Gui, %hParent%:Font, s14 w600 q5 c%titleText_color%, Segoe UI
Gui, %hParent%:Add, Text, x235 y2 hp w180 +0x200 +Center, MUGEN Quick VS
Gui, %hParent%:Add, Picture, +HwndhCloseButton x616 y0 w34 h34, .\res\close_button.png
Gui, %hParent%:Show, w650 h415
Gui, New, +HwndhMenu -Caption +ToolWindow -DPIScale +Parent%hParent%
Gui, %hMenu%:Color, % titleBar_color
Gui, %hMenu%:Font, s12 w600 q5 c%titleText_color%, Segoe UI
Gui, %hMenu%:Add, Text, +HwndhSetExe_MenuItem xm ym +0x200 +0x0100 vSetExe_MenuItem, SET MUGEN EXE
Gui, %hMenu%:Add, Text, +HwndhSetP1_MenuItem xs +0x200 +0x0100 vSetP1_MenuItem, SELECT PLAYER 1
Gui, %hMenu%:Add, Text, +HwndhSetP2_MenuItem xs +0x200 +0x0100 vSetP2_MenuItem, SELECT PLAYER 2
Gui, %hMenu%:Add, Text, +HwndhSetDefaults_MenuItem xs +0x200 +0x0100 vSetDefaults_MenuItem, RESET VALUES
Gui, %hMenu%:Show, % "x0 y34 Hide h" WinGetPos(hParent).H - 34
Gui, New, +HWndhFight -Caption +ToolWindow -DPIScale +Parent%hParent%
Gui, %hFight%:Margin, 15, 15
Gui, %hFight%:Color, % gui_color, % guiControl_color
Gui, %hFight%:Add, Picture, x116 y4 w-1 h373 +BackgroundTrans, .\res\fight_d.png
Gui, %hFight%:Font, s12 w600 q5 cBlack, Segoe UI
Gui, %hFight%:Add, Text, +HwndhTxtBlk1 xm y55 w10 h30 +0x200
Gui, %hFight%:Add, Text, +HwndhPlayer1 xm+10 yp w300 hp +0x200 vPlayer1 +Background%guiControl_color%
Gui, %hFight%:Add, Text, +HwndhPlayer2 x325 yp wp hp +0x200 +Right vPlayer2
Gui, %hFight%:Add, Text, +HwndhTxtBlk2 x625 yp w10 hp +0x200
Gui, %hFight%:Add, Picture, x255 ym w120 h120 +BackgroundTrans, .\res\vs.png
Gui, %hFight%:Font, s14 Bold q5 c0xFF8000, Segoe UI
Gui, %hFight%:Add, Text, x235 y150 w180 h23 +0x200 +Center +BackgroundTrans, <<< LIFE >>>
Gui, %hFight%:Add, Text, xp yp+40 wp hp +0x200 +Center +BackgroundTrans, <<< POWER >>>
Gui, %hFight%:Add, Text, xp yp+40 wp hp +0x200 +Center +BackgroundTrans, <<< AI >>>
Gui, %hFight%:Add, Text, xp yp+40 wp hp +0x200 +Center +BackgroundTrans, Rounds
Gui, %hFight%:Font, s12 w600 q5 cBlack, Segoe UI
Gui, %hFight%:Add, Edit, +HwndhP1Life x160 y153 w60 h21 -VScroll +Number +Center Limit4 -E0x200 vP1Life, 1000
Gui, %hFight%:Add, Edit, +HwndhP1Power xp yp+40 w60 h21 -VScroll +Number +Center Limit4 -E0x200 vP1Power, 1000
P1AI := new Checkbox(hFight, "xp+39 yp+40 w21 hp", guiControl_color)
Gui, %hFight%:Add, Edit, +HwndhP2Life x430 yp-80 w60 h21 -VScroll +Number +Center Limit4 -E0x200 vP2Life, 1000
Gui, %hFight%:Add, Edit, +HwndhP2Power xp yp+40 w60 h21 -VScroll +Number +Center Limit4 -E0x200 vP2Power, 1000
P2AI := new Checkbox(hFight, "xp yp+40 w21 hp", guiControl_color)
Gui, %hFight%:Add, Edit, +HwndhRounds x305 y300 w40 h21 -VScroll +Number +Center Limit1 -E0x200 vRounds, 1
Gui, %hFight%:Font, s14 Bold q5, Segoe UI
Gui, %hFight%:Add, Text, +HwndhFightButton x515 y+m w120 h30 +0x200 +Border +Center +0x0100, FIGHT
ControlColor(hPlayer1, hFight, guiControl_color)
, ControlColor(hPlayer2, hFight, guiControl_color)
, ControlColor(hTxtBlk1, hFight, guiControl_color)
, ControlColor(hTxtBlk2, hFight, guiControl_color)
, ControlColor(hFightButton, hFight, guiControl_color)
, OnMessage(0x0200, Func("WM_MOUSEMOVE"))
, OnMessage(0x201, Func("WM_LBUTTONDOWN"))
, OnMessage(0x202, Func("WM_LBUTTONUP"))
, gClose := Func("GuiClose")
, menuClick := Func("Menu_Click").Bind(hMenu)
GuiControl, %hParent%: +g, % hCloseButton, % gClose
GuiControl, %hParent%: +g, % hMenuButton, % menuClick
Gui, %hFight%:Show, x0 y34
return
Menu_Click(hwnd)
{
static isMenuVisible := 0
if (isMenuVisible)
DllCall("AnimateWindow", "UPtr", hwnd, "Int", 200, "UInt", 327682)
else
DllCall("AnimateWindow", "UPtr", hwnd, "Int", 200, "UInt", 393217)
isMenuVisible := !isMenuVisible
}
GuiClose()
{
ExitApp
}
WM_LBUTTONDOWN(W, L, M, H)
{
global
if (H = hParent)
{
PostMessage 0xA1, 2
return
}
ControlGet, isVisible, Visible,,, % "ahk_id " hMenu
if (isVisible && !(H = hMenu || H = hMenuButton || H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem))
Menu_Click(hMenu)
if (H = hCloseButton || H = hFightButton || H = P1AI.Hwnd || H = P2AI.Hwnd || H = hMenuButton || H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
{
if (H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
GuiControl, %A_Gui%: +c%gui_color% +Redraw, % H
else if (H = hCloseButton || H = hMenuButton)
ControlColor(H, A_Gui, titleBar_color)
else
ControlColor(H, A_Gui, gui_color)
}
}
WM_LBUTTONUP(W, L, M, H)
{
global
if (H = hCloseButton || H = hFightButton || H = P1AI.Hwnd || H = P2AI.Hwnd || H = hMenuButton || H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
{
if (H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
GuiControl, %A_Gui%: +c%highlight_color% +Redraw, % H
else
ControlColor(H, A_Gui, highlight_color)
}
OnMessage(0x202, "")
}
WM_MOUSEHOVER(W, L, M, H)
{
global
if (H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
GuiControl, %A_Gui%: +c%highlight_color% +Redraw, % H
else
ControlColor(H, A_Gui, highlight_color)
OnMessage(0x02A1, "")
}
WM_MOUSELEAVE(W, L, M, H)
{
global
if (H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
GuiControl, %A_Gui%: +c%titleText_color% +Redraw, % H
else if (H = hCloseButton || H = hMenuButton)
ControlColor(H, A_Gui, titleBar_color)
else
ControlColor(H, A_Gui, guiControl_color)
OnMessage(0x02A3, "")
}
WM_MOUSEMOVE(W, L, M, H)
{
global
if (H = hCloseButton || H = hFightButton || H = P1AI.Hwnd || H = P2AI.Hwnd || H = hMenuButton || H = hSetExe_MenuItem || H = hSetP1_MenuItem || H = hSetP2_MenuItem || H = hSetDefaults_MenuItem)
{
TrackMouseEvent(H, 3)
, OnMessage(0x02A1, "WM_MOUSEHOVER")
, OnMessage(0x02A3, "WM_MOUSELEAVE")
}
}
class Checkbox
{
__New(hParent, sizePos := "", backgroundColor := "", textColor := "", checked := 1, checkChar := "")
{
Gui, %hParent%:Add, Text, +HwndhCB %sizePos% +0x200 +0x0100 +Border +Center
this.Hwnd := hCB
, this.CheckChar := checkChar = "" ? Chr(0x2713) : checkChar
, this.ParentHwnd := hParent
, this.Checked := checked
, click := this.Click.Bind(this)
GuiControl, %hParent%: +g, % hCB, % click
if (backgroundColor || textColor)
ControlColor(hCB, hParent, backgroundColor, textColor)
}
Checked[]
{
get
{
GuiControlGet, checked, % this.ParentHwnd ":", % this.Hwnd
return (checked = this.CheckChar ? true : false)
}
set
{
GuiControl, % this.ParentHwnd ":", % this.Hwnd, % value ? this.CheckChar : ""
}
}
Click()
{
this.Checked := !this.Checked
}
}
;-----------------------------------------------------------
;-----------------------------------------------------------
;-----------------------------------------------------------
WinGetPos(hwnd)
{
WinGetPos, x, y, w, h, % "ahk_id " hwnd
Return {X: x, Y: y, W: w, H: h}
}
TrackMouseEvent(HWND, Event, HoverTime := 1) ; HOVER_DEFAULT = 0xFFFFFFFF
{
TME_Size := 8 + (A_PtrSize * 2)
, VarSetCapacity(TME, TME_Size, 0)
, Addr := &TME
, Addr := NumPut(TME_Size, Addr + 0, "UInt")
, Addr := NumPut(Event, Addr + 0, "UInt")
, Addr := NumPut(HWND, Addr + 0, "UPtr")
, NumPut(HoverTime, Addr + 0, "UInt")
return DllCall("TrackMouseEvent", "Ptr", &TME, "UInt")
}
; http://www.autohotkey.com/board/topic/104539-controlcol-set-background-and-text-color-gui-controls/
ControlColor(Control, Window, bc := "", tc := "", Redraw := True) {
Local a := {}
a["c"] := Control
a["g"] := Window
a["bc"] := (bc == "") ? "" : (((bc & 255) << 16) + (((bc >> 8) & 255) << 8) + (bc >> 16))
a["tc"] := (tc == "") ? "" : (((tc & 255) << 16) + (((tc >> 8) & 255) << 8) + (tc >> 16))
CC_WindowProc("Set", a, "", "")
If (Redraw) {
WinSet Redraw,, ahk_id %Control%
}
}
CC_WindowProc(hWnd, uMsg, wParam, lParam) {
Local tc, bc, a
Static Win := {}
; Critical
If uMsg Between 0x132 And 0x138 ; WM_CTLCOLOR(MSGBOX|EDIT|LISTBOX|BTN|DLG|SCROLLBAR|STATIC)
If (Win[hWnd].HasKey(lParam)) {
If (tc := Win[hWnd, lParam, "tc"]) {
DllCall("gdi32.dll\SetTextColor", "Ptr", wParam, "UInt", tc)
}
If (bc := Win[hWnd, lParam, "bc"]) {
DllCall("gdi32.dll\SetBkColor", "Ptr", wParam, "UInt", bc)
}
Return Win[hWnd, lParam, "Brush"] ; Return the HBRUSH to notify the OS that we altered the HDC.
}
If (hWnd == "Set") {
a := uMsg
Win[a.g, a.c] := a
If ((Win[a.g, a.c, "tc"] == "") && (Win[a.g, a.c, "bc"] == "")) {
Win[a.g].Remove(a.c, "")
}
If (!Win[a.g, "WindowProcOld"]) {
Win[a.g,"WindowProcOld"] := DllCall("SetWindowLong" . (A_PtrSize == 8 ? "Ptr" : "")
, "Ptr", a.g, "Int", -4, "Ptr", RegisterCallback("CC_WindowProc", "", 4), "UPtr")
}
If (Win[a.g, a.c, "bc"] != "") {
Win[a.g, a.c, "Brush"] := DllCall("gdi32.dll\CreateSolidBrush", "UInt", a.bc, "UPtr")
}
Return
}
Return DllCall("CallWindowProc", "Ptr", Win[hWnd, "WindowProcOld"], "Ptr", hWnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam, "Ptr")
}
- MUGEN Quick VS.zip
- (160.75 KiB) Downloaded 26 times
I would like if class Checkbox was able to handle its own messages. I want highlighting and checking built into the class instead of handling it in the main thread. Currently I'm using a property Checked and the text control's g_label to handle the check mark. I would like to leave the g_label for a Callback function if needed, instead of hogging it up on the check mark code.
Is what I'm asking possible?
If so, how do I go about implementing it?
Edit: Another question relating to the project.
Is it possible to change the highlight color of an edit control?