
footswitch
Active Members-
Posts
203 -
Joined
-
Last visited
Everything posted by footswitch
-
I don't want to get too much out of topic here, so I'll be brief just for the sake of letting people know the result of my experiment. Your script works like a charm for small files, which is probably what it was intended for in the first place. Starting with a filesize of 500kB or so it becomes really slow, perhaps proportionally - I haven't checked. So now I'm zipping the files before inserting them into the database, in binary form. Care must be taken to INSERT, UPDATE and SELECT small chunks of data at a time. SUBSTRING(field_name, binary_start_pos, binary_read_bytes) and DATALENGTH(field_name) seem to work well, but I've read that depending on the SQL Server's version, datalength() results can vary. Why zip? Well, it's a widely used format and it comes integrated with Windows since... whenever. Plus, if in the future some data recovery needs to be done, it'll be much easier to determine what kind of data is or should be there. I'm using this UDF: Thanks again!
- 164 replies
-
Oops. I believe you forgot about _OL_FolderAccess(). Isn't accepting a folder object. For me I just added this check before the main If clause: If IsObj($sOL_Folder) Then If $sOL_Folder.Class <> $olFolder Then Return SetError(1, 0, "") ; object is not a folder Else (...) Oh and _OL_ItemCopy(). When a destination folder isn't specified, use the folder of the source item. Added this If clause after the line Local $oOL_SourceFolder = $vOL_Item.Parent If $vOL_TargetFolder == "" Then $vOL_TargetFolder = $oOL_SourceFolder Else If Not IsObj($vOL_TargetFolder) Then If StringStripWS($vOL_TargetFolder, 3) = "" Then $vOL_TargetFolder = $oOL_SourceFolder Local $aOL_Temp = _OL_FolderAccess($oOL, $vOL_TargetFolder) If @error Then Return SetError(2, @error, 0) $vOL_TargetFolder = $aOL_Temp[1] EndIf EndIf Don't be upset about the trouble it's been causing. Error checking in UDFs is a major help for a lot of us. Those of us who don't want it, probably will skip to the source anyway
-
Your latest release 0.7.1.1 seems to have fixed the issues I was having with unexpected error returns! Looking good!
-
AutoIt Login Form without MySQL
footswitch replied to ProgrammerKid's topic in AutoIt GUI Help and Support
Sure thing -
About the last script posted by rover, here's a quick fix for multi-selection (replace the declaration of $bSelected and adjust the If statement) Local $bSelected = GUICtrlSendMsg($cID, $LVM_GETITEMSTATE, $itmID, $LVIS_SELECTED) <> 0 If $bSelected Then $iTxtCol = 0x494949 DllCall($iDllUSER32, "int", "FillRect", "handle", $hDC, "ptr", DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), "handle", $hBrush) Else $iTxtCol = 0xB79588 EndIf
-
AutoIt Login Form without MySQL
footswitch replied to ProgrammerKid's topic in AutoIt GUI Help and Support
The difference being that mine compiles and works. -
AutoIt Login Form without MySQL
footswitch replied to ProgrammerKid's topic in AutoIt GUI Help and Support
Is this what you're after? #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Multiple GUI Managing", 215, 78, 192, 124) $Button1 = GUICtrlCreateButton("Button", 24, 8, 137, 65, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUISetState(@SW_DISABLE, $Form1) SetGUI2() GUISetState(@SW_ENABLE, $Form1) EndSwitch WEnd Func SetGUI2() $Form2 = GUICreate("Child window is still here", 377, 212, 192, 124) $Username = GUICtrlCreateInput("Username", 64, 72, 209, 21) $Password = GUICtrlCreateInput("Password", 64, 104, 209, 21) $Button2 = GUICtrlCreateButton("Button", 136, 136, 73, 33, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 GUIDelete($Form1) $ReadingUsername = GUICtrlRead($Username) $ReadingPassword = GUICtrlRead($Password) If ($ReadingUsername = "user1" And $ReadingPassword = "password1") or ($ReadingUsername = "user2" And $ReadingPassword = "password2") Then MsgBox(0,"TEST!", "Login test has been passed!") Else MsgBox(0,"TEST!", "Login test has not been passed!") EndIf EndSwitch WEnd EndFunc EDIT: $ReadingUsername = "user1" ; accepts user1, User1, uSeR1 ... case insensitive $ReadingUsername == "user1" ; only accepts exactly user1. case sensitive -
Thanks. I've decided I'll go with DB consistency. So, after some tests and an average space saving of > 40%, I chose to compress everything
- 164 replies
-
You don't think there would be a way of determining, by looking at n-bytes of the decoded string, if it is compressed or not? I can't seem to find a pattern. On another approach, in which cases did you find the compression to be of disadvantage? I'm dealing with files from around 20kB to medium 150kB, maximum 20MB. Personally I think it wouldn't hurt to always compress the data. In a database it would make sense to have that sort of consistency. Thanks
- 164 replies
-
Instead of creating a new topic I chose to post here. This way we may be able to gather the necessary code to demonstrate all the personalizations in a single ListView. Edit in Place isn't for now one of the things I need or have in mind for my current project. One awesome example: And this example that I remember seeing working in the past, but now the code is outdated; haven't looked at it in a while: As for the multiline, I found a trick: Display multiline content with fly-over tooltips: It does what it says, but it's not very helpful (visually) and it's a bit annoying. I have an idea, though. I just need a little help: #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;#include <APIConstants.au3> #include <WinAPIEx.au3> ; from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ Global Const $ODT_LISTVIEW = 102 Global Const $ODA_DRAWENTIRE = 0x1 ; #################################### ; adjustment of the icon positioning, according to windows version Global $iAdjustV = 0 If $__WINVER > 0x0600 Then $iAdjustV = 1 ; $__WINVER defined in WinAPIEx, $__WINVER > 0x0600 means Vista+ ; #################################### ; WM_MEASUREITEM allows setting the row height Global $iListView_row_height = 50 GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created ;GUIRegisterMsg($WM_MEASUREITEM, "") ; call this after last ownerdrawn listview created ; --------------------------------------------------- _GDIPlus_Startup() $hGUI = GUICreate("ListView Set Item State", 700, 300) $cButton_CheckAll = GUICtrlCreateButton("Check All", 10, 275, 100, 20) $cButton_UncheckAll = GUICtrlCreateButton("UnCheck All", 120, 275, 100, 20) $cButton_StatesToArray = GUICtrlCreateButton("States to Array", 230, 275, 100, 20) ; listview 1 ----------------------------------------------- $iListView_row_height = 25 $cListView = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL)) GUICtrlSetFont(-1, 11, 400, 0, "Calibri", 5) $hListView = GUICtrlGetHandle($cListView) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES)) $hIml_Listview = _GUIImageList_Create(16, 16, 5, 3) $hBitmap_Icon = _Load_BMP_From_Mem(_Icon_Image_Checkbox_Unchecked(), True) _GUIImageList_Add($hIml_Listview, $hBitmap_Icon) _WinAPI_DeleteObject($hBitmap_Icon) $hBitmap_Icon = _Load_BMP_From_Mem(_Icon_Image_Checkbox_Checked(), True) _GUIImageList_Add($hIml_Listview, $hBitmap_Icon) _WinAPI_DeleteObject($hBitmap_Icon) ; ########################################################## ; this "breaks" WM_MEASUREITEM ;_GUICtrlListView_SetImageList($hListView, $hIml_Listview, 1) ; why do we need this anyway? ; ########################################################## ; Add columns _GUICtrlListView_AddColumn($hListView, " ", 0) For $i = 1 To 3 _GUICtrlListView_AddColumn($hListView, "Column " & $i, 100) Next Local $aItems[30][4] For $row = 1 To 30 $aItems[$row-1][0] = "this won't show up" $aItems[$row-1][1] = "Row " & $row & ": Col 1" $aItems[$row-1][2] = "Row " & $row & ": Col 2" $aItems[$row-1][3] = "Row " & $row & ": Col 3" Next ; if you add items via _GUICtrlListView_AddArray(), the drawing will become unstable. ; also, the checkboxes don't appear unless you click their respective subitem. _GUICtrlListView_DeleteAllItems($hListView) ;_GUICtrlListView_AddArray($hListView, $aItems) __GUI_ListView_Add_Array($hListView, $aItems) ; workaround ; ----------------------------------------------------------- ; listview 2 ----------------------------------------------- $iListView_row_height = 40 $cListView_2 = GUICtrlCreateListView("", 400, 2, 298, 268, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS)) GUICtrlSetFont(-1, 11, 400, 0, "Calibri", 5) $hListView_2 = GUICtrlGetHandle($cListView_2) _GUICtrlListView_SetExtendedListViewStyle($hListView_2, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) ; Add columns For $i = 1 To 3 _GUICtrlListView_AddColumn($hListView_2, "2 - Column " & $i, 90) Next ; Add items For $row = 1 To 20 _GUICtrlListView_AddItem($hListView_2, "Row " & $row & ": Col 0", 0) _GUICtrlListView_AddSubItem($hListView_2, $row - 1, "Row " & $row & ", resize me!" & @CRLF & "-----------Col 1", 1, 0) If $row <> 3 Then _GUICtrlListView_AddSubItem($hListView_2, $row - 1, "Row " & $row & ": Col 2", 2, 0) Else ; if you comment the line below and click+drag to resize this ListView's columns, the drawing will become unstable _GUICtrlListView_AddSubItem($hListView_2, $row - 1, "", 2, 0) EndIf Next ; ----------------------------------------------------------- GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUISetState() ; Loop until user exits While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cButton_CheckAll _LV_ImgCheckboxes_CheckAll($hListView) Case $cButton_UncheckAll _LV_ImgCheckboxes_UncheckAll($hListView) Case $cButton_StatesToArray $aLVStates = _LV_ImgCheckboxes_StatesToArray($hListView) _ArrayDisplay($aLVStates) EndSwitch WEnd GUIDelete() _GUIImageList_Destroy($hIml_Listview) _GDIPlus_Shutdown() Exit Func _LV_ImgCheckboxes_CheckAll($hWnd) _GUICtrlListView_BeginUpdate($hWnd) For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1 For $y = 0 To _GUICtrlListView_GetColumnCount($hWnd) - 1 _GUICtrlListView_SetItemImage($hWnd, $i, 1, $y) Next Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>_LV_ImgCheckboxes_CheckAll Func _LV_ImgCheckboxes_UncheckAll($hWnd) _GUICtrlListView_BeginUpdate($hWnd) For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1 For $y = 0 To _GUICtrlListView_GetColumnCount($hWnd) - 1 _GUICtrlListView_SetItemImage($hWnd, $i, 0, $y) Next Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>_LV_ImgCheckboxes_UncheckAll Func _LV_ImgCheckboxes_StatesToArray($hWnd) Local $iColumns = _GUICtrlListView_GetColumnCount($hWnd) If $iColumns = 0 Then Return SetError(1) Local $iItems = _GUICtrlListView_GetItemCount($hWnd) If $iItems = 0 Then Return SetError(2) Local $aStates[$iItems][$iColumns] For $i = 0 To $iItems - 1 For $y = 0 To $iColumns - 1 $aStates[$i][$y] = _GUICtrlListView_GetItemImage($hWnd, $i, $y) Next Next Return $aStates EndFunc ;==>_LV_ImgCheckboxes_StatesToArray Func __GUI_ListView_Add_Array($hListView, ByRef $array) If Not IsArray($array) Then Return SetError(1, 0, 0) ; not an array Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView) ; if the number of columns between the array and the listview doesn't match: If UBound($array,2) <> $iColumnCount Then Return SetError(3, 1, 0) Switch UBound($array, 0) Case 1 ; 1-dimensioned array _GUICtrlListView_BeginUpdate($hListView) For $r = 0 To UBound($array, 1) - 1 _GUICtrlListView_AddItem($hListView, $array[$r], 0) Next _GUICtrlListView_EndUpdate($hListView) Case 2 ; 2-dimensioned array _GUICtrlListView_BeginUpdate($hListView) Local $first_row For $r = 0 To UBound($array, 1) - 1 If $r = 0 Then $first_row = _GUICtrlListView_AddItem($hListView, $array[$r][0], 0) Else _GUICtrlListView_AddItem($hListView, $array[$r][0], 0) EndIf Next For $r = 0 To UBound($array, 1) - 1 For $c = 1 To UBound($array, 2) - 1 _GUICtrlListView_AddSubItem($hListView, $first_row + $r, $array[$r][$c], $c, 0) Next Next _GUICtrlListView_EndUpdate($hListView) Case Else Return SetError(2, 0, 0) ; invalid array (over 2 dimensions) EndSwitch Return EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") Local $nNotifyCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $nNotifyCode Case $NM_CLICK Local $tINFO = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iItem = DllStructGetData($tINFO, "Index") Local $iSubitem = DllStructGetData($tINFO, "SubItem") If $iSubitem == 2 And StringLen(_GUICtrlListView_GetItemText($hListView, $iItem, $iSubitem)) > 0 Then ;ConsoleWrite("painting row "&$iItem+1&" col "&$iSubitem+1&@CRLF) _GUICtrlListView_SetItemImage($hListView, $iItem, Not _GUICtrlListView_GetItemImage($hListView, $iItem, $iSubitem), $iSubitem) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC $timer = TimerInit() $tagDRAWITEMSTRUCT = DllStructCreate( _ "uint cType;" & _ "uint cID;" & _ "uint itmID;" & _ "uint itmAction;" & _ "uint itmState;" & _ "hwnd hItm;" & _ "hwnd hDC;" & _ "int itmRect[4];" & _ "dword itmData" _ , $lParam) If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID") $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID") $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction") $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState") $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm") $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC") Local $aDefaultVariables[9] = [$tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC] Switch $cID ; will look for ControlID, not window handle. Case $cListView Switch $itmAction Case $ODA_DRAWENTIRE Local $aRowColors[2] = [0xFDFDFD, 0xEEDDBB] Local $aRectMargins[4] = [6, -1, -4, 0] Local $aTextFormatting[5] = [-1, _ BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS), _ BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS), _ BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_RIGHT, $DT_END_ELLIPSIS), _ BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_END_ELLIPSIS)] __WM_DRAWITEM_ListView($hListView, $aDefaultVariables, $aRowColors, $aRectMargins, $aTextFormatting) ; end case EndSwitch ; end case Case $cListView_2 Switch $itmAction Case $ODA_DRAWENTIRE Local $aRowColors[2] = [0xFDFDFD, 0x00FFFF] Local $aRectMargins[4] = [6, -1, 0, 0] Local $aTextFormatting[3] = [BitOR($DT_VCENTER, $DT_SINGLELINE), _ BitOR($DT_EDITCONTROL, $DT_WORDBREAK), _ BitOR($DT_VCENTER, $DT_SINGLELINE)] __WM_DRAWITEM_ListView($hListView_2, $aDefaultVariables, $aRowColors, $aRectMargins, $aTextFormatting) ; end case EndSwitch ; end case EndSwitch ConsoleWrite(Round(TimerDiff($timer),2) & @TAB & "WM_DRAWITEM" & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Func __WM_DRAWITEM_ListView($hListView, ByRef $aDefaultVariables, ByRef $aRowColors, ByRef $aRectMargins, ByRef $aTextFormatting) Local $iSubItemCount = _GUICtrlListView_GetColumnCount($hListView) If UBound($aTextFormatting) < $iSubItemCount Then ConsoleWrite("!> Error: invalid parameters in __WM_DRAWITEM_ListView()" & @CRLF) Return EndIf Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC $tagDRAWITEMSTRUCT = $aDefaultVariables[0] $iBrushColor = $aDefaultVariables[1] $cID = $aDefaultVariables[2] $itmID = $aDefaultVariables[3] $itmAction = $aDefaultVariables[4] $itmState = $aDefaultVariables[5] $hItm = $aDefaultVariables[6] $hDC = $aDefaultVariables[7] If _GUICtrlListView_GetItemSelected($hListView, $itmID) Then $iBrushColor = $aRowColors[1] Else $iBrushColor = $aRowColors[0] EndIf ; create a brush with the desired color: Local $aBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iBrushColor) ; get the rectangle for the whole row and fill it: Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 0, 1) ; +0 is the left margin _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush[0]) ; draw the text in each subitem For $i = 0 To $iSubItemCount - 1 ; get subitem text: Local $iSubItmText = _GUICtrlListView_GetItemText($hListView, $itmID, $i) ; get subitem coordinates for drawing its respective text: Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hListView, $itmID, $i) ; the function above accepts not only subitems (one-based index), but also main item (index=0) ; pass the coordinates to a DLL struct: Local $iSubItmRect = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + $aRectMargins[0]) ; left margin DllStructSetData($iSubItmRect, 2, $aSubItmRect[1] + $aRectMargins[1]) ; upper margin DllStructSetData($iSubItmRect, 3, $aSubItmRect[2] + $aRectMargins[2]) ; right margin DllStructSetData($iSubItmRect, 4, $aSubItmRect[3] + $aRectMargins[3]) ; bottom margin Local $tRect = DllStructGetPtr($iSubItmRect) ;#cs If $cID == $cListView And StringLen($iSubItmText) > 0 And $aTextFormatting[$i] <> - 1 Then Local $hIcon = _GUIImageList_GetIcon($hIml_Listview, _GUICtrlListView_GetItemImage($hListView, $itmID, $i)) If $i = 0 Then ; the first column of a listview needs more handling than the other columns (sub-items) #cs ; positioning for the icon: DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 12) _WinAPI_DrawIconEx($hDC, DllStructGetData($iSubItmRect, "Left") - 16, Int((DllStructGetData($iSubItmRect, "Bottom") + DllStructGetData($iSubItmRect, "Top") - 16)/2) + $iAdjustV, $hIcon, 16, 16) ; positioning for the text: DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 4) #ce ElseIf $i == 2 Then _WinAPI_DrawIconEx($hDC, DllStructGetData($iSubItmRect, "Left"), Int((DllStructGetData($iSubItmRect, "Bottom") + DllStructGetData($iSubItmRect, "Top") - 16) / 2) - 1 + $iAdjustV, $hIcon, 16, 16) ; positioning for the text: DllStructSetData($iSubItmRect, "Left", DllStructGetData($iSubItmRect, "Left") + 20) EndIf _GUIImageList_DestroyIcon($hIcon) EndIf ;#ce If $aTextFormatting[$i] = -1 Then ; do nothing (don't draw any text) Else _WinAPI_DrawText($hDC, $iSubItmText, $tRect, $aTextFormatting[$i]) EndIf Next EndFunc ;==>__WM_DRAWITEM_ListView Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam) Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam) If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG DllStructSetData($tMEASUREITEMS, "itmH", $iListView_row_height) ; row height Return 1 EndFunc ;==>WM_MEASUREITEM ; Based on File to Base64 String Code Generator ; by UEZ ; http://www.autoitscript.com/forum/topic/...ng-code-generator-v103-build-2 ;====================================================================================== ; Function Name: Load_BMP_From_Mem ; Description: Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap ; ; Parameters: $bImage: the binary string which contains any valid image which is supported by GDI+ ; Optional: $hHBITMAP: if false a bitmap will be created, if true a hbitmap will be created ; ; Remark: hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format ; Don't forget _GDIPlus_Startup() and _GDIPlus_Shutdown() ; ; Requirement(s): GDIPlus.au3, Memory.au3 and _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3 ; Return Value(s): Success: handle to bitmap (GDI+ bitmap format) or hbitmap (WinAPI bitmap format), ; Error: 0 ; Error codes: 1: $bImage is not a binary string ; 2: unable to create stream on HGlobal ; 3: unable to create bitmap from stream ; ; Author(s): UEZ ; Additional Code: thanks to progandy for the MemGlobalAlloc and tVARIANT lines and ; Yashied for _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3 ; Version: v0.97 Build 2012-01-04 Beta ;======================================================================================= Func _Load_BMP_From_Mem($bImage, $hHBITMAP = False) If Not IsBinary($bImage) Then Return SetError(1, 0, 0) Local $aResult Local Const $memBitmap = Binary($bImage) ;load image saved in variable (memory) and convert it to binary Local Const $len = BinaryLen($memBitmap) ;get length of image Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents If @error Then SetError(2, 0, 0) Local Const $hStream = $aResult[3] $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface If @error Then SetError(3, 0, 0) Local Const $hBitmap = $aResult[2] Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 $tVARIANT = 0 If $hHBITMAP Then Local Const $hHBmp = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>_Load_BMP_From_Mem Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap) Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0 $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0) If (@error) Or ($Ret[0]) Then Return 0 $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB) $pBits = DllStructGetData($tData, 'Scan0') If Not $pBits Then Return 0 $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword') DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR)) DllStructSetData($tBIHDR, 2, $Ret[2]) DllStructSetData($tBIHDR, 3, $Ret[3]) DllStructSetData($tBIHDR, 4, 1) DllStructSetData($tBIHDR, 5, 32) DllStructSetData($tBIHDR, 6, 0) $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0) If (Not @error) And ($hResult[0]) Then DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0')) $hResult = $hResult[0] Else $hResult = 0 EndIf _GDIPlus_BitmapUnlockBits($hBitmap, $tData) Return $hResult EndFunc ;==>_GDIPlus_BitmapCreateDIBFromBitmap Func _Decompress_Binary_String_to_Bitmap($Base64String) $Base64String = Binary($Base64String) Local $iSize_Source = BinaryLen($Base64String) Local $pBuffer_Source = _WinAPI_CreateBuffer($iSize_Source) DllStructSetData(DllStructCreate('byte[' & $iSize_Source & ']', $pBuffer_Source), 1, $Base64String) Local $pBuffer_Decompress = _WinAPI_CreateBuffer(8388608) Local $Size_Decompressed = _WinAPI_DecompressBuffer($pBuffer_Decompress, 8388608, $pBuffer_Source, $iSize_Source) Local $b_Result = Binary(DllStructGetData(DllStructCreate('byte[' & $Size_Decompressed & ']', $pBuffer_Decompress), 1)) _WinAPI_FreeMemory($pBuffer_Source) _WinAPI_FreeMemory($pBuffer_Decompress) Return $b_Result EndFunc ;==>_Decompress_Binary_String_to_Bitmap Func _Icon_Image_Checkbox_Unchecked() Local $Base64String $Base64String &= '7rBIAAABABAQEAFwCAAAaAUAABYAAMwAKAAYAJAAIAAYAVwZAQBAAQIYDgCAgAAAANfc3ADZ3t4AANvg4ADe4uIAAOLl5QDl6OgAAOns7ADs7+8AAO/x8QDx8/MAAPT19QD29/cAAPj5+QD6+/sAAPz9/QD+/v7wAP///xNc/wB/AD8A/z8APwA/AD8APwA/AD8ACAAb4HYLAAEJAOEBCgsMAA0ODxAREhISbeIBCQcC4gEIBwLiAQfbBwLiAQYHAuIBBQcC4gG2BAcC4gEDBwLiAQIHAv/jAQcC5AEGAuIB7BceAOCfHgN/AG0A4QZhAA==' Return _Decompress_Binary_String_to_Bitmap(_Base64Decode($Base64String)) EndFunc ;==>_Icon_Image_Checkbox_Unchecked Func _Icon_Image_Checkbox_Checked() Local $Base64String $Base64String &= 'z7BIAAABABAQEAFwCAAAaAUAABYAAMwAKAAYAJAAIAAYAVwZAQBAAQIYDgCAgAAAAISEhADe3t5AAN7n5wDnAQbvCO8A7wEG9/cA9/EABv///xN4/wE/AD8A/z8APwA/AD8AHwAMAOB6CwAGAQkA4QEHCAkJCR4KAgDjAQcC5AEHCAKDAwLiAQYHBwICAwI54gEFBsABAwLjAQUCxgIkBOIBBAUCRQbjAVgEBQUCAuQBAwUCCPPkAQUCBwjkAQYC4gHsF3seAOCfA38AbQDhBmEA' Return _Decompress_Binary_String_to_Bitmap(_Base64Decode($Base64String)) EndFunc ;==>_Icon_Image_Checkbox_Checked Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode For me this is awesome already. But how would I draw different font sizes, or even different fonts, within the same subitem? In essential trying to resemble the Outlook lists (From, Subject, Body, all into one "cell"). And then there's the vertical alignment. $DT_VCENTER only seems to work with single line.
-
water, If Outlook isn't previously opened by the user, getting a Selection isn't a very good idea $oOL.ActiveExplorer.Selection.Count won't return a number in such case, and who knows in what other situations as well. So I suggest the following improvement, or something similar to improve the consistency of the element $Array[0][0]: Func _OL_FolderSelectionGet($oOL) Local $oOL_Selection = $oOL.ActiveExplorer.Selection Local $count = Int($oOL_Selection.Count) ; <== If 0 > $count Then $count = 0 ; <== and use $count from here on Local $aOL_Selection[$count + 1][3] = [[$count, 2]] For $iOL_Index = 1 To $count $aOL_Selection[$iOL_Index][0] = $oOL_Selection.Item($iOL_Index) $aOL_Selection[$iOL_Index][1] = $oOL_Selection.Item($iOL_Index).EntryId $aOL_Selection[$iOL_Index][2] = $oOL_Selection.Item($iOL_Index).Class Next Return $aOL_Selection EndFunc ;==>_OL_FolderSelectionGet
-
UEZ, just to let you know that I'm stealing your code as a means of inspiration for attaching files into database records So thanks!
- 164 replies
-
I believe I'm on the right track now. Many thanks. I don't want to keep nagging you without having a second look at things And of course fiddle with what I have so far.
-
Ok, I feel stupid it looks like it's all there and I just keep missing it
-
AWESOME. It works My setup, as mentioned before, is: Exchange 2003 Outlook 2003 SP3 Cached Exchange Mode Thank you so much.
-
Example: get the selected item and save it in the specified folder. EDIT: NOTE: The third parameter of _OL_ItemSave(), which is the StoreID, when set to Default works for the selected item, even if it's not in your own store. ; code adapted from: http://support.microsoft.com/kb/240935 #include <OutlookEX.au3> Global $oOutlook = _OL_Open() Global $oExp = $oOutlook.ActiveExplorer Global $oSel = $oExp.Selection For $i = 1 To $oSel.Count ; Loop through all the currently .selected items Global $oItem = $oSel.Item($i) ; Get a selected item. __DisplayInfo($oItem) ; Display information about it. Next _OL_ItemSave($oOutlook, $oItem.EntryID, Default, "C:temptest.msg", $olMSG, 3) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemSave Example Script", "Error saving mail item to C:tempOutlook-UDF-TestDir2. @error = " & @error & ", @extended = " & @extended) MsgBox(64, "OutlookEX UDF: _OL_ItemSave Example Script", "Example 2: Item successfully saved!") Func __DisplayInfo(ByRef $oItem) Switch $oItem.Class Case $olMail ConsoleWrite("+> it's a mail item!"&@CRLF) EndSwitch Switch $oItem.MessageClass Case "IPM.Appointment" MsgBox(0,"Appointment",$oItem.Subject) Case "IPM.Contact" MsgBox(0,"Contact",$oItem.FullName) Case "IPM.Note" MsgBox(0,"Note",$oItem.Subject) Case "IPM.Activity" MsgBox(0,"Activity",$oItem.Subject) Case "IPM.StickyNote" MsgBox(0,"Sticky Note",$oItem.Subject) Case "IPM.Task" MsgBox(0,"Task Item",$oItem.DueDate) EndSwitch EndFunc
-
Same return @error = 1, @extended = 0. Your help file mentions this. EDIT: I did bypass the version check in _OL_AccountGet(), and indeed it does not work. LOL talk about trusting the fellow user, eh?
-
Sweet I'm realizing this is going to be a longer journey than I had anticipated. So no actual hurry.
-
Only supported for Outlook 2007 and later Seems like some of my problems are related to the stone age Outlook. I'm having a look at what my options are, in matters of letting the user select the intended item, and then use that directly.
-
Ok, for example: search for yesterday's mail flow (default mail folder and subfolders) #include <OutlookEX.au3> Global $oOutlook = _OL_Open(True) Global $aFolder = _OL_FolderAccess($oOutlook, "*", $olFolderInbox) Global $aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, '@SQL="urn:schemas:httpmail:datereceived" > ''' & _DateAdd("D", -1, _NowCalcDate()) & ''' AND "urn:schemas:httpmail:datereceived" < ''' & _NowCalcDate() & '''', "", "", "EntryID, SenderName, SenderEmailAddress, ReceivedTime, To, Subject, Body", "", 1) If IsArray($aItems) Then _ArrayDisplay($aItems, "Yesterday's mail") Else MsgBox(48, "Error", "Could not find yesterday's mail. @error = " & @error & ", @extended: " & @extended) EndIf EDIT: Please note that usually dates in SQL are "YYYY-MM-DD" but Outlook seems to accept "YYYY/MM/DD", which is the direct output of _NowCalcDate(). How to do this for just one folder? (non-recursive) If I remove the last two parameters from _OL_ItemFind(), the result is a single-row array.
-
water, Thank you for taking the time to enlighten me. Regarding 1. and 2., I think I wasn't clear enough. What I mean is: I have a user which has access to more than one user's folders. But I don't know which user's folders he has added to his Outlook application. What I wanted was to somehow "mimic" the Outlook aspect so the user would intuitively navigate through the folder tree to select the desired item. Anyway, I tried to discover what _OL_FolderTree() could do to help: Global $oOutlook = _OL_Open() Global $aFolder = _OL_FolderAccess($oOutlook, "*", $olFolderInbox) ; ok, no error Global $aFolderDisplay = _OL_FolderTree($oOutlook, $aFolder[1]) ; error 1, extended 0 So yeah, I don't get it. Sorry :/ Thank you for this. I would post some code, but it's like I'm saying, I can't do anything with the UDF yet... I forgot to mention that most of the examples don't work because the creation of the test environment either fails or isn't completing properly.