-
Posts
260 -
Joined
-
Last visited
Profile Information
-
Location
06450
Recent Profile Visitors
1,119 profile views
buymeapc's Achievements

Universalist (6/7)
2
Reputation
-
mLipok reacted to a post in a topic: SQL ADO Get Print Messages?
-
Thank you so much for your helpful links, mLipok!! I am finally able to display the output now. Here's my example which I'm finally able to see the output in the console. #include-once #include <array.au3> #include "ADO.au3" Global $oADODB_Connection = ObjCreate("ADODB.Connection") _Example() Func _Example() ; Error monitoring. This will trap all COM errors while alive. ; This particular object is declared as local, meaning after the function returns it will not exist. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") Local $sPassword ='MyPassword' $oADODB_Connection.Open("PROVIDER=SQLOLEDB.1;SERVER=localhost;DATABASE=mydb;uid=sa;pwd="&$sPassword&";") Local $objquery = $oADODB_Connection.Execute("if 1 = 1 print 'this is a test - hello'") Local $test = $objquery.Parent ;ConsoleWrite('Before CommitTrans' & @CRLF) ;$oADODB_Connection.CommitTrans EndFunc ;==>_Example ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) Local $iErrorCol_Max = $oADODB_Connection.errors.Count If $iErrorCol_Max = 0 Then ConsoleWrite( @CRLF & _ "! ==> COM Error intercepted ==> NOT ADO related Error " & @CRLF & _ "-" & @TAB & "$oError.description is: " & @TAB & $oError.description & @CRLF & _ "-" & @TAB & "$oError.number is: " & @TAB & @TAB & $oError.number & " in HEX is 0x" & Hex($oError.number) & @CRLF & _ "-" & @TAB & "$oError.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ "-" & @TAB & "$oError.windescription:" & @TAB & @TAB & $oError.windescription & @CRLF & _ "-" & @TAB & "$oError.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "-" & @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "-" & @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "-" & @TAB & "$oError.scriptline is: " & @TAB & @TAB & $oError.scriptline & @CRLF & _ "-" & @TAB & "$oError.retcode is: " & @TAB & @TAB & "0x" & Hex($oError.retcode) & @CRLF & _ "! ==> COM End of Error dump." & @CRLF & _ @CRLF) Else Local $oErr For $iErrorCol_idx = 0 To $iErrorCol_Max - 1 $oErr = $oADODB_Connection.errors.Item($iErrorCol_idx) ConsoleWrite( @CRLF & _ "! ==> COM Error intercepted ==> ADO Error Collection: .errors.Count = " & $iErrorCol_Max & " $oErr = .errors.Item(" & $iErrorCol_idx & ") " & @CRLF & _ ">" & @TAB & "$oErr.description is: " & @TAB & @TAB & $oErr.description & @CRLF & _ ">" & @TAB & "$oErr.number is: " & @TAB & @TAB & $oError.number & " in HEX is 0x" & Hex($oErr.number) & @CRLF & _ ">" & @TAB & " ErrorValueEnum description:" & @TAB & _ADO_MSDNErrorValueEnum_Description("0x" & Hex($oErr.number)) & @CRLF & _ ">" & @TAB & "$oErr.source is: " & @TAB & @TAB & $oErr.source & @CRLF & _ ">" & @TAB & "$oErr.SQLState is: " & @TAB & @TAB & $oErr.SQLState & ' Description: ' &_SQLState_Description($oErr.SQLState) & @CRLF & _ ">" & @TAB & "$oErr.NativeError is: " & @TAB & @TAB & $oErr.NativeError & @CRLF & _ "-" & @TAB & "$oError.windescription:" & @TAB & @TAB & $oError.windescription & @CRLF & _ "-" & @TAB & "$oError.scriptline is: " & @TAB & @TAB & $oError.scriptline & @CRLF & _ "-" & @TAB & "$oError.helpfile is: " & @TAB & @TAB & $oError.helpfile & @CRLF & _ "-" & @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "-" & @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "-" & @TAB & "$oError.retcode is: " & @TAB & @TAB & "0x" & Hex($oError.retcode) & @CRLF & _ "-" & @TAB & "$oError.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ "! ==> COM End of Error Collections dump." & @CRLF & _ @CRLF) Next $oADODB_Connection.errors.clear EndIf EndFunc ;==>_ErrFunc
-
Hello all, I have a SQL database that I'm running scripts on in order to update the contents of the database. Some of these scripts have try/catch statements, which include print statements. I can see the print statements if I use SSMS, but I'm not sure how to get them using AutoIt while running the script. I was originally using SQL.au3, but I have also been trying to use ADO.au3. With the very simplified script below using ADO.au3, how can I display the print statement result of 'hello'? Thanks for your help! #include "ADO.au3" ; SetUP internal ADO.au3 UDF COMError Handler _ADO_ComErrorHandler_UserFunction(_ADO_COMErrorHandler) $sDatabase = 'mydb' ; change this string to YourDatabaseName $sServer = 'localhost' ; change this string to YourServerLocation $sUser = 'sa' ; change this string to YourUserName $sPassword = 'MyPassword' ; change this string to YourPassword ;_Example_4_MSSQL_SQLAuth($sServer, $sDatabase, $sUser, $sPassword, "Select * from MY_TABLE"); this works fine! _Example_4_MSSQL_SQLAuth($sServer, $sDatabase, $sUser, $sPassword, "if 1 = 1 print 'hello'"); how do I return the print message? Func _Example_4_MSSQL_SQLAuth($sServer, $sDatabase, $sUser, $sPassword, $sQUERY) ; Create connection object Local $oConnection = _ADO_Connection_Create() ; Open connection with $sConnectionString _ADO_Connection_OpenMSSQL($oConnection, $sServer, $sDatabase, $sUser, $sPassword, 'YourAppName', @ComputerName & '_' & 'YourProgram_UID') If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) ; Executing some query directly to Array of Arrays (instead to $oRecordset) Local $aRecordset = _ADO_Execute($oConnection, $sQUERY, True) ; Clean Up _ADO_Connection_Close($oConnection) $oConnection = Null ; Display Array Content with column names as headers _ADO_Recordset_Display($aRecordset, 'Recordset content') EndFunc ;==>_Example_4_MSSQL_SQLAuth
-
Test SQL 2016 Connection with CLR
buymeapc replied to buymeapc's topic in AutoIt General Help and Support
Thank you very much for the help with this, ptrex! This helps a lot to get me started. -
Hello, I was looking for a way to use the CLR functions to check a SQL 2016 database state, but I've been unable to find an example that I can get to work. Any help would be appreciated. Here's what I have, which always errors when I try to set the connection string and I'm not sure why. Thanks! #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" JustATest() Func JustATest() Local $oAssembly = _CLR_LoadLibrary("System.Data") ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $oSQLConn = _CLR_CreateObject($oAssembly, "System.Data.SqlClient.SqlConnection") ConsoleWrite("$oSQLConn: " & IsObj($oSQLConn) & @CRLF) $oSQLConn.ConnectionString = "Server=serverip;Database=dbname;UID=user;PWD=aaaa;" $oSQLConn.Open EndFunc Edit: I am using ptrex's CLR UDF from here:
-
.NET Common Language Runtime (CLR) Framework
buymeapc replied to ptrex's topic in AutoIt Example Scripts
Moved post to help forum -
buymeapc reacted to a post in a topic: FileOpen("con") not working
-
Local $iReturn = RunWait('msiexec /i \\@ScriptDir & \VNC UltraVnc_1224_X64.msi /loadinf="VNCConfig.ini" /props="VNCsetup.reg" /silent ' ) I think you're missing an extra quote here. Local $iReturn = RunWait('msiexec /i \\' & @ScriptDir & '\VNC UltraVnc_1224_X64.msi /loadinf="VNCConfig.ini" /props="VNCsetup.reg" /silent ' ) More importantly, what happens when you type msiexec.exe into a command prompt? You should get a "Windows Installer" window with command line options.
-
Thank you for the help, Melba! That was just what I needed. Hmm...good point. I did not think to post to your UDF thread. I will definitely post there if I have another question. Thanks again.
-
Hey gang, I've taken advantage of Melba's excellent scrollbar UDF for my GUI and I'm having a great time with it, but I'm encountering an issue that I'm hoping to get some help on. Once the GUIs are loaded, things work great. However, if I scroll all the way to the bottom, then maximize the window, the scrollbar stays where it is and the secondary window is proportioned properly, but I can now scroll up into basically empty space. I'm not quite sure how to remedy this. Here's a quick reproducer to show what I'm talking about. All you need to do to replicate is scroll the scrollbar to the bottom of the window, then maximize the window. You'll see the scrollbar at the bottom of the window and the controls that were at the top, are now in view and I can now scroll up into nothingness. Any help would be greatly appreciated. Thanks!! #include <GUIScrollBars_Ex.au3> $iLeft = 5 ; The distance of the labels from the left edge of the window $iTop = 40 ; First label's distance from the top edge of the window $iWidth = 100 ; Width of labels $iHeight = 25 ; Height of labels $iSpacing = 30 ; Vertical distance between the labels $hGUI = GUICreate('Calculate exact scrollheight for dynamic labels after maximize window', 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX)) GUICtrlCreateTab(2, 2, 496, 496) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) GUICtrlCreateTabItem("Example") $hGUI2 = GUICreate("", 488, 464, $iLeft, 26, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) For $i = 1 To 50 GUICtrlCreateLabel('Label ' & $i, $iLeft, $iTop, $iWidth, $iHeight) GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetResizing(-1, $GUI_DOCKALL) ; Prevent resizing $bot = $iTop + $iHeight ; Bottom edge of the last label $iTop = $bot + $iSpacing ; Top of next label Next $cButton = GUICtrlCreateButton("Maximize", 400, 40, 50, 30) GUICtrlCreateTabItem("") $iMaxScrollHeight = $iTop _GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hGUI2) GUIRegisterMsg($WM_SIZE, "_WM_SIZE") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton GUISetState(@SW_MAXIMIZE) EndSwitch Wend Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam If $hWnd = $hGUI Then ; Get new GUI size Local $aGUI_Size = WinGetClientSize($hGUI) ; Resize scroll GUI WinMove($hGUI2, "", Default, Default, ($aGUI_Size[0] - 14), ($aGUI_Size[1] - 34)) ; Create scrollbar if needed If $aGUI_Size[1] < $iMaxScrollHeight Then _GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight) EndIf EndIf EndFunc ;==>_WM_SIZE
-
[SOLVED] GDIPlus image created with a faint border??
buymeapc replied to buymeapc's topic in AutoIt General Help and Support
@UEZ That was indeed all it needed. Thank you so much for your help!! -
Hey all, Thanks to the forums, I've managed to create a Base64 image that I can use as a partial background for my GUI. However, the issue I'm having is that when the image is created, you can see a faint border around where the image is created. Is there any way to create the image without having this border created, so it can blend in? Here's a small reproducer. Thanks for the help! #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("Blending a pic in with the BG", 450, 144) GUISetBkColor(0xFFFFFF, $hGUI) GUISetState() $idPic2 = GUICtrlCreatePic("", 150, 0, 300, 144) ; resized picture $hBitmap2 = _GDIPlus_BitmapCreateFromMemory(_OptumFade()) $hBitmap_resized = _GDIPlus_ImageResize($hBitmap2, 300, 144) ;GDI+ bitmap $hHBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_resized) ;GDI bitmap _WinAPI_DeleteObject(GUICtrlSendMsg($idPic2, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap2)) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2015-01-20 Func _OptumFade($bSaveBinary = False, $sSavePath = @ScriptDir) Local $OptumFade $OptumFade &= 'iVBORw0KGgoAAAANSUhEUgAAASMAAABGCAYAAACHbvJwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAlDSURBVHhe7Z3teqrKEoQB3fd/t2f/SMBTVd0No2KiYFbY66nXhcxHd08DMxWiLtP/799/L90TTLC6jJeu77MhofPShNJQ4bKVjgMLreMFsaI0DGi/ckEf63w6RSNauv4S/izzn8qw6emEvdplO8FWRUEblekmv0m2EYe+3PGJ/TKIPWOim8fL444eAFvmMuK4wm9S8wUHOeT4E33RHylE/jk4QI1FbCN8mX9Y0AZlxGS/spzwDJtLtteBVCh5Mh+2051PONeRbxipL0tRlOE6zFs7xOR1KV8eo05E1nMXRLxlvJ+H50PzRjmtHAzb2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eCWvMb/DrYsS1UVsR9aVFCyhX0SwIK/SXPvtn87le4cqfbbJXFx/qjVo6xJfOwS6/W66+hO7CBtpUrPSpredGW8RPx/BrbDQWd0Sh6LfY0F5dtG3saq9ihlel+kjVq62pZ9i/n+aYvb2wfcUj+3Z/20fW+ousa86P09h2/Qj9ygjVpMWmFYJk1NB1k9onfg1l5KontvbdFJVYrCwmjDNNaOBguahpwu/2Zl2xWdcfHqAj/VHOsaM+ZpxJ8WmmP1KgWCkUGIPfCK5hWM8kODZtCfuYJ/17yT189T3jcpKf2suOvojKLBUHD6WleuRCaKc0aZMndWDsKCqufPlIHyZzfYkZA33ZzerfAA+pzkOQ19x8y3LaotSey7nMk6m26/OqeZj98w/fpOboWj/nabSFzdSNXf/x+ZEeP0fl1FJNQ2WKvZYyqqpRUHoue9hg4U48ECzMWsUlKiVKWogoD3KOvsuEisz5JwXkhtghKjx8FNgFBtToE3F6LuDoVlmxaCgDmDMVhmM/SyPzg83AToCmaRw7Dk+jnjkzX9XZRGGiIf8yi4LwnzqVM/eZD/OdeAJTpBibcXAUygGnCOmjAf2KRU4UI+zZF14zPe3YIgPQdv6HmReNThrnDuYCr735Fk3tKGmtzucSzOV5ulyfV/2AZB0xbuX/euahX4szuOAHJOfxkGum77ru/yXLKH+v3ak0AAAAAElFTkSuQmCC' Local Const $bString = Binary(_WinAPI_Base64Decode($OptumFade)) If $bSaveBinary Then Local Const $hFile = FileOpen($sSavePath & "\Optum_Fade_291x70.png", 18) If @error Then Return SetError(1, 0, 0) FileWrite($hFile, $bString) FileClose($hFile) EndIf Return $bString EndFunc ;==>_OptumFade Func _WinAPI_Base64Decode($sB64String) Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "") Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]") $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "") Return DllStructGetData($bBuffer, 1) EndFunc ;==>_WinAPI_Base64Decode
-
Trying to Create Custom Radios
buymeapc replied to buymeapc's topic in AutoIt General Help and Support
I guess my hopes were two-fold here. I was hoping that either: There was a way to simply color the dot in the radio button when checked (understood that it would be system-wide) Or someone had created a UDF that simplifies the way I've displayed above into a neat & portable function as I find the bools to check the state "messy" -
Hi all, I'm trying to create custom radio buttons. Basically, if I could simply color the dot of the checked radio button (orange), I would be satisfied. So, for the moment, I'm stuck with using an icon+label solution which isn't elegant at all. I'm wondering if there's a better way to do this than what I have below. I'm just using random shell32 icons as the example here. Any help is greatly appreciated. Thanks! Dim $iIcon_Checked = 15 Dim $iIcon_Unchecked = 0 Dim $bCheck1 = True Dim $bCheck2 = False $hGUI = GUICreate("Test GUI", 200, 200) $idIcon1 = GUICtrlCreateIcon("shell32.dll", $iIcon_Checked, 10, 10, 13, 13) $idLabel1 = GUICtrlCreateLabel("Radio 1", 25, 11, 60) ; ------- $idIcon2 = GUICtrlCreateIcon("shell32.dll", $iIcon_Unchecked, 10, 30, 13, 13) $idLabel2 = GUICtrlCreateLabel("Radio 2", 25, 31, 60) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $idIcon1, $idLabel1 $bCheck1 = Not $bCheck1 If $bCheck1 Then GUICtrlSetImage($idIcon1, "shell32.dll", $iIcon_Checked) GUICtrlSetImage($idIcon2, "shell32.dll", $iIcon_Unchecked) Else GUICtrlSetImage($idIcon1, "shell32.dll", $iIcon_Unchecked) GUICtrlSetImage($idIcon2, "shell32.dll", $iIcon_Checked) EndIf Case $idIcon2, $idLabel2 $bCheck2 = Not $bCheck2 If $bCheck2 Then GUICtrlSetImage($idIcon1, "shell32.dll", $iIcon_Unchecked) GUICtrlSetImage($idIcon2, "shell32.dll", $iIcon_Checked) Else GUICtrlSetImage($idIcon1, "shell32.dll", $iIcon_Checked) GUICtrlSetImage($idIcon2, "shell32.dll", $iIcon_Unchecked) EndIf EndSwitch WEnd
-
Disabled Context Items Look Odd
buymeapc replied to buymeapc's topic in AutoIt General Help and Support
-
buymeapc reacted to a post in a topic: Disabled Context Items Look Odd
-
Hello all, I've been working on a script that has many dynamically created context menus with icons for specific listview items. Depending on the listview item that was right-clicked, different menu choices are displayed. The best way to do this that I found was to use the "_GUICtrlMenu" UDF functions with WM_NOTIFY and UEZ's awesome _GUICtrlMenu_CreateBitmap function. All in all, things work great until I disable an item that also has an icon. The icon turns all black or discolored instead of having that "disabled" look of being grayed out. I've put together a simple reproducer to show what I'm talking about as well as a pic that displays the disabled icon from my main script Is there any way to make the disabled menu item's icon look grayed out and not black/discolored? Thanks!! #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GUIMenu.au3> #include <WindowsConstants.au3> Global $cDummy Global $hList $hGUI = GUICreate("Disabled Menu Item Test", 500, 300) $cDummy = GUICtrlCreateDummy() $idList = GUICtrlCreateListView("Col1|Col2|Col3", 10, 10, 480, 280) $hList = GUICtrlGetHandle(-1) GUICtrlCreateListViewItem("Test1|Test2|Test3", $idList) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cDummy _ShowContext($idList) EndSwitch WEnd Func _ShowContext($hWnd) Local Enum $idTest1 = 1000, $idTest2 Local $sIconPath = @ProgramFilesDir & "\AutoIt3\Icons\au3.ico" Local $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($hMenu, "Test1" & @TAB & "Ctrl+1", $idTest1) _GUICtrlMenu_SetIcon($hMenu, 0, $sIconPath) _GUICtrlMenu_AddMenuItem($hMenu, "Test2" & @TAB & "Ctrl+2", $idTest2) _GUICtrlMenu_SetIcon($hMenu, 1, $sIconPath); <<<<<<< Any way to make this work with transparency? _GUICtrlMenu_SetItemDisabled($hMenu, 1) Local $idMsg = _GUICtrlMenu_TrackPopupMenu($hMenu, GUICtrlGetHandle($hWnd), -1, -1, 1, 1, 2) Switch $idMsg Case $idTest1 ConsoleWrite(">> Test1" & @CRLF) Case $idTest2 ConsoleWrite(">> Test2" & @CRLF) EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) EndFunc Func _GUICtrlMenu_SetIcon($hWnd, $iIndex, $sIconPath) Local $hBMP_File_New = _GUICtrlMenu_CreateBitmap($sIconPath, 0, 16, 16) Return _GUICtrlMenu_SetItemBmp($hWnd, $iIndex, $hBMP_File_New) EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $iItem Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $HwndFrom = DllStructGetData($tNMHDR, "HwndFrom") Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $HwndFrom Case $hList Switch $iCode Case $NM_RCLICK $iItem = DllStructGetData(DllStructCreate($tagNMITEMACTIVATE, $lParam), "Index") If $iItem <> -1 Then GUICtrlSendToDummy($cDummy) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ; #FUNCTION# ============================================================================================================ ; Name...................: _GUICtrlMenu_CreateBitmap ; Description .......: Extracts the icon from $sFile and converts it to a HBitmap format ; Syntax................: _GUICtrlMenu_CreateBitmap($sFile, $iIndex = 0, $iX = 18, $iY = 18) ; Parameters ......: $sFile - file name where the icon should be extracted from or an image should be loaded (*.dll, *.ico, *.exe, *.jpg, *.png, *.bmp, *.gif, *.tif) ; $iIndex - index of the icon from $sFile ; $iX - set the width of the extracted icon ; $iY - set the height of the extracted icon ; Return values .: Success - handle to a HBITMAP ; Failure - Returns 0 and sets error to 1-7 ; Author ..............: UEZ ; Version .............: v0.70 Build 2012-10-13 beta ; Remarks ...........: Don't forget to use _WinAPI_DeleteObject($<handle to the HBITMAP>) when closing to to release the resources ; ======================================================================================================================= Func _GUICtrlMenu_CreateBitmap($sFile, $iIndex = 0, $iW = 18, $iH = 18) Local $hIcon, $Ret, $hBitmap, $hContext, $bBinary = False Local $aChk = _GDIPlus_ImageGetFlags($sFile) If Not @error Then $bBinary = True If FileExists($sFile) Or $bBinary Then Local Const $iStride = 0, $iPixelFormat = $GDIP_PXF32ARGB, $pScan0 = 0 Local $fext = StringMid($sFile, StringLen($sFile) - 3) If $bBinary Then $fext = "0815" Switch $fext Case ".dll", ".exe", ".ico" Return _WinAPI_GetFileIcon($sFile, $iIndex, $iW, $iH) Case ".jpg", ".png", ".bmp", ".gif", ".tif", "0815" Local $hImage If Not $bBinary Then $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then Return SetError(4, @extended, 0) Else $hImage = $sFile EndIf Local $hBitmap = _GDIPlus_BitmapCreateFromHICON32($hImage) ;~ $Ret = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) ;~ If @error Then Return SetError(5, @extended, 0) ;~ $hBitmap = $Ret[6] $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hContext, "int", 7) _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iW, $iH) $hIcon = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hImage) If Not $hIcon Then Return SetError(6, 0, 0) Case Else Return SetError(7, 0, 0) EndSwitch Return $hIcon Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_GUICtrlMenu_CreateBitmap Func _WinAPI_GetFileIcon($sFile, $iIndex = 0, $iW = 18, $iH = 18, $iColor = -1) Local $aRet, $hIcon, $hHBitmap Local $hDC, $hBackDC, $hBackSv $aRet = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sFile, 'int', $iIndex, 'int', $iW, 'int', $iH, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0) If @error Then Return SetError(6, @extended, 0) $hIcon = $aRet[5] $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) If $iColor = -1 Then $iColor = _WinAPI_GetSysColor($COLOR_MENU) $hHBitmap = _WinAPI_CreateSolidBitmap(0, $iColor, $iW, $iH) $hBackSv = _WinAPI_SelectObject($hBackDC, $hHBitmap) _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, $iW, $iH) _WinAPI_DestroyIcon($hIcon) _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteDC($hBackDC) Return $hHBitmap EndFunc ;==>_GUICtrlMenu_CreateBitmap
-
Use A Custom Checkbox State Image?
buymeapc replied to buymeapc's topic in AutoIt General Help and Support
Hmm...I don't think I'm quite understanding how to implement this properly. If I use $BS_PUSHLIKE, it looks like a button and not a checkbox. However, if I remove that style and set it back as $BS_AUTOCHECKBOX, I now see the original checkbox and the custom one I'm adding. Also, when I hover over the checkbox, the "checked" icon shows up until I move the mouse cursor away... #include <GUIButton.au3> #include <GUIConstantsEx.au3> #include <GUIImageList.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> Global $g__bBool = False $hGUI = GUICreate("Test", 200, 200) $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, "C:\Users\username\Documents\checkbox_empty.ico") _GUIImageList_AddIcon($hImage, "C:\Users\username\Documents\checkbox_filled.ico") ;$idCheck = GUICtrlCreateCheckbox("Something", 10, 70, 68, 17, $BS_PUSHLIKE); <<<< This shows a button without a checkbox $idCheck = GUICtrlCreateCheckbox("Something", 10, 70, 68, 17, $BS_AUTOCHECKBOX); <<<< This looks better, but shows the original *and* custom checkboxes _GUICtrlButton_SetImageList($idCheck, $hImage) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd