Alex1986

How Get HICON From Bitmap ;

8 posts in this topic

#1 ·  Posted (edited)

Hi

I want help me about GetHicon From Bitmap , For create Cursor mouse

i write this Example on Vb.net :

'_WinApi_CreateBitmap() Or GDI Create Bitmap = Autoti
        Dim bmCur As New Bitmap(60, 60)
        ' Create Graphic From Bitmap Similar _GDIPlus_ImageGetGraphicsContext($hBitmap) = Autoit
        Dim g As Graphics = Graphics.FromImage(bmCur)
        'GDIPlus_CreatePen() = Autoit
        Dim blackPen As New Pen(Color.FromArgb(255, 1, 0, 6), 1)
        Dim X As Integer = 60 / 2
        Dim Y As Integer = 60 / 2
        '_GDIPlus_GraphicsDrawEllipse ( $hGraphics, $iX, $iY, $iWidth, $iHeight [, $hPen = 0] )
        g.DrawEllipse(Pens.Red, X, Y, 1, 1)
        Dim X1 As Integer = 15
        Dim Y1 As Integer = 15
        g.DrawEllipse(blackPen, X1, Y1, 30, 30)
        'Create Cursor/icon From Bitmap
        Dim ptrCur As IntPtr = bmCur.GetHicon
        Dim cur As Windows.Forms.Cursor
        cur = New Windows.Forms.Cursor(ptrCur)
        'Change Cursor to New 
        Me.Cursor = cur

 

 

Edited by Alex1986

Share this post


Link to post
Share on other sites



Please be more specyfic.

What is your question ?

1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

i want create cursor from bitmap , but I can't do it in Autoit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this example

#include <GDIplus.au3>

$hGUI = GUICreate("" , 60 ,60 , -1 , -1 , -1 )

GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hW = 60 , $hH = 60
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($hW,$hH , $hGraphic)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hPen = _GDIPlus_PenCreate(0xFF0F0F0F , 2)
$hX = $hW / 2 - $hW / 2 + 15
$hY = $hH / 2 - $hW / 2 + 15
_GDIPlus_GraphicsDrawRect($g_hGfxCtxt , $hX  , $hY  , 30 ,30 , $hPen)
_GDIPlus_GraphicsDrawRect($g_hGfxCtxt , 60 / 2  , 60 / 2  , 1 ,1 ,_GDIPlus_PenCreate(0x99FF0000 , 2) )
_GDIPlus_GraphicsDrawImage($hGraphic , $hBitmap , 2 , 2)
$icon = _GDIPlus_HICONCreateFromBitmap($hBitmap)
 ; { here stopped }


Do
Until  GUIGetMsg() = -3

i need create cursor and change to new cur

Edited by Alex1986

Share this post


Link to post
Share on other sites

Help Plz ..

Share this post


Link to post
Share on other sites

Try this:

#include <GDIplus.au3>
#include <WinAPIRes.au3>

$hGUI = GUICreate("" , 260 ,260 , -1 , -1 , -1 )
GUISetState(@SW_SHOW)
_GDIPlus_Startup()

Local $hW = 60 , $hH = 60
$hBitmap = _GDIPlus_BitmapCreateFromScan0($hW, $hH)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hPen = _GDIPlus_PenCreate(0xFF0F0F0F , 2)
$hX = $hW / 2 - $hW / 2 + 15
$hY = $hH / 2 - $hW / 2 + 15
_GDIPlus_GraphicsDrawRect($g_hGfxCtxt , $hX  , $hY  , 30 ,30 , $hPen)
_GDIPlus_PenSetColor($hPen, 0x99FF0000)
_GDIPlus_GraphicsDrawRect($g_hGfxCtxt , 60 / 2  , 60 / 2  , 1 ,1 ,  $hPen)

$icon = _GDIPlus_HICONCreateFromBitmap($hBitmap)

Local $hPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32512))

_WinAPI_SetSystemCursor($icon, 32512)


Do
Until  GUIGetMsg() = -3

_WinAPI_SetSystemCursor($hPrev, 32512)
_WinAPI_DestroyCursor($icon)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($g_hGfxCtxt)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
GUIDelete()

 

2 people like this

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

An other one using _WinAPI_CreateIconIndirect, as described in the helpfile and here :
http://www.codeguru.com/cpp/w-p/win32/cursors/article.php/c4529/Creating-a-Color-Cursor-from-a-Bitmap.htm

#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <WinAPIRes.au3>

$hold_cursor = _WinAPI_CopyCursor(_WinAPI_LoadCursor (0, $OCR_NORMAL))

; Create XOR bitmap
Local $hDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hXOR = _WinAPI_CreateCompatibleBitmapEx($hDC, 32, 32, 0)
Local $hSv = _WinAPI_SelectObject($hMemDC, $hXOR)
_WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_BRUSH))
_WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_PEN))
Local $tRECT = _WinAPI_CreateRectEx(0, 1, 22, 22)
_WinAPI_SetDCBrushColor($hMemDC, 0x0000FF)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_OffsetRect($tRECT, 11, 0)
_WinAPI_SetDCBrushColor($hMemDC, 0x00FF00)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_OffsetRect($tRECT, -6, 9)
_WinAPI_SetDCBrushColor($hMemDC, 0xFF0000)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_SelectObject($hMemDC, $hSv)
_WinAPI_DeleteDC($hMemDC)

; Create AND bitmap
$hDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hAND = _WinAPI_CreateBitmap(32, 32, 1, 1)
$hSv = _WinAPI_SelectObject($hMemDC, $hAND)
_WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_BRUSH))
_WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_PEN))
_WinAPI_SetDCBrushColor($hMemDC, 0xFFFFFF)
$tRECT = _WinAPI_CreateRectEx(0, 0, 33, 33)
_WinAPI_Rectangle($hMemDC, $tRECT)
_WinAPI_SetDCBrushColor($hMemDC, 0)
$tRECT = _WinAPI_CreateRectEx(0, 1, 22, 22)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_OffsetRect($tRECT, 11, 0)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_OffsetRect($tRECT, -6, 9)
_WinAPI_Ellipse($hMemDC, $tRECT)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_SelectObject($hMemDC, $hSv)
_WinAPI_DeleteDC($hMemDC)

; Create cursor
Local $hnew_Cursor = _WinAPI_CreateIconIndirect($hXOR, $hAND, 0, 0, False)

; Free bitmaps
_WinAPI_DeleteObject($hXOR)
_WinAPI_DeleteObject($hAND)

; Create GUI
$hGUI = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 128, 128)
GUISetState(@SW_SHOW)

_WinAPI_SetSystemCursor($hnew_Cursor, $OCR_NORMAL, 1)

Do
Until  GUIGetMsg() = -3

_WinAPI_SetSystemCursor($hold_Cursor, $OCR_NORMAL, 1)

 

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

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