Coder Social home page Coder Social logo

nperovic / guienhancerkit Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 0.0 76 KB

Elevate your AHK Gui development with extended methods and properties.

Home Page: https://github.com/users/nperovic/projects/5?pane=info

License: MIT License

AutoHotkey 100.00%
ahk ahk-gui ahk-library ahk2 ahkscript ahkv2 autohotkey autohotkey-script autohotkey-v2 dark-mode

guienhancerkit's Introduction

GuiEnhancerKit

Elevate your AHK Gui development with extended methods and properties. This library provides a set of extended methods and properties to enhance your AutoHotkey Gui development experience.

🌍Other Language: 中文

Getting Started

Including the library in your script

#Requires AutoHotkey v2
#Include <GuiEnhancerKit>

Using VSCode's IntelliSence

image image

To ensure proper functioning of VSCode's IntelliSence, you can:

  1. 替换 Gui object with GuiExt. (Recommended)
myGui := GuiExt("-Caption +Resize")
  1. Annotate the variable type as GuiExt above the line where you create a new Gui object instance.
/** @var {GuiExt} myGui */
myGui := Gui("-Caption +Resize")

Features

GuiControl.SetRounded(corner := 9)

image

This method sets the control's border style to rounded corners. The radius of the rounded corners is set to 9 in this case.

text.SetRounded(9)

GuiOrControl.X/ GuiOrControl.Y/ GuiOrControl.W/ GuiOrControl.H

These properties allow you to get or set the Gui or Gui Control's position and size.

/* Get the current gui position. */
myEdit.UpdatePos := ctrl => (ctrl.Value := 
(
    "x: " myGui.X "
    y: " myGui.Y "
    w: " myGui.W "
    h: " myGui.H
))

myGui.OnEvent("Size", Size)

/**
 * @param {GuiExt|Gui} GuiObj 
 * @param {Integer} MinMax 
 * @param {Integer} Width 
 * @param {Integer} Height 
 */
Size(GuiObj, MinMax, Width, Height) {
    Critical("Off")
    SetWinDelay(-1), SetControlDelay(-1)

    /* Moving Controls */
    myEdit.W := text.W := Width - (GuiObj.MarginX*2)
    myEdit.H := Height - (GuiObj.MarginY*2)
    text.SetRounded()
    myEdit.UpdatePos()
}

Gui.OnMessage(Msg, Callback, MaxThreads := 1)

GuiControl.OnMessage(Msg, Callback, AddRemove := 1)

This method registers a function or method to be called whenever the Gui or GuiControl receives the specified message. Learn more

WM_LBUTTONDOWN   := 0x0201
WM_SETCURSOR     := 0x0020
WM_MOVING        := 0x0216

myGui.OnMessage(WM_LBUTTONDOWN, DragWindow)
myEdit.OnMessage(WM_SETCURSOR, SetCursor)
myGui.OnMessage(WM_MOVING, (*) => myEdit.UpdatePos())

/**
 * Callback function for `GuiCtrl.OnMessage()`
 * @param GuiCtrlObj 
 * @param wParam 
 * @param lParam 
 * @param msg 
 * @returns {Integer} 
 */
DragWindow(GuiCtrlObj, wParam, lParam, msg) {
    static WM_NCLBUTTONDOWN := 0x00A1
    PostMessage(WM_NCLBUTTONDOWN, 2,,, GuiCtrlObj is Gui.Control ? GuiCtrlObj.Gui : GuiCtrlObj)
    return 0
}

/**
 * Callback function for `GuiCtrl.OnMessage()`
 * @param GuiCtrlObj 
 * @param wParam 
 * @param lParam 
 * @param msg 
 * @returns {Integer} 
 */
SetCursor(GuiCtrlObj, wParam, lParam, Msg) {
    static hCursor := DllCall("LoadCursor", "ptr", 0, "ptr", 32512)
    DllCall("SetCursor", "ptr", hCursor, "ptr")
    return 0
}

Gui.SetDarkTitle()

This method sets the dark mode title bar for the window if the operating system version supports it.

myGui.SetDarkTitle()

Gui.SetWindowAttribute(dwAttribute, pvAttribute?)

This method calls the DwmSetWindowAttribute function from the dwmapi library to set attributes of a window.

Requires Windows 11.
Learn more on MSDN
image

/* To set Rounded Corners for window. */
myGui.SetWindowAttribute(33, 2)

Gui.SetWindowColor(titleText?, titleBackground?, border?)

This method sets the title bar background color to match the GUI background and removes the window border.

myGui.SetWindowColor(, myGui.BackColor, myGui.BackColor)

Gui.SetDarkMenu()

This method sets the dark mode context menus.

myGui.SetDarkMenu()

GuiControl.SetTheme(pszSubAppName, pszSubIdList := "")

Applies a specified theme to the window through the SetWindowTheme function from the uxtheme library.

/* This example sets dark mode edit control.*/
myEdit.SetTheme("DarkMode_Explorer")

GuiOrControl.SendMsg(Msg, wParam := 0, lParam := 0)

This method sends a message to the gui or gui control.

EN_KILLFOCUS := 0x0200
myEdit.SendMsg(EN_KILLFOCUS)

GuiExt.RECT(objOrAddress?)

Create a RECT structure object that defines a rectangle by the coordinates of its upper-left and lower-right corners. This can be used directly with DllCall.

/* Get RECT object from DllCall */
DllCall("GetWindowRect", "Ptr", WinExist("A"), "ptr", rc := GuiExt.RECT())
MsgBox(Format("{} {} {} {} {} {}", rc.left, rc.top, rc.right, rc.bottom, rc.Width, rc.Height))

/* Create a RECT object with values preset. */
rc := GuiExt.RECT({top: 10, bottom: 69})
MsgBox(Format("L{}/ T{}/ R{}/ B{}", rc.left, rc.top, rc.right, rc.bottom))

myGui.OnMessage(WM_NCCALCSIZE := 0x0083, NCCALCSIZE)

NCCALCSIZE(guiObj, wParam, lParam, msg) {
    if !wParam {
        /* Get the structure object from pointer address. */
        rc := GuiExt.RECT(lParam)
        ToolTip(Format("L{}/ T{}/ R{}/ B{}", rc.left, rc.top, rc.right, rc.bottom))
    }
}

GuiOrControl.GetWindowRect()

Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. Learn more on MSDN

rc := myGui.GetWindowRect()
MsgBox(rc.left " " rc.top " " rc.right " " rc.bottom " " rc.Width " " rc.Height)

GuiOrControl.GetClientRect()

Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).

rc := myEdit.GetClientRect()
MsgBox(rc.left " " rc.top " " rc.right " " rc.bottom " " rc.Width " " rc.Height)

Gui.SetBorderless(border := 6, dragWndFunc := "", cxLeftWidth?, cxRightWidth?, cyTopHeight?, cyBottomHeight?)

To create a borderless window with customizable resizing behavior. Creating a borderless resizable window with Mica (Alt) effect. background.

20240530-0455-52 6409216

myGui := GuiExt("-Caption +Resize")
myGui.SetFont("cWhite s16", "Segoe UI")
myGui.SetDarkTitle()
myGui.SetDarkMenu()
myGui.OnEvent('Size', Size)

myGui.BackColor := 0x202020

text := myGui.Add("Text", "vTitlebar Backgroundcaa2031 cwhite Center R1.5 0x200 w280", "Titlebar Area")
text.SetRounded()

/* Set Mica (Alt) background. (Supported starting with Windows 11 Build 22000.) */
if (VerCompare(A_OSVersion, "10.0.22600") >= 0)
    myGui.SetWindowAttribute(38, 4)

myGui.SetBorderless(6, (g, x, y) => (y <= g['Titlebar'].GetWindowRect().bottom), 500, 500, 500, 500)

myGui.Show("h500")

Size(g, minmax, width, height) {
    SetControlDelay(-1)
    /** Set titlebar's width to fix the gui. */
    g["Titlebar"].W := (width - (g.MarginX*2))
}

guienhancerkit's People

Contributors

nperovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

guienhancerkit's Issues

myGui.SetDarkMenu() is ignored when a menu option with BarBreak is present

First, I'd like to express my gratitude for the GuiEnhancerKit project. It's been incredibly useful in my work, and I truly appreciate the effort put into developing it.

I've encountered an issue while attempting to force dark mode in the tray menu using GuiEnhancerKit. The dark mode works perfectly on submenus, which is great. However, I've noticed that it doesn't apply to the main menu when there's a menu item with the "Break" or "BarBreak" option. I've attached a screenshot to illustrate this behavior.

I'm wondering if I'm missing something in my implementation, or if this might be a potential bug in the project. Any insights or guidance would be greatly appreciated.

Thank you again for this fantastic tool, and for taking the time to review this issue.

immagine

Without the BarBreak
immagine

Syntax error

Hi!
I recently found your repository and would really like to use it, but there is one thing, but for some reason your code does not want to work at the same time in Visual Studio Code with plugins, it displays normally without a single error, but if I want to run it, then I teach an error with syntax!

Error:
(232) : ==> Syntax error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.