Jump to content

rover

Active Members
  • Posts

    792
  • Joined

  • Last visited

  • Days Won

    3

rover last won the day on June 24 2012

rover had the most liked content!

Profile Information

  • Member Title
    unmutual
  • Location
    the unfashionable end of the western spiral arm of the Milky Way Galaxy

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

rover's Achievements

Universalist

Universalist (7/7)

56

Reputation

  1. My comments are not directed at you JScript.My first post gives additional reasons of support for your method. Your UDF fixes two problems with the EM_SETCUEBANNER method for users with requirement for Asian languages support that is missing in XP, as well as the broken cue banner when the control has focus option.
  2. Edit: My apologies JScript and James for my incorrect assumption and off-topic remark to the post above.
  3. Hi AZJIO Two reasons for using JScripts alternative to native EM_SETCUEBANNER in XP 1/ I forgot to mention XP has an issue with Asian Language support that was not fixed until Vista. Microsoft could not be bothered to fix it in any of the XP service packs of course... Sorting it all Out : EM_SETCUEBANNER vs. international support in XP and Server 2003 https://blogs.msdn.com/michkap/archive/2006/02/25/538735.aspx 2/ Display cuebanner when edit has focus feature does not work in XP. EM_SETCUEBANNER Message, wParam TRUE - not working for XP. - MSDN Forums http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2799112&SiteID=1
  4. A novel approach JScript Also gets around the XP compatibility issues of EM_SETCUEBANNER @AZJIO Minimum OS for EM_SETCUEBANNER is XP Regarding any other posts of EM_SETCUEBANNER, a simple forum check for pre-existing examples would have sufficed, but that is done so infrequently here...
  5. To turn control theming back on DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hWnd, "ptr", 0, "ptr", 0)
  6. Thanks UEZ Nice pure math trackbar in GDI+! Any idea on code to use alpha transparent images for the trackbar thumb? Rounded thumb png's?
  7. _GUICtrlListView_SetItemChecked is faster than _GUICtrlTreeView_SetChecked, even after both are optimized.
  8. Your slowdown would be from the large number of thumbnails. If you are not already doing so, use the BeginUpdate/EndUpdate functions before and after calling SetItemChecked and use the extended style LVS_EX_DOUBLEBUFFER. (just a paint buffer that helps with flickering, especially with customdrawn listviews and graphics painting, wont help with your issue) Maybe move to a virtual (ownerdata) listview - only draws the number of items that fit in the listview client area. Uses the WM_NOTIFY LVN_GETDISPINFOW notification to update the items shown as the listview is scrolled. That way you only load thumbnails on demand, and only as many as are visible or use a cache of images in an array so each full page scroll is not having to load all the images for a page at once. I think there are examples of this on the forum. I coded an example loading thumbnails to an array, just to try it, but the memory use was high. This optimized version of _GUICtrlListView_SetItemChecked halves the time to check all items. Modified for listview control ID only The example is slower creating the items with the unmodified udf _GUICtrlListView_AddItem/AddSubItem functions than it is with the native GUICtrlCreateListViewItem Edit: added Begin/EndUpdate functions #include <GUIConstantsEx.au3> #include <GuiListView.au3> _Main() Func _Main() Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES), $cListView GUICreate("ListView Set Item Checked State", 400, 300) $cListView = GUICtrlCreateListView("", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($cListView, $exStyles) GUISetState() _GUICtrlListView_BeginUpdate($cListView) _GUICtrlListView_AddColumn($cListView, "Column 1", 100) _GUICtrlListView_AddColumn($cListView, "Column 2", 100) _GUICtrlListView_AddColumn($cListView, "Column 3", 100) Local $iIdx ConsoleWrite("+ Creating 5000 items " & @LF) ; Add items For $i = 0 To 5000 $iIdx = _GUICtrlListView_AddItem($cListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($cListView, $iIdx, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($cListView, $iIdx, "Row 1: Col 3", 2) Next _GUICtrlListView_EndUpdate($cListView) _GUICtrlListView_BeginUpdate($cListView) ConsoleWrite("+ Check all items " & @LF) Local $iT = TimerInit() __GUICtrlListView_SetItemChecked($cListView, -1, True) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($iT) = ' & TimerDiff($iT) & @crlf) _GUICtrlListView_EndUpdate($cListView) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main ;modified for GUICtrlCreateListView() control ID only Func __GUICtrlListView_SetItemChecked($cLV, $iIndex, $fCheck = True) Local $pItem, $tItem, $iState = 0x1000 $tItem = DllStructCreate($tagLVITEM) $pItem = DllStructGetPtr($tItem) DllStructSetData($tItem, "Mask", $LVIF_STATE) DllStructSetData($tItem, "StateMask", $LVIS_STATEIMAGEMASK) If @error Then Return SetError($LV_ERR, $LV_ERR, $LV_ERR) If ($fCheck) Then $iState = 0x2000 Local $hLV = GUICtrlGetHandle($cLV) If $iIndex <> -1 Then ;check single item DllStructSetData($tItem, "Item", $iIndex) DllStructSetData($tItem, "State", $iState) Return GUICtrlSendMsg($cLV, $LVM_SETITEMW, 0, $pItem) <> 0 Else ;check all For $x = 0 To _GUICtrlListView_GetItemCount($cLV) - 1 DllStructSetData($tItem, "Item", $x) DllStructSetData($tItem, "State", $iState) ;_SendMessage($cLV, $LVM_SETITEMW, 0, $tItem, 0, "wparam", "struct*") If Not GUICtrlSendMsg($cLV, $LVM_SETITEMW, 0, $pItem) <> 0 Then Return SetError($LV_ERR, $LV_ERR, $LV_ERR) EndIf Next Return True EndIf Return False EndFunc ;==>__GUICtrlListView_SetItemChecked
  9. Trackbars (Slider) can be custom skinned by Customdrawing or Ownerdrawing. I've used a skinning dll in the past to theme a slider in a script, otherwise I haven't the need to bother working out the details of customdrawing a slider. Yashied posted an example of painting the background image behind a slider that used customdrawing. At the time, I did a few tests theming the slider, then left it. Here is the updated code modified from Yashied's post with hard coded metrics, no image alpha transparency support and without image state code (hot/focused/disabled). Version with background image has high cpu usage when trackbar moved (NM_CUSTOMDRAW message) and some optimization is needed. Alternately use a layered gui for transparency. Or use UEZ's custom trackbar posted in your other thread just as I was logging in to post this. Solid colour Background ;coded by rover 2k12 - modified from customdrawn slider background code by Yashied #include <Constants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Global Const $tagNMCUSTOMDRAW = $tagNMHDR & ';dword DrawStage;handle hDC;long Rect[4];dword_ptr ItemSpec;uint ItemState;lparam ItemlParam' Global Const $STM_GETIMAGE = 0x0173 Global $iBuffer, $hBitmap1, $hBitmap2, $bmWidth1, $bmHeight1, $bmWidth2, $bmHeight2, $cSldr1, $cSldr2, $hSlider1, $hSlider2 _Main() Func _Main() Local $iLoad = BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION, $LR_LOADTRANSPARENT), $Msg $hBitmap1 = _WinAPI_LoadImage(0, @ScriptDir & '\B.bmp', $IMAGE_BITMAP, 0, 0, $iLoad); LoadImage API only works with BMP files or BMP resources $hBitmap2 = _WinAPI_LoadImage(0, @ScriptDir & '\A.bmp', $IMAGE_BITMAP, 0, 0, $iLoad) _GetBitmapSize($hBitmap1, $bmWidth1, $bmHeight1) _GetBitmapSize($hBitmap2, $bmWidth2, $bmHeight2) GUICreate('Custom Skin Slider', 300, 150) GUISetBkColor(0x494949) $cSldr1 = GUICtrlCreateDummy() $cSldr2 = GUICtrlCreateDummy() Local $cEdit1 = GUICtrlCreateInput("0", 10, 26, 42, 24, BitOR($ES_CENTER, $ES_READONLY)) ;does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control) GUICtrlSetFont(-1, 12, 800, 1, "Arial") GUICtrlSetColor(-1, 0x00EEEE) GUICtrlSetBkColor(-1, 0x494949) Local $cEdit2 = GUICtrlCreateInput("0", 10, $bmHeight1 + 42, 42, 24, BitOR($ES_CENTER, $ES_READONLY));does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control) GUICtrlSetFont(-1, 12, 800, 1, "Arial") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetBkColor(-1, 0x363636) GUICtrlCreateSlider(60, 20, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP)) $hSlider1 = GUICtrlGetHandle(-1) GUICtrlSetCursor(-1, 0) _SendMessage($hSlider1, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar GUICtrlSetBkColor(-1, 0x494949) GUICtrlCreateSlider(60, $bmHeight1 + 36, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP)) $hSlider2 = GUICtrlGetHandle(-1) GUICtrlSetCursor(-1, 0) _SendMessage($hSlider2, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar GUICtrlSetBkColor(-1, 0x494949) GUIRegisterMsg($WM_HSCROLL, "_WM_HVSCROLL") ;GUIRegisterMsg($WM_VSCROLL, "_WM_HVSCROLL") GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hBitmap1) _WinAPI_DeleteObject($hBitmap2) Exit Case $cSldr1 GUICtrlSetData($cEdit1, GUICtrlRead($cSldr1)) Case $cSldr2 GUICtrlSetData($cEdit2, GUICtrlRead($cSldr2)) EndSwitch WEnd EndFunc Func _WM_HVSCROLL($hWnd, $Msg, $wParam, $lParam) Switch $lParam Case $hSlider1, $hSlider2 Local $iCtrlID = _WinAPI_GetDlgCtrlID($lParam) Local $iPos = GUICtrlRead($iCtrlID) If $iBuffer <> $iPos Then ; buffer read slider value to prevent unnecessary updating at start/end of slider range. $iBuffer = $iPos ;ConsoleWrite(' Slider = ' & $iPos & @CRLF) Switch $lParam Case $hSlider1 GUICtrlSendToDummy($cSldr1, $iPos) Case $hSlider2 GUICtrlSendToDummy($cSldr2, $iPos) EndSwitch EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_HVSCROLL Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom') Local $Code = DllStructGetData($tNMHDR, 'Code') Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Switch $hWndFrom Case $hSlider1, $hSlider2 Switch $Code Case $NM_CUSTOMDRAW Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam) Local $DrawStage = DllStructGetData($tNMCD, 'DrawStage') Local $ItemSpec = DllStructGetData($tNMCD, 'ItemSpec') Local $hDC, $hMemDC, $hPrev Switch $DrawStage Case $CDDS_PREPAINT DllStructSetData($tNMCD, 'ItemState', BitXOR(DllStructGetData($tNMCD, 'ItemState'), $CDIS_FOCUS)) ; Remove focus Rectangle Return $CDRF_NOTIFYITEMDRAW Case $CDDS_ITEMPREPAINT Local $nLeft = DllStructGetData($tNMCD, 'Rect', 1) Local $nTop = DllStructGetData($tNMCD, 'Rect', 2) Local $nRight = DllStructGetData($tNMCD, 'Rect', 3) Local $nBottom = DllStructGetData($tNMCD, 'Rect', 4) Local $nWidth = $nRight - $nLeft Local $nHeight = $nBottom - $nTop $hDC = DllStructGetData($tNMCD, 'hDC') Switch $ItemSpec Case $TBCD_TICS Return $CDRF_SKIPDEFAULT ; draw custom ticks from bitmap or remove tics ;Return $CDRF_DODEFAULT ; draw tics from current theme Case $TBCD_CHANNEL $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap2) _WinAPI_BitBlt($hDC, $nLeft, $nTop - 16, $nWidth, $bmHeight2, $hMemDC, 0, 0, $MERGECOPY) _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) Return $CDRF_SKIPDEFAULT ;custom draw channel with bitmap or remove channel ;Return $CDRF_DODEFAULT ;draw channel from current theme Case $TBCD_THUMB If ($nWidth - $bmWidth1) > 0 Then $nLeft += (($nWidth - $bmWidth1) / 2) $nWidth = $bmWidth1 EndIf If ($nHeight - $bmHeight1) > 0 Then $nTop += ($nHeight - $bmHeight1) / 2 $nHeight = $bmHeight1 EndIf $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap1) _WinAPI_BitBlt($hDC, $nLeft, $nTop - 10, $nWidth, $nHeight, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) Return $CDRF_SKIPDEFAULT ;custom draw thumb with bitmap ;Return $CDRF_DODEFAULT ;draw thumb from current theme EndSwitch EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GetBitmapSize($hBitmap, ByRef $X, ByRef $Y) Local $iRet = _WinAPI_GetObject($hBitmap, 0, 0) Local $tBitmap = DllStructCreate("int bmType;int bmWidth;int bmHeight;" & _ "int bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;long_ptr bmBits") If DllStructGetSize($tBitmap) <> $iRet Then Return SetError(1, 0, -1) $iRet = _WinAPI_GetObject($hBitmap, $iRet, DllStructGetPtr($tBitmap)) $X = DllStructGetData($tBitmap, "bmWidth") $Y = DllStructGetData($tBitmap, "bmHeight") EndFunc ;==>_GetBitmapSize Image Background (High cpu when trackbar moved) ;coded by rover 2k12 - modified from customdrawn slider background code by Yashied #include <Constants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Global Const $tagNMCUSTOMDRAW = $tagNMHDR & ';dword DrawStage;handle hDC;long Rect[4];dword_ptr ItemSpec;uint ItemState;lparam ItemlParam' Global Const $STM_GETIMAGE = 0x0173 Global $hTemp = 0, $hPic, $iBuffer, $hBitmap1, $hBitmap2, $bmWidth1, $bmHeight1, $bmWidth2, $bmHeight2, $cSldr1, $cSldr2, $hSlider1, $hSlider2 _Main() Func _Main() Local $iLoad = BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION, $LR_LOADTRANSPARENT), $Msg $hBitmap1 = _WinAPI_LoadImage(0, @ScriptDir & '\B.bmp', $IMAGE_BITMAP, 0, 0, $iLoad); LoadImage API only works with BMP files or BMP resources $hBitmap2 = _WinAPI_LoadImage(0, @ScriptDir & '\A.bmp', $IMAGE_BITMAP, 0, 0, $iLoad) _GetBitmapSize($hBitmap1, $bmWidth1, $bmHeight1) _GetBitmapSize($hBitmap2, $bmWidth2, $bmHeight2) GUICreate('Custom Skin Slider', 300, 150) GUISetBkColor(0x494949) Local $Wow64 = "", $Msg If @AutoItX64 Then $Wow64 = "\Wow6432Node" Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg" GUICtrlCreatePic($sPath, 0, 0, 413, 161) GUICtrlSetState(-1, $GUI_DISABLE) $hPic = GUICtrlGetHandle(-1) $cSldr1 = GUICtrlCreateDummy() $cSldr2 = GUICtrlCreateDummy() Local $cEdit1 = GUICtrlCreateInput("0", 10, 26, 42, 24, BitOR($ES_CENTER, $ES_READONLY)) ;does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control) GUICtrlSetFont(-1, 12, 800, 1, "Arial") GUICtrlSetColor(-1, 0x00EEEE) GUICtrlSetBkColor(-1, 0x494949) Local $cEdit2 = GUICtrlCreateInput("0", 10, $bmHeight1 + 42, 42, 24, BitOR($ES_CENTER, $ES_READONLY));does not have the flicker of a rapidly updated GUICtrlCreateLabel() (Static control) GUICtrlSetFont(-1, 12, 800, 1, "Arial") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetBkColor(-1, 0x363636) GUICtrlCreateSlider(60, 20, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP)) $hSlider1 = GUICtrlGetHandle(-1) GUICtrlSetCursor(-1, 0) _SendMessage($hSlider1, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar GUICtrlSetBkColor(-1, 0x494949) GUICtrlCreateSlider(60, $bmHeight1 + 36, $bmWidth2 + $bmHeight1, $bmHeight1 + 6, BitOR($TBS_NOTICKS, $TBS_FIXEDLENGTH, $WS_TABSTOP)) $hSlider2 = GUICtrlGetHandle(-1) GUICtrlSetCursor(-1, 0) _SendMessage($hSlider2, $TBM_SETTHUMBLENGTH, ($bmWidth1 * 2) - 1, 0) ;-1 pixel to compensate for thumb not covering channel at right end of trackbar GUICtrlSetBkColor(-1, 0x494949) GUIRegisterMsg($WM_HSCROLL, "_WM_HVSCROLL") ;GUIRegisterMsg($WM_VSCROLL, "_WM_HVSCROLL") GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hBitmap1) _WinAPI_DeleteObject($hBitmap2) Exit Case $cSldr1 GUICtrlSetData($cEdit1, GUICtrlRead($cSldr1)) Case $cSldr2 GUICtrlSetData($cEdit2, GUICtrlRead($cSldr2)) EndSwitch WEnd EndFunc Func _WM_HVSCROLL($hWnd, $Msg, $wParam, $lParam) Switch $lParam Case $hSlider1, $hSlider2 Local $iCtrlID = _WinAPI_GetDlgCtrlID($lParam) Local $iPos = GUICtrlRead($iCtrlID) If $iBuffer <> $iPos Then ; buffer read slider value to prevent unnecessary updating at start/end of slider range. $iBuffer = $iPos ;ConsoleWrite(' Slider = ' & $iPos & @CRLF) Switch $lParam Case $hSlider1 GUICtrlSendToDummy($cSldr1, $iPos) Case $hSlider2 GUICtrlSendToDummy($cSldr2, $iPos) EndSwitch EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_HVSCROLL Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom') Local $Code = DllStructGetData($tNMHDR, 'Code') Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Switch $hWndFrom Case $hSlider1, $hSlider2 Switch $Code Case $NM_CUSTOMDRAW Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam) Local $DrawStage = DllStructGetData($tNMCD, 'DrawStage') Local $ItemSpec = DllStructGetData($tNMCD, 'ItemSpec') Local $hDC = DllStructGetData($tNMCD, 'hDC') Local $hMemDC, $hBitmap, $hPrev, $aPos Switch $DrawStage Case $CDDS_PREPAINT, $CDDS_POSTPAINT $aPos = ControlGetPos($hWndFrom, '', '') Switch $DrawStage Case $CDDS_PREPAINT $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _SendMessage($hPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0) $hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap) _WinAPI_BitBlt($hDC, 0, 0, $aPos[2], $aPos[3], $hMemDC, $aPos[0], $aPos[1], $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) DllStructSetData($tNMCD, 'ItemState', BitXOR(DllStructGetData($tNMCD, 'ItemState'), $CDIS_FOCUS)) ; Remove focus Rectangle Return BitOR($CDRF_NOTIFYITEMDRAW, $CDRF_NOTIFYPOSTPAINT) Case $CDDS_POSTPAINT $hMemDC = _WinAPI_CreateCompatibleDC($hDC) If Not $hTemp Then $hTemp = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3]) $hPrev = _WinAPI_SelectObject($hMemDC, $hTemp) _WinAPI_BitBlt($hMemDC, 0, 0, $aPos[2], $aPos[3], $hDC, 0, 0, $MERGECOPY) Else $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hPrev = _WinAPI_SelectObject($hMemDC, $hTemp) _WinAPI_BitBlt($hDC, 0, 0, $aPos[2], $aPos[3], $hMemDC, 0, 0, $SRCCOPY) EndIf _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) Return $CDRF_DODEFAULT EndSwitch Case $CDDS_ITEMPREPAINT If $hTemp Then _WinAPI_DeleteObject($hTemp) $hTemp = 0 EndIf Local $nLeft = DllStructGetData($tNMCD, 'Rect', 1) Local $nTop = DllStructGetData($tNMCD, 'Rect', 2) Local $nRight = DllStructGetData($tNMCD, 'Rect', 3) Local $nBottom = DllStructGetData($tNMCD, 'Rect', 4) Local $nWidth = $nRight - $nLeft Local $nHeight = $nBottom - $nTop Switch $ItemSpec Case $TBCD_TICS Return $CDRF_SKIPDEFAULT ; draw custom ticks from bitmap or remove tics ;Return $CDRF_DODEFAULT ; draw tics from current theme Case $TBCD_CHANNEL $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap2) _WinAPI_BitBlt($hDC, $nLeft, $nTop - 16, $nWidth, $bmHeight2, $hMemDC, 0, 0, $MERGECOPY) _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) Return $CDRF_SKIPDEFAULT ;custom draw channel with bitmap or remove channel ;Return $CDRF_DODEFAULT ;draw channel from current theme Case $TBCD_THUMB If ($nWidth - $bmWidth1) > 0 Then $nLeft += (($nWidth - $bmWidth1) / 2) $nWidth = $bmWidth1 EndIf If ($nHeight - $bmHeight1) > 0 Then $nTop += ($nHeight - $bmHeight1) / 2 $nHeight = $bmHeight1 EndIf $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap1) _WinAPI_BitBlt($hDC, $nLeft, $nTop - 10, $nWidth, $nHeight, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hPrev) _WinAPI_DeleteDC($hMemDC) Return $CDRF_SKIPDEFAULT ;custom draw thumb with bitmap ;Return $CDRF_DODEFAULT ;draw thumb from current theme EndSwitch EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GetBitmapSize($hBitmap, ByRef $X, ByRef $Y) Local $iRet = _WinAPI_GetObject($hBitmap, 0, 0) Local $tBitmap = DllStructCreate("int bmType;int bmWidth;int bmHeight;" & _ "int bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;long_ptr bmBits") If DllStructGetSize($tBitmap) <> $iRet Then Return SetError(1, 0, -1) $iRet = _WinAPI_GetObject($hBitmap, $iRet, DllStructGetPtr($tBitmap)) $X = DllStructGetData($tBitmap, "bmWidth") $Y = DllStructGetData($tBitmap, "bmHeight") EndFunc ;==>_GetBitmapSize
  10. @2Reg2Post The OP is only running selected programs (exe) from the treeview, and most likely not in the thousands. Using a listview was suggested by me in a previous thread by the OP. Yes, a listview check all with _GUICtrlListView_SetItemChecked $iIndex = -1 (internal ForNext loop) is faster than a treeview, and 2x faster if _GUICtrlListView_SetItemChecked is optimized. Unfortunately there is no listview/treeview single message to select all checkboxes without having to loop through all items. A few thousand treeview items do not take several minutes to check. Checking 5000 items with _GUICtrlTreeView_SetChecked $iIndex = -1 takes approx 5 seconds, and that can be halved with optimization. Both the treeview and listview functions can be optimized by using only the listview control ID* and removing the unicode, external process and handle/control ID checks. *_SendMessage() with a handle is 4 times slower than GuiSendMsg() with a control ID. ;optimized check all Func _TVCheckAll($hWnd, $fCheck = True) ;coded by rover 2k12 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, False) Local $hItem = _GUICtrlTreeView_GetFirstItem($hWnd), $iChk = 0 _GUICtrlTreeView_BeginUpdate($hWnd) ;~ Do ;~ If _GUICtrlTreeView_SetChecked($hWnd, $hItem, $fCheck) Then $iChk += 1 ;~ $hItem = _GUICtrlTreeView_GetNextSibling($hWnd, $hItem) ;~ Until $hItem = 0 Local $tItem = DllStructCreate($tagTVITEMEX) DllStructSetData($tItem, "Mask", $TVIF_STATE) DllStructSetData($tItem, "StateMask", 0xf000) If ($fCheck) Then DllStructSetData($tItem, "State", 0x2000) Else DllStructSetData($tItem, "State", 0x1000) EndIf Do DllStructSetData($tItem, "hItem", $hItem) If _SendMessage($hWnd, $TVM_SETITEMW, 0, $tItem, 0, "wparam", "struct*") Then $iChk += 1 $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "handle", "handle") Until $hItem = 0 _GUICtrlTreeView_EndUpdate($hWnd) Return SetError(0, $iChk, True) EndFunc ;==>_TVCheckAll
  11. You have to remove the $WS_TABSTOP style #include <GUIConstantsEx.au3> GUICreate("My GUI Button") $Button_1 = GUICtrlCreateButton("Botton 1", 10, 30, 100) $Button_2 = GUICtrlCreateButton("Botton 2", 10, 60, 100) $Button_3 = GUICtrlCreateButton("Botton 3", 10, 90, 100) $Button_4 = GUICtrlCreateButton("Botton 4", 10, 120, 100) GUISetState() GUICtrlSetStyle($Button_2, 0) ;$GUI_SS_DEFAULT_BUTTON = 0 GUICtrlSetStyle($Button_3, 0) ;$GUI_SS_DEFAULT_BUTTON = 0 While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEnd
  12. You still have the memory leak from undeleted child item control ids if you use TVM_DELETEITEM. Might I suggest purging the message queue after all delete item events. In my DeleteAll function there were no misfires (only tested on my XP box - 7x64 box being rebuilt) Setting events for items of a Treeview as if they are controls obviously has issues with false events when items are unregistered/deleted. Treeview/Listview Item notifications should be processed in a WM_NOTIFY message handler... Consider the added complication of having to code delete functions to loop through and unregister (item set to run an event mode function) and delete every root and child item. and then clear the message queue, as opposed to using the existing udf single line delete all or delete all children functions with WM_NOTIFY for event handling. What problems are you having using the udf functions? I forgot that _GUICtrlTreeView_GetItemParam returns False instead of 0 when there is no item data (the combobox and listview param functions return 0 for no data). Try this message queue purge example, no memory leaks and no event misfires. Edit: clarification. #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> $Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Opt("GUIOnEventMode", 1) Global $hTreeView, $cTreeview Global $message = "You clicked a parent" _Main() Func _Main() Local $hItem Local $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) GUICreate("TreeView Delete All", 400, 300) $cTreeview = GUICtrlCreateTreeView(2, 2, 396, 225, $iStyle, $WS_EX_CLIENTEDGE) $hTreeView = GUICtrlGetHandle(-1) GUISetState() GUICtrlCreateButton("Delete All", 2, 250, 75, 25) GUICtrlSetOnEvent(-1, "DeleteAll") GUICtrlCreateButton("Rebuild Tree", 79, 250, 75, 25) GUICtrlSetOnEvent(-1, "BuildTree") BuildTree() ; Loop until user exits GUISetOnEvent($GUI_EVENT_CLOSE, 'Close') While 1 Sleep(10) WEnd EndFunc ;==>_Main Func DeleteAll() $message = "You did not click a parent." & @CRLF & "Why is this showing?" Local $hParentItem = _GUICtrlTreeView_GetFirstItem($hTreeView), $cItem = 0, $hChildItem Do $hChildItem = _GUICtrlTreeView_GetFirstChild($hTreeView, $hParentItem) Do $cItem = _GUICtrlTreeView_GetItemParam($hTreeView, $hChildItem) $hChildItem = _GUICtrlTreeView_GetNextChild($hTreeView, $hChildItem) ;GUICtrlSetOnEvent($cItem, "") ;unregister event GUICtrlDelete($cItem) ;delete child Until $hChildItem = 0 $cItem = _GUICtrlTreeView_GetItemParam($hTreeView, $hParentItem) ConsoleWrite('! Item Param Data (False for items added with UDF) = ' & $cItem & @crlf) $hParentItem = _GUICtrlTreeView_GetNextSibling($hTreeView, $hParentItem) GUICtrlSetOnEvent($cItem, "") ;unregister event GUICtrlDelete($cItem) ;delete parent Until $hParentItem = 0 ;purge message queue Opt("GUIOnEventMode", 0) ;switch to PeekMessage API (loop mode) Do Until GUIGetMsg() = 0 ;clear message queue Opt("GUIOnEventMode", 1) ;switch back to GetMessage API (event mode) $message = "You clicked a parent" EndFunc ;==>DeleteAll Func What() MsgBox(0, "Warning", $message) EndFunc ;==>What Func BuildTree() For $x = 1 To 5 $hItem = GUICtrlCreateTreeViewItem("Parent - " & $x, $cTreeView) GUICtrlSetOnEvent(-1, "What") ConsoleWrite('+ Item added ControlID = ' & $hItem & @crlf ) For $y = 1 To 5 GUICtrlCreateTreeViewItem("Child - " & $y, $hItem) Next _GUICtrlTreeView_SetChildren($cTreeView, $hItem) ;using control id for native items Next EndFunc ;==>BuildTree Func Close() GUIDelete($hTreeView) Exit EndFunc ;==>Close
×
×
  • Create New...