Sign in to follow this  
Followers 0
monoscout999

How to set a Bitmap into a Pic control using a Bitmap handle?

3 posts in this topic

#1 ·  Posted (edited)

Hello forum. I want to use GuiCtrlSendMsg() to put a bitmap handle into a pic control but i don`t know how.

This is my try.

#include <winapi.au3>
#include <gdiplus.au3>
#include <array.au3>
#include <Math.au3>
#include <Constants.au3>
#include <Staticconstants.au3>
#include <WindowsConstants.au3>
Global Const $STM_SETIMAGE = 0x172

$hGui = GUICreate("Pot by monoscout999", -1, -1)
GUISetState()
$aPot = _CreatePot(10, 10)


While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            _DestryPot($aPot)
            Exit
        case $aPot[0]
            consolewrite("im here"&@crlf)

    EndSwitch
WEnd
Func _CreatePot($iX, $iY, $iBkColor = 0, $iPenColor = 0x00FF00, $iDieameter = 50, $iMinValue = 0, $iMaxValue = 250)
    local $iWidth = $iDieameter
    local $iHeight = $iDieameter
    Local $iPic = GUICtrlCreatePic("", $iX, $iY, $iWidth, $iHeight)
    Local $hHandle = GUICtrlGetHandle($iPic)
    Local $iWidth2 = $iWidth - 2
    Local $iHeight2 = $iHeight - 2
    _GDIPlus_Startup()
    Local $hpen = _GDIPlus_PenCreate("0xFF" & hex($iPenColor, 6))
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hHandle)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
    _GDIPlus_GraphicsFillEllipse($hGraphics, 1, 1, $iWidth2, $iHeight2)
    Local $xPoint = (($iWidth2 / 2) * Cos(_Radian(135))) + $iWidth2 / 2
    Local $yPoint = (($iHeight2 / 2) * Sin(_Radian(135))) + $iHeight2 / 2
    _GDIPlus_GraphicsDrawLine($hGraphics, $iWidth2 / 2, $iHeight2 / 2, $xPoint, $yPoint, $hpen)
    $oBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth2,$iHeight2,$hGraphics)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($oBitmap,0x00000000)
    GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) ;  = STM_SETIMAGE
    Local $aPot[7] = [$iPic, $hHandle, $hBitmap, $iBkColor, $iPenColor, $iMinValue, $iMaxValue]
    _GDIPlus_BitmapDispose($oBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_PenDispose($hpen)
    _gdiplus_shutdown()
    Return $aPot
EndFunc   ;==>_CreatePot
Func _DestryPot($aPot)
    _WinAPI_DeleteObject($aPot[2])
EndFunc   ;==>_DestryPot

The Graphic is well created, but when i try to put into the picture to the graphic instead of drawing it all the times, the picture looks all black.

I post the code without the bitmap issue to show you that the code that generates the graphic is correct.

#include <winapi.au3>
#include <gdiplus.au3>
#include <array.au3>
#include <Math.au3>
#include <Constants.au3>
#include <Staticconstants.au3>
#include <WindowsConstants.au3>
Global Const $STM_SETIMAGE = 0x172
global $hpen
global $hGraphics

$hGui = GUICreate("Pot by monoscout999", -1, -1)
GUISetState()
$aPot = _CreatePot(10, 10)


While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            _DestryPot($aPot)
            Exit
        case $aPot[0]
            consolewrite("im here"&@crlf)

    EndSwitch
WEnd
Func _CreatePot($iX, $iY, $iBkColor = 0, $iPenColor = 0x00FF00, $iDieameter = 50, $iMinValue = 0, $iMaxValue = 250)
    local $iWidth = $iDieameter
    local $iHeight = $iDieameter
    Local $iPic = GUICtrlCreatePic("", $iX, $iY, $iWidth, $iHeight)
    Local $hHandle = GUICtrlGetHandle($iPic)
    Local $iWidth2 = $iWidth - 2
    Local $iHeight2 = $iHeight - 2
    _GDIPlus_Startup()
    $hpen = _GDIPlus_PenCreate("0xFF" & hex($iPenColor, 6))
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hHandle)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
    _GDIPlus_GraphicsFillEllipse($hGraphics, 1, 1, $iWidth2, $iHeight2)
    Local $xPoint = (($iWidth2 / 2) * Cos(_Radian(135))) + $iWidth2 / 2
    Local $yPoint = (($iHeight2 / 2) * Sin(_Radian(135))) + $iHeight2 / 2
    _GDIPlus_GraphicsDrawLine($hGraphics, $iWidth2 / 2, $iHeight2 / 2, $xPoint, $yPoint, $hpen)
    Local $aPot[7] = [$iPic, $hHandle, "", $iBkColor, $iPenColor, $iMinValue, $iMaxValue]

    Return $aPot
EndFunc   ;==>_CreatePot
Func _DestryPot($aPot)
    _WinAPI_DeleteObject($aPot[2])
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_PenDispose($hpen)
    _gdiplus_shutdown()
EndFunc   ;==>_DestryPot
Edited by monoscout999

Share this post


Link to post
Share on other sites



You can use somethin' like this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_GDIPlus_Startup()
Global Const $hGUI = GUICreate("Test", 320, 256)
Global Const $idPic = GUICtrlCreatePic("", 50, 50, 100, 100)
GUISetState()
Global Const $hBmp =  Create_Bitmap(100, 100)
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp))

While 1
    Switch GUIGetMsg()
        Case -3
            _Exit()
        Case $idPic
            MsgBox(0, "Test", "Picture was clicked!")
    EndSwitch
WEnd

Func Create_Bitmap($width, $height)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($width, $height)
    Local Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    _GDIPlus_GraphicsFillPie($hContext, 0, 0, $width, $height, 0, 350, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hContext)
    Local Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBITMAP
EndFunc

Func _Exit()
    _WinAPI_DeleteObject($hBmp)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
EndFunc

Br,

UEZ


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

#3 ·  Posted (edited)

You can use somethin' like this:

Br,

UEZ

Yes that is working creating the bitmap before and editin it is the way to do it, thank you.

I will keep this thread open to ask for anything that may need to about this proyect.

Edited by monoscout999

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
Sign in to follow this  
Followers 0