BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 20 Jul 2021, 06:07

This function is a component of ChooseColors().
Edit: Rectangular cursors/any cursor larger than 32x32 works only in Windows 10.
Pre Window 10, cursor will be resized to 32x32 when passed to SetSystemCursor() API function.
 
Example:

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force

F1:: BoxCur(128, 64)       ; create/apply 128x64 bordered box as system-wide cursor.
F2:: BoxCur()              ; restore system cursors.
F3:: BoxCur(128, 64, True) ; create/apply 128x64 filled box as system-wide cursor.
 
BoxCur.png
BoxCur.png (20.94 KiB) Viewed 1674 times
 
 
The function:
 

Code: Select all

BoxCur(P*) {            ; v0.3 by SKAN on D47J/D47K @ tiny.cc/boxcur
Local                   ; Original function name ChooseColors_BoxCur()
    If ! ( P.Count() )
           Return DllCall("User32.dll\SystemParametersInfo", "Int",SPI_SETCURSORS := 0x57, "Int",0, "Int",0, "Int",0)

    CW := Max( 32, Format("{:d}", P[1]) )
    CH := Max( 32, Format("{:d}", P[2]) )
    RegRead, m, HKEY_CURRENT_USER\Control Panel\Cursors, CursorBaseSize
    m  := ( (m := Format("{:d}", m)) > 32 ? m/32 : 1 )
    CW := Round(CW/m)
    CH := Round(CH/m)

    VarSetCapacity(BITMAPINFO, 40, 0)
    pBMI := &BITMAPINFO,  pBits := 0
    NumPut(1, NumPut(1,NumPut(CH,NumPut(CW,NumPut(40,pBMI+0,"Int"),"Int"),"Int"),"Short"),"Short")

    hBM   := DllCall("gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",pBMI, "Int",0, "PtrP",pBits, "Ptr",0, "Int", 0, "Ptr")
    hPen  := DllCall("Gdi32.dll\CreatePen", "Int",0, "Int",1, "Int",0xFFFFFF, "Ptr")
    hBrush  := DllCall("Gdi32.dll\CreateSolidBrush", "Int",m!=1 || P[3]!="" ? 0xFFFFFF : 0x000000, "Ptr")
    mDC     := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",0, "Ptr")
    DllCall("Gdi32.dll\SaveDC", "Ptr",mDC)

    DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBrush)
    DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hPen)
    DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM)
    DllCall("Gdi32.dll\RoundRect", "Ptr",mDC, "Int",0, "Int",0, "Int",CW, "Int",CH, "Int",0, "Int",0)
    DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1)
    DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC)
    DllCall("Gdi32.dll\DeleteObject", "Ptr",hBrush)
    DllCall("Gdi32.dll\DeleteObject", "Ptr",hPen)

    VarSetCapacity( BITMAP, SzBITMAP := ( A_PtrSize = 8 ? 32 : 24 ) )
    DllCall("Gdi32.dll\GetObject", "Ptr",hBM, "Int",SzBITMAP, "Ptr",&BITMAP)
    WB      := Numget(BITMAP, 12, "Int")
    biSize  := (WB*CH) * 2
    ttlSize :=  22 + 40 + 8 + biSize

    pCURSOR := DllCall("Kernel32.dll\GlobalAlloc", "Int",0x40, "Ptr",ttlSize, "Ptr")

    NumPut(0x0100020000,    pCURSOR +  0, "Int64")
    NumPut(CW,              pCURSOR +  6, "UChar")
    NumPut(CH,              pCURSOR +  7, "UChar")
    NumPut(40 + 8 + biSize, pCURSOR + 14, "UInt")
    NumPut(22,              pCURSOR + 18, "UInt")
    NumPut(0xFFFFFF,        pCURSOR + 66, "UInt")
    NumPut(CW,     pBMI +  4, "UInt")
    NumPut(CH*2,   pBMI +  8, "UInt")
    NumPut(bisize, pBMI + 20, "UInt")
    NumPut(2,      pBMI + 32, "UInt")
    NumPut(2,      pBMI + 36, "UInt")

    DllCall("Kernel32.dll\RtlMoveMemory", "Ptr",pCURSOR + 22,         "Ptr",pBMI,    "Ptr",40)
    DllCall("Kernel32.dll\RtlMoveMemory", "Ptr",pCURSOR + 70,         "Ptr",pBits,   "Ptr",WB*CH)
    DllCall("Kernel32.dll\RtlFillMemory", "Ptr",pCURSOR + 70+(WB*CH), "Ptr",(WB*CH), "Int",255)
    DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM)

    Loop, Parse, % "32512,32513,32514,32515,32516,32640,32641,32642,32643,32644,32645,32646,32648,32649,32650,32651", `,
          DllCall("User32.dll\SetSystemCursor", "Ptr",DllCall("User32.dll\CreateIconFromResourceEx", "Ptr",pCURSOR+22
                , "UInt",ttlSize-22, "Int",True, "Int",0x30000, "Int",CW, "Int",CH, "Int",0, "Ptr"), "Int",A_Loopfield)

;   FileOpen("box.cur", "w").RawWrite(pCURSOR+0, ttlSize)
    DllCall("Kernel32.dll\GlobalFree", "Ptr",pCURSOR)
Return ttlSize
}
My Scripts and Functions: V1  V2
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by Delta Pythagorean » 20 Jul 2021, 13:33

What use would this have?
It's just a box that replaces your mouse cursor? What?

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by gregster » 20 Jul 2021, 13:40

As a component of certain tools, I see some use cases (example: see the link in the original post to SKAN's ChooseColors()).
Thanks again, SKAN!
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 20 Jul 2021, 14:21

Delta Pythagorean wrote:
20 Jul 2021, 13:33
It's just a box that replaces your mouse cursor? What?
It is hardcore stuff and you wouldn't understand if I explained.
Can't you see in screenshot that the box line is inverting colors?
Let me just say: It is a windows magic.

I guess one wouldn't know if they have never tried the third type of Mouse pointer
which inverts the color under it making itself 100% visible in any background.
 
image.png
image.png (14.85 KiB) Viewed 1603 times
PS: It is disheartening when people comment without even trying the example.
 
@gregster :thumbup:
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by Delta Pythagorean » 21 Jul 2021, 09:13

I tried the example but I guess my desktop background is too simple.
Didn't think of it to be an inverted mouse cursor. But my question was why a box instead of a crosshair or something a little more practical.
I can see the use of an inverted mouse cursor function, but the reason for a box makes no sense to me.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 21 Jul 2021, 10:13

Delta Pythagorean wrote:
21 Jul 2021, 09:13
I can see the use of an inverted mouse cursor function, but the reason for a box makes no sense to me.
How would a user know that the selection area is 128x64 with a cross-hair?
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by Delta Pythagorean » 21 Jul 2021, 13:12

Selection? What? Where does it say that this is for a selection? Who would need a 128x64 sized selection?

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 21 Jul 2021, 13:31

Delta Pythagorean wrote:
21 Jul 2021, 13:12
Where does it say that this is for a selection?
What else would a Box shaped cursor do?
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by rommmcek » 21 Jul 2021, 13:47

Does not work for me! Instead of showing box cursor it hides it and then I have to restore it manually.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 21 Jul 2021, 13:51

rommmcek wrote:
21 Jul 2021, 13:47
Does not work for me! Instead of showing box cursor it hides it
Which windows version?
rommmcek wrote:
21 Jul 2021, 13:47
and then I have to restore it manually.
F2 should restore system cursors unconditionally?

Edit: Updated OP.
Rectangular cursors (of any size) is supported only Windows 10 onwards.
For older OS, only BoxCur(32, 32) or BoxCur(32, 32, True) would work.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by rommmcek » 22 Jul 2021, 13:31

Edition: Windows 10 Home, Version: 1803, OS build 17134.1

P.s.: Indeed, w/o parameters restores the cursor.
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by DataLife » 23 Jul 2021, 06:34

The filled box system-wide cursor would work great to invert the colors on part of the screen that is difficult to read due to poor colors.

The box cursor flickers like crazy. Is that intentional?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: BoxCur(128, 64) : Create/apply 128x64 bordered box as system-wide cursor.

Post by SKAN » 23 Jul 2021, 08:03

DataLife wrote:
23 Jul 2021, 06:34
The box cursor flickers like crazy. Is that intentional?
It doesn't for me in latest Windows. It should be steady and smooth even if there is a video running under filled box cursor.
The color inversion is amazing with high FPS.

I realize my mistake. I should never develop anything in Windows 10.
I should write code in older OS and then check it with Win-10, instead.
Post Reply

Return to “Scripts and Functions (v1)”