taotao878 Posted May 7, 2008 Share Posted May 7, 2008 (edited) #include <GuiConstantsEX.au3> #include <GDIPlus.au3> #include "resources.au3" _GDIPlus_Startup() $hGui = GUICreate("show png", 350, 300) $hPic = GUICtrlCreatePic("", 25, 25, 300, 200) $Button = GUICtrlCreateButton("view", 130, 250, 75, 21) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button $OpenFile = FileOpenDialog("Select image file", "", "image(*.png)") _GUICtrlStatic_SetPicture($OpenFile, $hPic) EndSwitch WEnd FUnc _GUICtrlStatic_SetPicture($File, $CtrlId) $hImage = _GDIPlus_ImageLoadFromFile($File) $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) GUICtrlSetImage($CtrlId, "") _SetBitmapToCtrl($CtrlId, $hBitmap) EndFUnc Edited May 8, 2008 by taotao878 Link to comment Share on other sites More sharing options...
gseller Posted May 7, 2008 Share Posted May 7, 2008 Are youy going to share #include "resources.au3" Link to comment Share on other sites More sharing options...
Zedna Posted May 7, 2008 Share Posted May 7, 2008 Here is link to my resource UDF Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted May 7, 2008 Share Posted May 7, 2008 (edited) This has nothing with resources. It just uses internal helper function _SetBitmapToCtrl() from my UDF: Func _SetBitmapToCtrl($CtrlId, $hBitmap) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 Local Const $SS_BITMAP = 0xE Local Const $GWL_STYLE = -16 Local $hWnd = GUICtrlGetHandle($CtrlId) If $hWnd = 0 Then Return SetError(1, 0, 0) ; set SS_BITMAP style to control Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE) If @error Then Return SetError(2, 0, 0) DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP)) If @error Then Return SetError(3, 0, 0) Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap) If @error Then Return SetError(4, 0, 0) If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0]) Return 1 EndFunc So generally you needn't include whole resources.au3 just copy this one function into your script :-) Edited May 7, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted May 7, 2008 Share Posted May 7, 2008 (edited) Also minor bug: GUICtrlSetImage($CtrlId, "") correction: FUnc _GUICtrlStatic_SetPicture($File, $CtrlId) $hImage = _GDIPlus_ImageLoadFromFile($File) $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) GUICtrlSetImage($CtrlId, "") _SetBitmapToCtrl($CtrlId, $hBitmap) EndFUnc Edited May 7, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search 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