Jump to content

Recommended Posts

Posted

Hi guys,

is there a way to save the current mouse cursor image to a bmp ?

I understand there is the GetCursor function to get a handle to the cursor, but I can figure out how to get the actual image from there (and then save it).

Thanks for any suggestions!

 

Posted

Well, you could get a bmp library

and draw every single pixel of the desired cursor into a bmp file. . . this will probably take a while but you asked for suggestions !!!

Posted

Something like this here?

#include <GDIPlus.au3>
#include <WinAPIRes.au3>

_WinAPI_SaveCurrentCursorAsImage("CurrentCursor.png")

Func _WinAPI_SaveCurrentCursorAsImage($sFilename)
    Local Const $hCursor = _WinAPI_LoadCursor(0, 32512)
    If Not $hCursor Or @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local Const $hImage = _GDIPlus_BitmapCreateFromHICON32($hCursor)
    _GDIPlus_ImageSaveToFile($hImage, $sFilename)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Return 1
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
6 hours ago, UEZ said:

Something like this here?

#include <GDIPlus.au3>
#include <WinAPIRes.au3>

_WinAPI_SaveCurrentCursorAsImage("CurrentCursor.png")

Func _WinAPI_SaveCurrentCursorAsImage($sFilename)
    Local Const $hCursor = _WinAPI_LoadCursor(0, 32512)
    If Not $hCursor Or @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local Const $hImage = _GDIPlus_BitmapCreateFromHICON32($hCursor)
    _GDIPlus_ImageSaveToFile($hImage, $sFilename)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Return 1
EndFunc

 

Hi Uez,

thanks, this results indeed in saving the cursor to a file. However it seems to always save an arrow cursor in my case, not the actual cursor being displayed. Any idea?

Cheers,

tom

 

Posted

What about this version?

 

#include <GDIPlus.au3>
#include <WinAPIRes.au3>

ConsoleWrite(_WinAPI_SaveCurrentCursorAsImage("CurrentCursor.png") & @CRLF)

Func _WinAPI_SaveCurrentCursorAsImage($sFilename)
    Local Const $hCursor = _WinAPI_CopyIcon(_WinAPI_GetCursorInfo()[2])
    If Not $hCursor Or @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local Const $hImage = _GDIPlus_BitmapCreateFromHICON32($hCursor)
    _GDIPlus_ImageSaveToFile($hImage, $sFilename)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DestroyIcon($hCursor)
    _GDIPlus_Shutdown()
    Return 1
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
3 hours ago, UEZ said:

What about this version?

 

#include <GDIPlus.au3>
#include <WinAPIRes.au3>

ConsoleWrite(_WinAPI_SaveCurrentCursorAsImage("CurrentCursor.png") & @CRLF)

Func _WinAPI_SaveCurrentCursorAsImage($sFilename)
    Local Const $hCursor = _WinAPI_CopyIcon(_WinAPI_GetCursorInfo()[2])
    If Not $hCursor Or @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local Const $hImage = _GDIPlus_BitmapCreateFromHICON32($hCursor)
    _GDIPlus_ImageSaveToFile($hImage, $sFilename)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DestroyIcon($hCursor)
    _GDIPlus_Shutdown()
    Return 1
EndFunc

 

Works like a charm! Exactly what I was looking for - Many thanks.

Posted

Hi Uez,

 

I'm one step closer, but still have a remaining question.

I can load the saved bitmap with following command: _GDIPlus_BitmapCreateFromFile

How can I now compare the current mouse cursor with the saved file, to see if they match?

Below is what I intent to achieve, but i guess it compares of the Pointers are the same rather than the actual images?

Quote
Local Const $hImage = _GDIPlus_BitmapCreateFromHICON32($hCursor)
Local Const $hImage2 = _GDIPlus_BitmapCreateFromFile("CurrentCursor.png")

if $hImage 1 = $hImage2 then
    dosomething
EndIf

 

Cheers,

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...