TomP Posted April 16, 2016 Share Posted April 16, 2016 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! Link to comment Share on other sites More sharing options...
Oel Posted April 16, 2016 Share Posted April 16, 2016 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 !!! Link to comment Share on other sites More sharing options...
UEZ Posted April 16, 2016 Share Posted April 16, 2016 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
TomP Posted April 17, 2016 Author Share Posted April 17, 2016 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 Link to comment Share on other sites More sharing options...
UEZ Posted April 17, 2016 Share Posted April 17, 2016 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
TomP Posted April 17, 2016 Author Share Posted April 17, 2016 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. Link to comment Share on other sites More sharing options...
TomP Posted April 19, 2016 Author Share Posted April 19, 2016 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, Link to comment Share on other sites More sharing options...
UEZ Posted April 19, 2016 Share Posted April 19, 2016 Check this out: 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now