Kip Posted June 17, 2008 Posted June 17, 2008 Hi,I'm trying to create a static control (already done that) with an image. (can't get that working)This is what I have now:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <UDFGlobalID.au3> #include <SendMessage.au3> $Gui = GUICreate("bla") GUISetState() _Image_Create($Gui, @ScriptDir&"\PageTwoItem.bmp", 10, 10, 55, 55) While 1 WEnd Func _Image_Create($hWnd, $sPath, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) $nCtrlID = _UDF_GetNextGlobalID($hWnd) $hBitmap = _WinAPI_LoadImage(0, $sPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) $hImage = _WinApi_CreateWindowEx($iExStyle, "Static", $hBitmap, _ $WS_VISIBLE+$WS_CHILD+$SS_NOTIFY+$SS_BITMAP+$iStyle, _ $iX, $iY, $iWidth, $iHeight, _ $hWnd, $nCtrlID, 0, 0) $STM_SETIMAGE = 0x172 _SendMessage($hImage,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap) return $hImage EndFuncBut that doesn't work... (like I already said) MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Zedna Posted June 17, 2008 Posted June 17, 2008 AutoIt 3.2.10 syntax:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> ;~ #include <UDFGlobalID.au3> ;~ #include <SendMessage.au3> $Gui = GUICreate("bla", 400,300) GUISetState() _Image_Create($Gui, @ScriptDir&"\PageTwoItem.bmp", 10, 10, 55, 55) While 1 Sleep(100) WEnd Func _Image_Create($hWnd, $sPath, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) $CtrlID = GUICtrlCreateLabel('',$iX, $iY, $iWidth, $iHeight) $hBitmap = _WinAPI_LoadImage(0, $sPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) _SetBitmapToCtrl($CtrlId, $hBitmap) EndFunc 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_SetBitmapToCtrl() used from my resources UDFhttp://www.autoitscript.com/forum/index.ph...st&p=386541 Resources UDF ResourcesEx UDF AutoIt Forum Search
Kip Posted June 17, 2008 Author Posted June 17, 2008 (edited) That is a normal label. I really need one created with _CreateWindowEx. $nCtrlID = _UDF_GetNextGlobalID($hWnd) $hBitmap = _WinAPI_LoadImage(0, $sPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) $hImage = _WinApi_CreateWindowEx($iExStyle, "Static", $hBitmap, _ $WM_PAINT+$WS_VISIBLE+$WS_CHILD+$SS_NOTIFY+$SS_BITMAP+$iStyle, _ $iX, $iY, $iWidth, $iHeight, _ $hWnd, $nCtrlID, 0, 0) $STM_SETIMAGE = 0x172 _SetBitmapToCtrl($hImage, $hBitmap) This, again, doesn't work. Edited June 17, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Kip Posted June 18, 2008 Author Posted June 18, 2008 bump MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Kip Posted June 18, 2008 Author Posted June 18, 2008 I'm trying to create a label and image control created with CreateWindowEx, and I already have the label: Func _GUICtrlLabel_Create($hWnd, $sText, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) $nCtrlID = _UDF_GetNextGlobalID($hWnd) $hLabel = _WinApi_CreateWindowEx($iExStyle, "Static", $sText, _ $WS_VISIBLE+$WS_CHILD+$SS_NOTIFY+$iStyle, _ $iX, $iY, $iWidth, $iHeight, _ $hWnd, $nCtrlID, 0, 0) _WinAPI_SetFont($hLabel, _WinAPI_GetStockObject($DEFAULT_GUI_FONT)) return $hLabel EndFunc MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
ProgAndy Posted June 18, 2008 Posted June 18, 2008 You have to chagen setimage to accept Handles and not just CtrlIDs CODE#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> ;~ #include <UDFGlobalID.au3> ;~ #include <SendMessage.au3> $Gui = GUICreate("bla", 400,300) GUISetState() _Image_Create($Gui, @SystemDir & "\oemlogo.bmp", 10, 10, 55, 55) While 1 Sleep(100) WEnd Func _Image_Create($hWnd, $sPath, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) $CtrlID = _GUICtrlLabel_Create($hWnd,'',$iX, $iY, $iWidth, $iHeight) $hBitmap = _WinAPI_LoadImage(0, $sPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) _SetBitmapToCtrl($CtrlId, $hBitmap) EndFunc Func _GUICtrlLabel_Create($hWnd, $sText, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) ;~ $nCtrlID = _UDF_GetNextGlobalID($hWnd) $hLabel = _WinApi_CreateWindowEx($iExStyle, "Static", $sText, _ $WS_VISIBLE+$WS_CHILD+$SS_NOTIFY+$iStyle, _ $iX, $iY, $iWidth, $iHeight, _ $hWnd);, $nCtrlID, 0, 0) ;~ _WinAPI_SetFont($hLabel, _WinAPI_GetStockObject($DEFAULT_GUI_FONT)) return $hLabel EndFunc 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 IsHWnd($CtrlID) And WinExists($CtrlID) Then $hWnd = $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 And btw, why do you use GetNextGlobalID? THe parameter after $hwnd is for a Menuhandle, not for an ID. The ID is genersted automatically *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Kip Posted June 18, 2008 Author Posted June 18, 2008 (edited) GuiCtrlCreatePicHave you ever read my topic? I'm not that dumb (yes, i'm serious ) @ProgAndy: Thanks, that works And btw, why do you use GetNextGlobalID? THe parameter after $hwnd is for a Menuhandle, not for an ID. The ID is genersted automatically smile.gifBecause all the other _GUICtrl UDFs use that, it was kinda weird to me too. I have this: Func _Image_Create($hWnd, $sPath, $iX, $iY, $iWidth, $iHeight, $iStyle=0, $iExStyle=0) Local Const $STM_SETIMAGE = 0x0172 Local Const $SS_BITMAP = 0xE $hImage = _WinApi_CreateWindowEx($iExStyle, "Static", "", $WS_VISIBLE+$WS_CHILD+$SS_NOTIFY+$SS_BITMAP+$iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd) $hBitmap = _WinAPI_LoadImage(0, $sPath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) Local $hOldBitmap = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hImage, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap) If $hOldBitmap[0] <> 0 Then _WinAPI_DeleteObject($hOldBitmap[0]) EndFuncBut when I comment out the 4th line (where $SS_BITMAP is declared) it doesn't work anymore. So, is the $SS_BITMAP of StaticConstants.au3 wrong? Edit: From StaticConstants.au3: "Global Const $SS_BITMAP = 15" = Dec(0xE) Edited June 18, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Siao Posted June 18, 2008 Posted June 18, 2008 The ID is genersted automatically No it's not. Unless you are talking about controls made with native GuiCtrlCreate... functions, but topic starter is way too smart to use these. "be smart, drink your wine"
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