Jump to content

Recommended Posts

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
Posted

Please be more specyfic.

What is your question ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
Posted

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()

 

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 (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

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...