Jump to content

Recommended Posts

Posted

Hi all

I am wondering if someone knows what could be causing the images in my GUI to display little black squares all over them. They seem to change depending on how much code is in the file/program.

I have attached two examples, the first is from a set of buttons called using GUICtrlCreatePic and they are in BMP format

post-60602-0-44654600-1354552051_thumb.j

Shows a screenshot of the GUI image on the left and the original images on the right

The second is also called using GUICtrlCreatePic but they are in JPG format

post-60602-0-21163300-1354552059_thumb.j

Shows a screenshot of the GUI image on the top and the original image on the bottom

Both of them display the same problem although in earlier versions of the code it seemed to just exist on the BMP buttons, although i havent been watching it closely until i noticed them in both places today. They show up whether the script is compiled or not.

Thanks in advance

Adam

Posted

I don't know whether this is a feature or a bug in GUICtrlCreatePic() function. A possible workaround is to load the images with GDI+ and send it to the picture control.

There are a lot of examples how to load an image in GDI+ and send it to a control.

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

Posted

Check the remarks in GUICtrlCreatePic regarding the WS_EX_LAYERED GUI style and transparent images. If that doesn't apply, then I'm out of ideas.

Thanks for the reply, i have checked some of the GUIs in question and the only style we use on them is WS_POPUP and barely use extended styles at all throughout the program

I don't know whether this is a feature or a bug in GUICtrlCreatePic() function. A possible workaround is to load the images with GDI+ and send it to the picture control.

There are a lot of examples how to load an image in GDI+ and send it to a control.

Br,

UEZ

I did look at GDI+ briefly quite a while back but i couldnt really get it to work, do you have a simple small example i could try?

Posted

Try this:

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

_GDIPlus_Startup()
$hGUI = GUICreate("Test", 200, 140)
GUISetBkColor(0x0, $hGUI)
$idPic_Default1 = GUICtrlCreatePic(@ScriptDir & "SwitchOn.bmp", 20, 20, 0, 0)
$idPic_Default2 = GUICtrlCreatePic(@ScriptDir & "SwitchOff.bmp", 20, 90, 0, 0)
$idPic_GDIP1 = GUICtrlCreatePic("", 120, 20, 0, 0)
_GDIPlus_SendImage2Control(@ScriptDir & "SwitchOn.bmp", $idPic_GDIP1)
$idPic_GDIP2 = GUICtrlCreatePic("", 120, 90, 0, 0)
_GDIPlus_SendImage2Control(@ScriptDir & "SwitchOff.bmp", $idPic_GDIP2)
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            _GDIPlus_Shutdown()
            Exit
    EndSwitch
Until False

Func _GDIPlus_SendImage2Control($sImageFile, $idControl) ;coded by UEZ 2012
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sImageFile)
    If @error Then Return SetError(1, 0, 0)
    Local Const $IMAGE_BITMAP = 0, $STM_SETIMAGE = 0x0172
    Local $hHBmp
    If @OSBuild < 6000 Then
        $hHBmp = _GDIPlus_ConvertTransparentBitmap($hBitmap)
    Else
        $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hResult = GUICtrlSendMsg($idControl, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp)
    If $hResult Then _WinAPI_DeleteObject($hResult)
EndFunc

Func _GDIPlus_ConvertTransparentBitmap($hBitmap) ;coded by UEZ 2012
    Local $iButtonColor = _WinAPI_GetSysColor($COLOR_BTNFACE)
    $iButtonColor = 0x10000 * BitAND($iButtonColor, 0xFF) + BitAND($iButtonColor, 0x00FF00) + BitShift($iButtonColor, 16)
    Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap_New = $aResult[6]
    Local $hCtx_new = _GDIPlus_ImageGetGraphicsContext($hBitmap_New)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $iButtonColor)
    _GDIPlus_GraphicsFillRect($hCtx_new, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hCtx_new, $hBitmap, 0, 0, $iWidth, $iHeight)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_New)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BitmapDispose($hBitmap_New)
    _GDIPlus_GraphicsDispose($hCtx_new)
    Return $hHBitmap
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thanks for that example

The GDI+ example doesn't suffer from the same issue, will take a look at re-coding the GUI to use GDI+, do any of the other controls (labels, progress bars) etc get affected by GDI+? Also does GDI+ work natively on Windows XP, Vista and 7?

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
×
×
  • Create New...