Jump to content

rover

Active Members
  • Posts

    792
  • Joined

  • Last visited

  • Days Won

    3

Reputation Activity

  1. Like
    rover got a reaction from Norm73 in Problem selecting listview item to tick a checkbox   
    you need to hittest and check that the click is not on a checkbox


    #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GuiListView.au3> Opt('MustDeclareVars', 1) Local $msg Local $search_gui = GUICreate("Product Scanner", 400, 300, -1, -1) Local $listview = GUICtrlCreateListView("Product ID|Category|Last Update", 2, 2, 394, 250) _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_BORDERSELECT, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES)) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUICtrlCreateListViewItem("1|2|3", $listview) GUICtrlCreateListViewItem("4|5|6", $listview) GUICtrlCreateListViewItem("7|8|9", $listview) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") If $iIDFrom = $listview Then Switch $iCode Case $NM_CLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) If @error Then Return $GUI_RUNDEFMSG Local $Item = DllStructGetData($tInfo, "Index") If @error Or $Item = -1 Then Return $GUI_RUNDEFMSG Local $tTest = DllStructCreate($tagLVHITTESTINFO) DllStructSetData($tTest, "X", DllStructGetData($tInfo, "X")) DllStructSetData($tTest, "Y", DllStructGetData($tInfo, "Y")) Local $iRet = GUICtrlSendMsg($iIDFrom, $LVM_HITTEST, 0, DllStructGetPtr($tTest)) If @error Or $iRet = -1 Then Return $GUI_RUNDEFMSG Switch DllStructGetData($tTest, "Flags") Case $LVHT_ONITEMICON, $LVHT_ONITEMLABEL, $LVHT_ONITEM If _GUICtrlListView_GetItemChecked($listview, $Item) = False Then _GUICtrlListView_SetItemChecked($listview, $Item, 1) Else _GUICtrlListView_SetItemChecked($listview, $Item, 0) EndIf Case $LVHT_ONITEMSTATEICON ;on checkbox EndSwitch EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc
  2. Thanks
    rover got a reaction from Parsix in Working example of GetTextColor()/GetBkColor()   
    Get text and background colour from standard controls

    How to retrieve the data you already have...

    Not a very useful thing, as it only works for in-process standard controls, but there you go.


    This example is based on code by Prog@ndy and Malkey in this thread:
    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    Standard Controls do not store colour in their Device Context. (CS_OWNDC)
    Using GetTextColor() on the controls DC returns 0xFFFFFF, (COLOR_WINDOW)
    the default value in the WNDCLASS structure. The parent window sets the colour (CS_PARENTDC)

    By sending a WM_CTLCOLORSTATIC message to the controls parent window.
    we can have it write to a temporary memory DC and then use GetTextColor/GetBkColor.



    The four functions return the RGB colours of visible, hidden or disabled Standard Controls
    on active, inactive, hidden, disabled, locked or minimized AutoIt GUI forms.

    The following form/control classes have been tested in XP/VISTA x86:

    AutoIt v3 GUI, Static (Label), Edit(Edit/Input), Button (Ownerdrawn/Classic Theme PushButton**, Group, Radio, CheckBox), ListBox, ComboBox



    _GuiCtrlGetTextColorEx() - get RGB text colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GuiCtrlGetBkColorEx() - get RGB background colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GUIGetBkColorEx() - get RGB background colour of active, inactive, hidden, locked, disabled or
    minimized in-process* forms. - the only feature this adds over existing forum examples is getting colour from a minimized gui

    _GuiCtrlGetColorEx() - all-in-one testing version with ownerdrawn/themed button testing
    Use the separate functions _GUICtrlGetTextColorEx() and_GUICtrlGetBkColorEx() instead of this


    *This UDF only supports controls in the current script process. It does not work with external process controls.

    Nor does it support controls that are painted on (colour not set by WM_CTLCOLORSTATIC message)
    themed controls or Common Controls (they have their own methods to retrieve colour)

    Does not return transparent layered window attributes, use _WinAPI_GetLayeredWindowAttributes()

    Disabled and/or hidden controls will still return their enabled colours,
    the WM_CTLCOLORSTATIC message does not return the system colours for disabled controls.

    **NOTE: ownerdrawn buttons with no set background color default to the COLOR_BTNFACE system colour,
    but the returned background mode is OPAQUE and the colour is the underlying colour of the parent gui,
    so GetPixel() is required to get the actual colour.

    There will probably be some conditions or OS versions where this code will return incorrect or no colour.


    Other get control colour examples:

    Get GUI Background color? is there such a thing??


    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    GUICtrlGetBkColor() - Get the background color of a control


    Get colour get label colour



    Example:
    Get text, background colour and background mode from four standard controls (visible/hidden/disabled)
    while looping through the following gui states: active, inactive, hidden, minimized, locked and disabled.



    ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include "_GetCtrlColorEx.au3" #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> Opt('MustDeclareVars', 1) Global $aColour, $aStr[4] = ["Edit", "Static 1", "Static 2", "Button "] Global $hGui = GUICreate('Get Control Colours', 230, 200) GUISetBkColor(0xABCDEF) Global $cFst = GUICtrlCreateInput('Edit', 20, 10, 160, 20);, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFF) GUICtrlCreateLabel("Static 1", 20, 45, 160, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) GUICtrlSetColor(-1, 0x191970) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel("Static 2", 20, 80, 160, 20) GUICtrlSetColor(-1, 0xFFE9A9) GUICtrlSetBkColor(-1, 0x6E7B80) GUICtrlCreateButton("Button", 20, 115, 160, 25) ;Ownerdrawn GUICtrlSetColor(-1, 0xFAFAFF) GUICtrlSetBkColor(-1, 0x494949) ;classic theme ;DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", "", "wstr", "") GUISetState() For $i = 0 To 6 Switch $i Case 0 ConsoleWrite("+ ACTIVE ====================" & @CRLF) Case 1 Sleep(1000) ConsoleWrite("+ INACTIVE ==================" & @CRLF) _WinAPI_SetWindowPos($hGui, $HWND_BOTTOM, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Case 2 Sleep(1000) _WinAPI_SetWindowPos($hGui, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Sleep(1000) ConsoleWrite("+ HIDDEN ====================" & @CRLF) GUISetState(@SW_HIDE) Case 3 Sleep(1000) GUISetState(@SW_SHOW) Sleep(1000) ConsoleWrite("+ MINIMIZED ==================" & @CRLF) GUISetState(@SW_MINIMIZE) Case 4 Sleep(1000) GUISetState(@SW_RESTORE) ConsoleWrite("+ LOCKED ======================" & @CRLF) GUISetState(@SW_LOCK) Case 5 Sleep(1000) GUISetState(@SW_UNLOCK) ConsoleWrite("+ DISABLED ====================" & @CRLF) GUISetState(@SW_DISABLE) Sleep(1000) Case 6 GUISetState(@SW_ENABLE) ConsoleWrite("+ CONTROLS HIDDEN/DISABLED =====" & @CRLF) For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_DISABLE) GUICtrlSetState($j, $GUI_HIDE) Next Sleep(1000) EndSwitch For $k = $cFst To ($cFst+3) $aColour = _GUICtrlGetColorEx($k, 1) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & $aColour[0][0] & @CRLF) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & _GUICtrlGetTextColorEx($k, 1) & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & $aColour[1][0] & " - " & $aColour[1][1] & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & _GUICtrlGetBkColorEx($k, 1) & " - Mode: " & @extended & @CRLF & @CRLF) Next ConsoleWrite("> GUI BkGnd Colour: " & _GUIGetBkColorEx($hGui, 1) & @CRLF & @CRLF) Next For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_ENABLE) GUICtrlSetState($j, $GUI_SHOW) Next Do Until GUIGetMsg() = -3 Exit_GetCtrlColorEx.au3
  3. Like
    rover got a reaction from Norm73 in Remove GUI title bar icon   
    Replace the icon with a blank


    $hGUI = GUICreate("No Icon", 300, 200) GUISetIcon(@AutoItExe, -2, $hGUI) GUISetState() Do Until GUIGetMsg() = -3
  4. Like
    rover got a reaction from Parsix in _GUICtrlStatusBar_SetText   
    statusbar text colour is a bit more problematic as it requires ownerdrawing and more code
    this example is a modified version of Rasim's demo with ownerdraw code added for statusbar part text and background colour

    Cheers

    to whom it may concern: please refrain from posting this code in the example scripts forum without author attribution.

    Edit Hi Rasim

    ;to whom it may concern: please refrain from posting this code in the example scripts forum with no attribution to the author. ;Author: rover ;Ownerdrawn StatusBar text font and colour demo ;set text colour and font for StatusBar parts ;modified version of demo by Rasim for setting StatusBar font ;http://www.autoitscript.com/forum/index.php?showtopic=88063 #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <FontConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hFont Global $aParts[3] = [125, 250] Global $aPartsText[2] = ["RED on Transparent", "BLUE on Transparent"] Global $hGUI = GUICreate("Statusbar custom font and colour demo", 400, 300) GUISetBkColor(0xE0FFFF) Global $hStatus = _GUICtrlStatusBar_Create($hGUI) _GUICtrlStatusBar_SetParts($hStatus, $aParts) ; add text and color to struct called in WM_DRAWITEM message handler Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000); Red on transparent background Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0); Blue on transparent background ;_GUICtrlStatusBar_SetText($hStatus, "", 0, $SBT_OWNERDRAW); text not set when ownerdrawn ;_GUICtrlStatusBar_SetText($hStatus, "", 1, $SBT_OWNERDRAW) _GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS") GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM") GUISetState() Sleep(3000) ;you can use the above _GUICtrlStatusBar_SetText() lines and set text and colour in the message handler ;or use _GUICtrlStatusBar_SetColor() to change text, text colour and part background colour more easily Local $iCnt = 0 Do $iCnt +=1 $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, "GOLD on BLACK", 0, 0xFFD700, 0) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, "BLUE on GOLD", 1, 0x0C0DC0, 0xFFD700) Sleep(500) $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0) Sleep(500) Until $iCnt = 5 Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") ;Author: Rasim $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;" & _ "uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) Local $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm"); retrieve statusbar handle Switch _WinAPI_GetClassName($hItm);an example of how message handler does not have to rely on having global variable for statusbar in advance ;Switch $hItm Case "msctls_statusbar32" ;Case $hStatus Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC") ; device context for statusbar for color and/or font Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID"); statusbar part number ; get 32-bit value in itmData when text has SBT_OWNERDRAW drawing type - pointer to struct with text and color Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData") Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam) ; create RECT structure from itmRect byte array for part metrics Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") ; metrics not same as non-ownerdrawn part for some reason, so 1 added for alignment DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)+1) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)+1) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) _WinAPI_SetBkMode($hDC, $TRANSPARENT); otherwise text background set to 0xFFFFFF _WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2)); set part text colour from struct If Not DllStructGetData($tParam, 4) Then; check if background should be transparent Local $iBkColor = DllStructGetData($tParam, 3), $hStatusDC, $hBrushBk $hStatusDC = _WinAPI_GetDC($hItm) $hBrushBk = _WinAPI_CreateSolidBrush($iBkColor) _WinAPI_FillRect($hStatusDC, DllStructGetPtr($tRect), $hBrushBk) _WinAPI_DeleteObject($hBrushBk) _WinAPI_ReleaseDC($hItm, $hStatusDC) EndIf ; draw text to DC (can also use gdi32 TextOutW and ExtTextOut API's) _WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRect, $DT_LEFT) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1) ;Author: rover - modified ownerdraw version of _GUICtrlStatusBar_SetText() from GuiStatusBar.au3 ;Includes RGB2BGR() - Author: Siao - http://www.autoitscript.com/forum/index.php?s=&showtopic=57161&view=findpost&p=433593 ;sets itmData element of statusbar DRAWITEMSTRUCT with pointer to struct with text and colour for part number If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd) Local $ret, $tStruct, $pStruct, $iBuffer ; In Microsoft Windows XP and earlier, the text for each part is limited to 127 characters. ; This limitation has been removed in Windows Vista. ; set sufficiently large buffer for use with Vista (can exceed XP limit of 128 chars) $tStruct = DllStructCreate("wchar Text[512];dword Color;dword BkColor;dword Trans") Switch $iBkColor Case -1 DllStructSetData($tStruct, "Trans", 1) Case Else $iBkColor = BitAND(BitShift(String(Binary($iBkColor)), 8), 0xFFFFFF) DllStructSetData($tStruct, "Trans", 0) DllStructSetData($tStruct, "BkColor", $iBkColor) EndSwitch $iColor = BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF); From RGB2BGR() Author: Siao DllStructSetData($tStruct, "Text", $sText) DllStructSetData($tStruct, "Color", $iColor) $pStruct = DllStructGetPtr($tStruct) If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID ;FOR INTERNAL STATUSBARS ONLY If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then $ret = _SendMessage($hWnd, $SB_SETTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr") Return $tStruct; returns struct to global variable EndIf Return 0 EndFunc ;==>_GUICtrlStatusBar_SetColor
  5. Like
    rover got a reaction from GicuPiticu in A better tool than Auinfo?   
    The Winspector site windows-spy.com is gone (the last entry at Archive.org is in 2008), but for some reason the file is available from Archive.org (the WayBack Machine).
    normally files are not archived from sites from my experience with Archive.org

    http://web.archive.org/web/20080615232304/http://www.windows-spy.com/files/Winspector_setupU.exe
    or
    http://www.softpedia.com/get/Security/Security-Related/Winspector.shtml

    http://web.archive.org/web/20080615230748/http://www.windows-spy.com/
    http://web.archive.org/web/20080615230748/http://www.windows-spy.com/download/
    http://web.archive.org/web/20080615232304/www.windows-spy.com/download/

    another utility I use is Window Detective
    http://sourceforge.net/projects/windowdetective/

    These two apps will read controls in windows that the AutoIt info tool doesn't.

    that MediTech app may use DirectUI or a Citrix like interface, you can't read those with these tools.

    search google and groups.google.com for "meditech software automation"
    the comments in this forum don't sound promising
    http://forums.networkautomation.com/forum/messageview.cfm?catid=34&threadid=8151

    look for AccExplorer or UISpy, they will show if the interface is DirectUI.
    I don't know if code is available yet on the forums in a user friendly form to automate these IAccessible object interfaces.

    this article will show you whats involved.
    UI Automation Using Microsoft Active Accessibility (MSAA)
    http://www.codeproject.com/KB/winsdk/MSAA_UI_Automation.aspx
  6. Thanks
    rover got a reaction from mike2003 in Live Slider Control   
    search forum for WM_HSCROLL, many examples of this

    register WM_HSCROLL and/or WM_VSCROLL
    messages only occur on event
    no continuous slider reading in main loop
    can be used with OnEvent or loop mode


    #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SliderConstants.au3> Opt('MustDeclareVars', 1) ;Global Const $WM_HSCROLL = 0x0114 ;Global Const $WM_VSCROLL = 0x0115 Global $Slider, $hSlider, $Dummy, $iBuffer, $Label Example() Func Example() Local $hGUI, $msg $hGUI = GUICreate("Slider Demo", 280, 100) $Label = GUICtrlCreateLabel('0', 125, 50, 30, 20) $Slider = GUICtrlCreateSlider(40, 10, 200, 30, BitOR($TBS_AUTOTICKS, $TBS_TOOLTIPS)) $hSlider = GUICtrlGetHandle($Slider) GUICtrlSetCursor(-1, 0) $Dummy = GUICtrlCreateDummy() ;one or both at same time GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") ;horz slider ;GUIRegisterMsg($WM_VSCROLL, "WM_HVSCROLL");vert slider GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $Dummy _Slider() EndSwitch Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _Slider() Local $iValue, $sValue $iValue = GUICtrlRead($Dummy) If $iBuffer <> $iValue Then $iBuffer = $iValue GUICtrlSetData($Label, $iBuffer) ;ConsoleWrite('-Value = ' & $iBuffer & @CRLF) EndIf Return EndFunc ;==>_Slider Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Switch $iMsg Case $WM_HSCROLL Switch $lParam Case $hSlider GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider)) EndSwitch Case $WM_VSCROLL EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_HVSCROLL
  7. Thanks
    rover got a reaction from Norm73 in Temporarily Disable contextmenu   
    SoulA
    modified helpfile example without any checking for menu handles.
    use the GuiMenu.au3 UDF to make menus
    you can check for the handles of using wparam in _WM_CONTEXTMENU().

    see helpfile GuiMenu UDF section example for _GUICtrlMenu_CreatePopup ()

    Edit: added comment on helpfile example

    #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Local $contextmenu, $button, $buttoncontext, $buttonitem, $msg, $iFlag = 0 Local $newsubmenu, $textitem, $fileitem, $saveitem, $infoitem ;right click on gui to bring up context Menu. ;right click on the "ok" button to bring up a control specific context menu. ;click on the "ok" button to disable contextmenus GUICreate("My GUI Context Menu", 300, 200) $button = GUICtrlCreateButton("Context Menu Enabled", 75, 100, 150, 20) $buttoncontext = GUICtrlCreateContextMenu($button) $buttonitem = GUICtrlCreateMenuItem("About button", $buttoncontext) $contextmenu = GUICtrlCreateContextMenu() $newsubmenu = GUICtrlCreateMenu("new", $contextmenu) $textitem = GUICtrlCreateMenuItem("text", $newsubmenu) $fileitem = GUICtrlCreateMenuItem("Open", $contextmenu) $saveitem = GUICtrlCreateMenuItem("Save", $contextmenu) GUICtrlCreateMenuItem("", $contextmenu) ; separator $infoitem = GUICtrlCreateMenuItem("Info", $contextmenu) GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") GUISetState() While 1 Switch GUIGetMsg() Case $button $iFlag = Not $iFlag If $iFlag Then GUICtrlSetData($button, "Context Menu Disabled") Else GUICtrlSetData($button, "Context Menu Enabled") EndIf Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _WM_CONTEXTMENU($hwnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam If $iFlag Then Return 0 Return $GUI_RUNDEFMSG EndFunc
  8. Like
    rover got a reaction from mLipok in _WinAPI_ClearConsole - _WinAPI_CursorShowConsole   
    _WinAPI_ClearConsole
    Clear console screen buffer, six options to set cursor and clear or overwrite text

    _WinAPI_CursorShowConsole
    Show or hide cursor and set cursor size

    NOTE: for scripts compiled as console apps with wrapper directive: #AutoIt3Wrapper_Change2CUI=y

    some console related links:

    Overwriting StdOut in CUI compiled app
    http://www.autoitscript.com/forum/index.php?showtopic=66486

    set text colour attributes
    http://www.autoitscript.com/forum/index.ph...st&p=493255

    CMD.au3
    http://www.autoit.de/index.php?page=Thread...44881#post44881

    How To Performing [sic] Clear Screen (CLS) in a Console Application
    http://support.microsoft.com/kb/99261

    Clearing the Screen (Windows)
    http://msdn.microsoft.com/en-us/library/ms682022.aspx

    Screen_Scrape.au3
    http://www.autoitscript.com/forum/index.ph...st&p=527810

    Edit 1 second example added - DOS character set frame around multiple data displays and mid line progress bar
    Edit 2 corrected error in parameter range check on X Y coordinates - Thanks Authenticity

    Example 1: Console line editing and data display updating on a row
    [autoit]#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Change2CUI=y
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

    If Not @Compiled Then Exit MsgBox(262144 + 16, "_WinAPI_ClearConsole() Test", "Script must be compiled as a console app to run")

    Opt('MustDeclareVars', 1)

    ;clear screen - clears prompt if run from command line
    Local $hStdOut = _WinAPI_ClearConsole()

    ;save previous cursor, hide cursor
    Local $iPrevSize = _WinAPI_CursorShowConsole($hStdOut, False)

    #Region - Console line editing example
    ;//////////////////////////////////////////////////////////////////////////////////////
    ;Example demonstrating console line editing
    ;//////////////////////////////////////////////////////////////////////////////////////

    Local $aArray = StringSplit("4D7900204B61726D61002072756E00206F76657200206D790020446F676D61", "00", 1)
    Local $iCnt

    ; sequentially append text to end of row 0 ($iCnt is character column position on row)
    For $i = 1 To $aArray[0]
    ConsoleWrite(BinaryToString("0x" & $aArray[$i]))
    Sleep(750)
    $iCnt += (StringLen($aArray[$i]) / 2)
    _WinAPI_ClearConsole(-1, $iCnt, 0)
    Next

    ConsoleWrite(@CRLF)

    ;add a block of rows
    For $i = 1 To 6
    ConsoleWrite("Jackdaws love my big sphinx of quartz" & @CRLF)
    Next

    Sleep(1000)

    ; set cursor size to a block
    _WinAPI_CursorShowConsole($hStdOut, True, 100)

    ; clear then write single rows with new text
    For $i = 1 To 3
    _WinAPI_ClearConsole(-1, Default, $i)
    Sleep(1000)
    ConsoleWrite("New row " & $i)
    Next

    Sleep(2000)
    _WinAPI_ClearConsole(-1, -2, -1) ; clear a block of 2 rows starting on row 1
    ConsoleWrite("correcting 'Typo' in row 0")
    Sleep(2000)
    _WinAPI_ClearConsole(-1, -10, 0) ; change letter in first row of text
    ConsoleWrite("a")
    Sleep(2000)
    _WinAPI_ClearConsole(-1, Default, 1) ; clear row 1
    ConsoleWrite("Done")
    Sleep(1000)
    _WinAPI_ClearConsole(-1, 0, 0) ; set cursor on character column 0 and row 0
    Sleep(1000)
    _WinAPI_ClearConsole(-1, 0, Default) ; set cursor on character column 0 and bottom row
    Sleep(1000)
    _WinAPI_ClearConsole(-1, Default, -1) ; clear all rows starting at second row
    Sleep(1000)
    _WinAPI_ClearConsole() ; clear screen (set cursor on character column 0 and row 0)
    ;//////////////////////////////////////////////////////////////////////////////////////
    #EndRegion - Console line editing example


    #Region - Console label and data updating on a row
    ;//////////////////////////////////////////////////////////////////////////////////////
    ;Example demonstrating label and data updating on a row
    ;//////////////////////////////////////////////////////////////////////////////////////
    ;Overwriting StdOut in CUI compiled app, for use with progress indicator
    ;http://www.autoitscript.com/forum/index.php?showtopic=66486

    ;hide cursor
    _WinAPI_CursorShowConsole($hStdOut, False)

    Local $progress, $buffer, $ClearProgress
    ConsoleWrite("Milliseconds: " & @CRLF)
    ConsoleWrite("Seconds : " & @CRLF)
    ConsoleWrite("Progress" & @CRLF)

    For $i = 0 To 500
    Sleep(10)
    _WinAPI_ClearConsole(-1, 14, 0)
    ConsoleWrite(@MSEC)
    _WinAPI_ClearConsole(-1, 14, 1)
    ConsoleWrite(@SEC)
    If @SEC <> $buffer Then
    _WinAPI_ClearConsole(-1, 8, 2)
    $buffer = @SEC
    $progress &= "."
    ConsoleWrite($progress)
    $ClearProgress += 1
    If $ClearProgress = 25 Then
    $ClearProgress = 0
    $progress = ""
    EndIf
    EndIf
    Next
    ;//////////////////////////////////////////////////////////////////////////////////////
    #EndRegion - Console label and data updating on a row


    ;restore and show cursor, clear console
    _WinAPI_CursorShowConsole($hStdOut, True, $iPrevSize)
    _WinAPI_ClearConsole()
    Sleep(1000)
    Exit


    ; #FUNCTION# =======================================================
    ; Name...........: _WinAPI_ClearConsole
    ; Description ...: Clears console screen buffer /w six options to clear rows & characters & set cursor position
    ; Syntax.........: _WinAPI_ClearConsole($hConsole = -1, $iX = Default, $iY = Default)
    ; Parameters ....: $hConsole - (Optional) Handle to standard output device
    ; $iX - (Optional) zero based character column position of cursor
    ; Default or 0 to screen buffer max width (negative values for some modes)
    ; $iY - (Optional) zero based row position of cursor
    ; Default or 0 to screen buffer max height (negative values for some modes)
    ;
    ;No params ; clear screen (-1, Default, Default)
    ;(-1, Default, 0) ; clear single row: $iY = row number (0 is row 1)
    ;(-1, -2, -3) ; clear block of rows: -$iX = number of rows, -$iY = starting row (minimum $iX = -1, $iY = -1)
    ;(-1, Default, -1) ; clear all rows from start row: -$iY = starting row (minimum $iY = -1)
    ;(-1, 20, 2) ; clear characters to end of row: $iX = start character column, $iY = row number
    ;(-1, -20, 2) ; set cursor at coordinates: -$iX = start character column, $iY = row number (minimum $iX = -1)
    ;(-1, 0, Default) ; set cursor on bottom row of console window: $iX = start character column

    ; Return values .: Success - return handle to standard output device (does not have to be closed)
    ; Failure - return 0, set error and extended
    ; Author ........: rover
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ;
    ; Link ..........; @@MsdnLink@@ FillConsoleOutputCharacter
    ; Example .......; Yes
    ; ==================================================================
    Func _WinAPI_ClearConsole($hConsole = -1, $iX = Default, $iY = Default)
    Local $dwCoord, $fFlag = False
    Local $bChar = 0x20, $iErr ; fill character: 0x20 (Space)
    Local Const $STD_OUTPUT_HANDLE = -11
    Local Const $INVALID_HANDLE_VALUE = -1
    Local Const $tagCONSOLE_SCREEN_BUFFER_INFO = "short dwSizeX; short dwSizeY;short dwCursorPositionX;" & _
    "short dwCursorPositionY; short wAttributes;short Left; short Top; short Right; short Bottom;" & _
    "short dwMaximumWindowSizeX; short dwMaximumWindowSizeY"

    ;// get handle to standard output device (handle does not have to be closed on return)
    Local $hDLLK32 = DllOpen("Kernel32.dll"), $aRet
    If $hConsole = -1 Then
    $aRet = DllCall($hDLLK32, "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE)
    $iErr = @error
    If @error Or UBound($aRet) <> 2 Or $aRet[0] = $INVALID_HANDLE_VALUE Then
    Return SetError($iErr, 1, $INVALID_HANDLE_VALUE)
    EndIf
    $hConsole = $aRet[0]
    EndIf

    ;// create console screen buffer struct, get buffer
    Local $tCONSOLE_SCREEN_BUFFER_INFO = DllStructCreate($tagCONSOLE_SCREEN_BUFFER_INFO)
    If @error Then Return SetError(@error, 2, 0)
    Local $pConsoleScreenBufferInfo = DllStructGetPtr($tCONSOLE_SCREEN_BUFFER_INFO)
    If @error Then Return SetError(@error, 3, 0)

    $aRet = DllCall($hDLLK32, "int", "GetConsoleScreenBufferInfo", "hwnd", _
    $hConsole, "ptr", $pConsoleScreenBufferInfo)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 4, 0)

    ;// Get the screen buffer max width (character columns) and height (rows)
    Local $dwSizeX = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "dwSizeX")
    Local $dwSizeY = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "dwSizeY")
    Local $dwConSize

    ;// input coordinates range check
    If IsNumber($iX) And (Abs($iX) > ($dwSizeX -1)) Then $iX = $dwSizeX -1
    If IsNumber($iY) And (Abs($iY) > ($dwSizeY -1)) Then $iY = $dwSizeY -1

    Select
    ;// clear screen (Default) - max screen buffer width multiplied by height
    Case IsNumber($iX) = 0 And IsNumber($iY) = 0
    ; handles Default keyword and strings in params
    $dwConSize = ($dwSizeX * $dwSizeY)
    $iX = 0
    $iY = 0
    ;// overwrite or clear any single row - cursor now set to start of that row
    Case IsKeyword($iX) = 1 And IsKeyword($iY) = 0 And $iY >= 0
    $dwConSize = $dwSizeX
    $iX = 0
    ;// overwrite or clear a number of rows from starting row
    ;(-$iX parameter is number of rows to overwrite, second row minimum)
    Case $iX < 0 And $iY < 0
    $iY = Abs($iY)
    $dwConSize = ($dwSizeX * Abs($iX))
    $iX = 0
    ;// overwrite or clear all rows from starting row to last row, second row minimum)
    Case IsKeyword($iX) = 1 And $iY < 0
    $iY = Abs($iY)
    $dwConSize = ($dwSizeX * $dwSizeY) - ($dwSizeX * $iY)
    $iX = 0
    ;// overwrite or clear text from character position on row to end of row
    Case $iX >= 0 And IsKeyword($iY) = 0 And $iY >= 0
    $dwConSize = ($dwSizeX - $iX)
    If $iX = 0 And $iY = 0 Then
    $fFlag = True
    ContinueCase
    EndIf
    ;// place cursor at last row of console window
    Case $iX >= 0 And IsKeyword($iY) = 1
    If Not $fFlag Then $iY = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "Bottom")
    ContinueCase
    ;// places cursor at coordinates for overwriting
    Case $iX < 0 And $iY >= 0
    $dwCoord = BitOR($iY * 0x10000, BitAND(Abs($iX), 0xFFFF))
    $aRet = DllCall($hDLLK32, "int", "SetConsoleCursorPosition", "hwnd", _
    $hConsole, "dword", $dwCoord)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 5, 0)
    DllClose($hDLLK32)
    Return SetError(0, 0, $hConsole)
    Case Else
    Return SetError(@error, 6, 0)
    EndSelect

    ;// Cursor position: make DWord of X,Y coordinates)
    $dwCoord = BitOR($iY * 0x10000, BitAND($iX, 0xFFFF))

    ;// Fill selected rows with blanks
    $aRet = DllCall($hDLLK32, "int", "FillConsoleOutputCharacterW", "hwnd", $hConsole, _
    "byte", $bChar, "dword", $dwConSize, "dword", $dwCoord, "int*", 0)
    $iErr = @error
    If @error Or UBound($aRet) <> 6 Or $aRet[5] <> $dwConSize Then Return SetError($iErr, 7, 0)

    ;// Get the current text attributes
    $aRet = DllCall($hDLLK32, "int", "GetConsoleScreenBufferInfo", "hwnd", _
    $hConsole, "dword", $pConsoleScreenBufferInfo)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 8, 0)
    Local $wAttribute = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "wAttributes")

    ;// Set the buffer's attributes
    $aRet = DllCall($hDLLK32, "int", "FillConsoleOutputAttribute", "hwnd", $hConsole, _
    "short", $wAttribute, "dword", $dwConSize, "dword", $dwCoord, "int*", 0)
    $iErr = @error
    If @error Or UBound($aRet) <> 6 Or $aRet[5] <> $dwConSize Then Return SetError($iErr, 9, 0)

    ;// Put the cursor at 0,0 or supplied coordinates
    $aRet = DllCall($hDLLK32, "int", "SetConsoleCursorPosition", "hwnd", _
    $hConsole, "dword", $dwCoord)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 10, 0)
    DllClose($hDLLK32)
    Return SetError(@error, 0, $hConsole)
    EndFunc ;==>_WinAPI_ClearConsole

    ; #FUNCTION# =======================================================
    ; Name...........: _WinAPI_CursorShowConsole
    ; Description ...: Show or Hide console cursor, set cursor size
    ; Syntax.........: _WinAPI_CursorShowConsole($hConsole, $fShow = True, $iSize = Default)
    ; Parameters ....: $hConsole - Handle to standard output device
    ; $fShow - Boolean: True - show cursor, False - hide cursor
    ; $iSize - (Optional) set cursor size 1-100
    ;
    ; Return values .: Success - return previous cursor size
    ; Failure - return 0, set error and extended
    ; Author ........: rover
    ; Modified.......:
    ; Remarks .......:
    ;
    ; Related .......:
    ; Link ..........; @@MsdnLink@@ SetConsoleCursorInfo / GetConsoleCursorInfo
    ; Example .......; Yes
    ; ==================================================================
    Func _WinAPI_CursorShowConsole($hConsole = -1, $fShow = True, $iSize = Default)
    If $hConsole = -1 Then Return SetError(1, 1, 0)
    ;// create console cursor info struct
    Local $aRet, $iErr
    Local Const $tagCONSOLE_CURSOR_INFO = "dword dwSize;int bVisible"
    Local $tCONSOLE_CURSOR_INFO = DllStructCreate($tagCONSOLE_CURSOR_INFO)
    If @error Then Return SetError(@error, 2, 0)

    Local $pCONSOLE_CURSOR_INFO = DllStructGetPtr($tCONSOLE_CURSOR_INFO)
    If @error Then Return SetError(@error, 3, 0)

    $aRet = DllCall("Kernel32.dll", "int", "GetConsoleCursorInfo", _
    "hwnd", $hConsole, "ptr", $pCONSOLE_CURSOR_INFO)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 4, 0)

    Local $iPrevSize = DllStructGetData($tCONSOLE_CURSOR_INFO, "dwSize")
    If @error Then Return SetError(@error, 5, 0)

    DllStructSetData($tCONSOLE_CURSOR_INFO, "bVisible", $fShow)
    If @error Then Return SetError(@error, 6, 0)

    If Not IsKeyword($iSize) And IsNumber($iSize) Then
    DllStructSetData($tCONSOLE_CURSOR_INFO, "dwSize", $iSize)
    If @error Then Return SetError(@error, 7, 0)
    EndIf

    DllCall("Kernel32.dll", "int", "SetConsoleCursorInfo", _
    "hwnd", $hConsole, "ptr", $pCONSOLE_CURSOR_INFO)
    $iErr = @error
    If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 8, 0)

    Return SetError(@error, 0, $iPrevSize)
    EndFunc ;==>_WinAPI_CursorShowConsole
  9. Thanks
    rover got a reaction from pixelsearch in Temporarily Disable contextmenu   
    SoulA
    modified helpfile example without any checking for menu handles.
    use the GuiMenu.au3 UDF to make menus
    you can check for the handles of using wparam in _WM_CONTEXTMENU().

    see helpfile GuiMenu UDF section example for _GUICtrlMenu_CreatePopup ()

    Edit: added comment on helpfile example

    #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Local $contextmenu, $button, $buttoncontext, $buttonitem, $msg, $iFlag = 0 Local $newsubmenu, $textitem, $fileitem, $saveitem, $infoitem ;right click on gui to bring up context Menu. ;right click on the "ok" button to bring up a control specific context menu. ;click on the "ok" button to disable contextmenus GUICreate("My GUI Context Menu", 300, 200) $button = GUICtrlCreateButton("Context Menu Enabled", 75, 100, 150, 20) $buttoncontext = GUICtrlCreateContextMenu($button) $buttonitem = GUICtrlCreateMenuItem("About button", $buttoncontext) $contextmenu = GUICtrlCreateContextMenu() $newsubmenu = GUICtrlCreateMenu("new", $contextmenu) $textitem = GUICtrlCreateMenuItem("text", $newsubmenu) $fileitem = GUICtrlCreateMenuItem("Open", $contextmenu) $saveitem = GUICtrlCreateMenuItem("Save", $contextmenu) GUICtrlCreateMenuItem("", $contextmenu) ; separator $infoitem = GUICtrlCreateMenuItem("Info", $contextmenu) GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") GUISetState() While 1 Switch GUIGetMsg() Case $button $iFlag = Not $iFlag If $iFlag Then GUICtrlSetData($button, "Context Menu Disabled") Else GUICtrlSetData($button, "Context Menu Enabled") EndIf Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _WM_CONTEXTMENU($hwnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam If $iFlag Then Return 0 Return $GUI_RUNDEFMSG EndFunc
  10. Thanks
    rover got a reaction from Professor_Bernd in Temporarily Disable contextmenu   
    SoulA
    modified helpfile example without any checking for menu handles.
    use the GuiMenu.au3 UDF to make menus
    you can check for the handles of using wparam in _WM_CONTEXTMENU().

    see helpfile GuiMenu UDF section example for _GUICtrlMenu_CreatePopup ()

    Edit: added comment on helpfile example

    #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Local $contextmenu, $button, $buttoncontext, $buttonitem, $msg, $iFlag = 0 Local $newsubmenu, $textitem, $fileitem, $saveitem, $infoitem ;right click on gui to bring up context Menu. ;right click on the "ok" button to bring up a control specific context menu. ;click on the "ok" button to disable contextmenus GUICreate("My GUI Context Menu", 300, 200) $button = GUICtrlCreateButton("Context Menu Enabled", 75, 100, 150, 20) $buttoncontext = GUICtrlCreateContextMenu($button) $buttonitem = GUICtrlCreateMenuItem("About button", $buttoncontext) $contextmenu = GUICtrlCreateContextMenu() $newsubmenu = GUICtrlCreateMenu("new", $contextmenu) $textitem = GUICtrlCreateMenuItem("text", $newsubmenu) $fileitem = GUICtrlCreateMenuItem("Open", $contextmenu) $saveitem = GUICtrlCreateMenuItem("Save", $contextmenu) GUICtrlCreateMenuItem("", $contextmenu) ; separator $infoitem = GUICtrlCreateMenuItem("Info", $contextmenu) GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") GUISetState() While 1 Switch GUIGetMsg() Case $button $iFlag = Not $iFlag If $iFlag Then GUICtrlSetData($button, "Context Menu Disabled") Else GUICtrlSetData($button, "Context Menu Enabled") EndIf Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _WM_CONTEXTMENU($hwnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam If $iFlag Then Return 0 Return $GUI_RUNDEFMSG EndFunc
  11. Like
    rover got a reaction from krasnoshtan in [SOLVED] Detect click on TrayTip?!   
    n3ne you need to subclass the hidden parent window 'AutoIt v3' to get the custom WM_USER+1 callback message
    registered with the Notification Area toolbar for tray icon events.
    you want the NIN_BALLOONUSERCLICK and NIN_BALLOONTIMEOUT notifications (NIN_BALLOONTIMEOUT also sent if traytip close icon clicked).

    the drawback is subclassing...
    the SetWindowLong call can occasionally fails to subclass the AutoIt v3 hidden window.
    on one slow machine (old 1.4gig Athlon running XP) SetWindowLong will occasionally give 'Access is denied.' error.
    on my faster machines (2.2G Athlon, 2.6G P4) I can't get it to error at all, even running multiple instances.
    (multiple instances to check that subclassing worked for every instance)
    YMMV so test away
    see example script notes ***

    I see there is a problem with the traytip not appearing again when an instance sets a TrayTip when another instance is already displaying a traytip
    but that would have to be a windows issue.

    you could also use the messages TTM_ACTIVATE or WM_ACTIVATEAPP = True and WM_LBUTTONUP with Hi/Lo word lparam tooltip coordinates hittest
    to discriminate between a click on tooltip or close button (using GuiRegisterMsg or subclassing tooltip). but again, more workarounds...

    an alternative to subclassing the AutoIt v3 gui is to create your own tray icon with Shell_NotifyIconW API,
    handle the WM_USER+1 callback message with GuiRegisterMsg and check for the NIN_BALLOONUSERCLICK and NIN_BALLOONTIMEOUT notifications.
    Holgers ModernMenu UDF does this,
    but like customdrawn/ownerdrawn controls its more work.

    Cheers

    Edit: with further testing launching multiple instances I get 1 access denied in 20 to 30 instances on P4 and 3 or 4 access denied in 20 instances on Athlon
    creating a tray icon with Shell_NotifyIconW is best approach...
    Edit2: typos
    Edit3: found problem: example updated with ProgAndys AutoItWinGetHandle function
    Access denied error caused by using AutoItWinGetTitle with WinGetHandle to retrieve the AutoIt v3 window handle without first editing the title.
    sometimes you overlook the obvious...
    Edit4: added Return SetError(0, 0, 1) to _SubclassWin(), another typo


    ;Author: rover 07/04/09 ;MSDN reference: ;Shell_NotifyIcon Function ;http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4 Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5 ;Global Const $GWLP_WNDPROC = -4; for SetWindowLongPtr Global $wProcNew = 0, $wProcOld = 0, $iMsg, $iError = 0 ;get handle to AutoIt v3 hidden gui Global $hGUI1 = _AutoItWinGetHandle() ;$hGUI1 = WinGetHandle(AutoItWinGetTitle()) ;will work without GUICreate but global vars must be set in WndProc instead of GUICtrlCreateDummy/GUICtrlSendToDummy ;NOTE: _WinAPI_SetWindowLong() in WinAPI.au3 consistently returns 'The specified procedure could not be found' error 127 ;error is due to the call being SetWindowLong instead of SetWindowLongW, ;using SetWindowLongW the error message is 'The operation completed successfully. Global $hGUI2 = GUICreate("Traytip click detect", 260, 150, @DesktopWidth - 400, @DesktopHeight - 300) Global $cTooltipClose = GUICtrlCreateDummy() Global $cTooltipClick = GUICtrlCreateDummy() Global $cLabel1 = GUICtrlCreateLabel("Traytip area clicked", 70, 80, 120, 16, $SS_CENTER) Global $cLabel2 = GUICtrlCreateLabel("", 10, 110, 240, 16, $SS_CENTER) GUICtrlSetBkColor(-1, 0xFFFFFF) Global $cButton = GUICtrlCreateButton("Create Traytip", 70, 30, 120, 25) GUISetState() ;subclass AutoIt v3 gui to get tray icon/traytip notifications _SubclassWin($hGUI1, $wProcNew, $wProcOld) Global $sLastError = _WinAPI_GetLastErrorMessage() ConsoleWrite('- GetLastErrorMessage ' & $sLastError & "- Error: " & _WinAPI_GetLastError() & @CRLF) ConsoleWrite('+$wProcOld = ' & $wProcOld & @CRLF) GUICtrlSetData($cLabel2, $sLastError) If StringInStr($sLastError, "Access is denied.") <> 0 Then GUICtrlSetBkColor($cLabel2, 0xFF0000) EndIf While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $cButton TrayTip("Clear", "", 1) TrayTip("I'm a title", "I'm the message", 5, 1) Case $cTooltipClick GUICtrlSetData($cLabel2, "") GUICtrlSetColor($cLabel2, 0x0000FF) Sleep(100) GUICtrlSetData($cLabel2, "Tooltip clicked") ConsoleWrite("!NIN_BALLOONUSERCLICK" & @CRLF) Case $cTooltipClose GUICtrlSetData($cLabel2, "") GUICtrlSetColor($cLabel2, 0xFF0000) Sleep(100) GUICtrlSetData($cLabel2, "Tooltip closed") ConsoleWrite("-NIN_BALLOONTIMEOUT" & @CRLF) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _SubclassWin($hWnd, ByRef $hProcNew, ByRef $hProcOld) If $hProcNew <> 0 Or $hProcOld <> 0 Then Return SetError(1, 0, 0) $hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam") If @error Or $hProcNew = 0 Then Return SetError(2, 0, 0) $hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", _ $hWnd, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew)) If @error Or $hProcOld[0] = 0 Then $hProcOld = 0 Return SetError(3, 0, 0) EndIf $hProcOld = $hProcOld[0] Return SetError(0, 0, 1) EndFunc;==>_SubclassWin Func _RestoreWndProc($hWnd, ByRef $hProcNew, ByRef $hProcOld) If $hProcOld <> 0 Then _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, $hProcOld) If $hProcNew <> 0 Then DllCallbackFree($hProcNew) $hProcNew = 0 $hProcOld = 0 EndFunc;==>_RestoreWndProc Func OnAutoItExit() _RestoreWndProc($hGUI1, $wProcNew, $wProcOld) EndFunc;==>OnAutoItExit Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Switch $iMsg Case $WM_USER + 1;AutoIt callback message value for tray icon (1025), can be retrieved with ReadProcessMemory and TRAYDATA struct Switch $ilParam Case $NIN_BALLOONTIMEOUT; timeout and by tooltip close icon GUICtrlSendToDummy($cTooltipClose) Case $NIN_BALLOONUSERCLICK GUICtrlSendToDummy($cTooltipClick) EndSwitch EndSwitch ; pass the unhandled messages to default WindowProc Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $iwParam, $ilParam) EndFunc;==>_AutoItWndProc ;=============================================================================== ; ; Function Name: _AutoItWinGetHandle ; Description:: Returns the Windowhandle of AutoIT-Window ; Parameter(s): -- ; Requirement(s): -- ; Return Value(s): Autoitwindow Handle ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _AutoItWinGetHandle() Local $oldTitle = AutoItWinGetTitle() Local $x = Random(1248578, 1249780) AutoItWinSetTitle("qwrzu" & $x) Local $x = WinGetHandle("qwrzu" & $x) AutoItWinSetTitle($oldTitle) Return $x EndFunc;==>_AutoItWinGetHandle
  12. Thanks
    rover got a reaction from LeoSS in [Solved] Problem with shutdown.exe on W2K3 x64   
    help file under section: 'Running the 32-bit version of AutoIt on a x64 System'

    DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
  13. Like
    rover got a reaction from moimon in Working example of GetTextColor()/GetBkColor()   
    Get text and background colour from standard controls

    How to retrieve the data you already have...

    Not a very useful thing, as it only works for in-process standard controls, but there you go.


    This example is based on code by Prog@ndy and Malkey in this thread:
    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    Standard Controls do not store colour in their Device Context. (CS_OWNDC)
    Using GetTextColor() on the controls DC returns 0xFFFFFF, (COLOR_WINDOW)
    the default value in the WNDCLASS structure. The parent window sets the colour (CS_PARENTDC)

    By sending a WM_CTLCOLORSTATIC message to the controls parent window.
    we can have it write to a temporary memory DC and then use GetTextColor/GetBkColor.



    The four functions return the RGB colours of visible, hidden or disabled Standard Controls
    on active, inactive, hidden, disabled, locked or minimized AutoIt GUI forms.

    The following form/control classes have been tested in XP/VISTA x86:

    AutoIt v3 GUI, Static (Label), Edit(Edit/Input), Button (Ownerdrawn/Classic Theme PushButton**, Group, Radio, CheckBox), ListBox, ComboBox



    _GuiCtrlGetTextColorEx() - get RGB text colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GuiCtrlGetBkColorEx() - get RGB background colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GUIGetBkColorEx() - get RGB background colour of active, inactive, hidden, locked, disabled or
    minimized in-process* forms. - the only feature this adds over existing forum examples is getting colour from a minimized gui

    _GuiCtrlGetColorEx() - all-in-one testing version with ownerdrawn/themed button testing
    Use the separate functions _GUICtrlGetTextColorEx() and_GUICtrlGetBkColorEx() instead of this


    *This UDF only supports controls in the current script process. It does not work with external process controls.

    Nor does it support controls that are painted on (colour not set by WM_CTLCOLORSTATIC message)
    themed controls or Common Controls (they have their own methods to retrieve colour)

    Does not return transparent layered window attributes, use _WinAPI_GetLayeredWindowAttributes()

    Disabled and/or hidden controls will still return their enabled colours,
    the WM_CTLCOLORSTATIC message does not return the system colours for disabled controls.

    **NOTE: ownerdrawn buttons with no set background color default to the COLOR_BTNFACE system colour,
    but the returned background mode is OPAQUE and the colour is the underlying colour of the parent gui,
    so GetPixel() is required to get the actual colour.

    There will probably be some conditions or OS versions where this code will return incorrect or no colour.


    Other get control colour examples:

    Get GUI Background color? is there such a thing??


    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    GUICtrlGetBkColor() - Get the background color of a control


    Get colour get label colour



    Example:
    Get text, background colour and background mode from four standard controls (visible/hidden/disabled)
    while looping through the following gui states: active, inactive, hidden, minimized, locked and disabled.



    ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include "_GetCtrlColorEx.au3" #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> Opt('MustDeclareVars', 1) Global $aColour, $aStr[4] = ["Edit", "Static 1", "Static 2", "Button "] Global $hGui = GUICreate('Get Control Colours', 230, 200) GUISetBkColor(0xABCDEF) Global $cFst = GUICtrlCreateInput('Edit', 20, 10, 160, 20);, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFF) GUICtrlCreateLabel("Static 1", 20, 45, 160, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) GUICtrlSetColor(-1, 0x191970) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel("Static 2", 20, 80, 160, 20) GUICtrlSetColor(-1, 0xFFE9A9) GUICtrlSetBkColor(-1, 0x6E7B80) GUICtrlCreateButton("Button", 20, 115, 160, 25) ;Ownerdrawn GUICtrlSetColor(-1, 0xFAFAFF) GUICtrlSetBkColor(-1, 0x494949) ;classic theme ;DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", "", "wstr", "") GUISetState() For $i = 0 To 6 Switch $i Case 0 ConsoleWrite("+ ACTIVE ====================" & @CRLF) Case 1 Sleep(1000) ConsoleWrite("+ INACTIVE ==================" & @CRLF) _WinAPI_SetWindowPos($hGui, $HWND_BOTTOM, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Case 2 Sleep(1000) _WinAPI_SetWindowPos($hGui, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Sleep(1000) ConsoleWrite("+ HIDDEN ====================" & @CRLF) GUISetState(@SW_HIDE) Case 3 Sleep(1000) GUISetState(@SW_SHOW) Sleep(1000) ConsoleWrite("+ MINIMIZED ==================" & @CRLF) GUISetState(@SW_MINIMIZE) Case 4 Sleep(1000) GUISetState(@SW_RESTORE) ConsoleWrite("+ LOCKED ======================" & @CRLF) GUISetState(@SW_LOCK) Case 5 Sleep(1000) GUISetState(@SW_UNLOCK) ConsoleWrite("+ DISABLED ====================" & @CRLF) GUISetState(@SW_DISABLE) Sleep(1000) Case 6 GUISetState(@SW_ENABLE) ConsoleWrite("+ CONTROLS HIDDEN/DISABLED =====" & @CRLF) For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_DISABLE) GUICtrlSetState($j, $GUI_HIDE) Next Sleep(1000) EndSwitch For $k = $cFst To ($cFst+3) $aColour = _GUICtrlGetColorEx($k, 1) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & $aColour[0][0] & @CRLF) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & _GUICtrlGetTextColorEx($k, 1) & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & $aColour[1][0] & " - " & $aColour[1][1] & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & _GUICtrlGetBkColorEx($k, 1) & " - Mode: " & @extended & @CRLF & @CRLF) Next ConsoleWrite("> GUI BkGnd Colour: " & _GUIGetBkColorEx($hGui, 1) & @CRLF & @CRLF) Next For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_ENABLE) GUICtrlSetState($j, $GUI_SHOW) Next Do Until GUIGetMsg() = -3 Exit_GetCtrlColorEx.au3
  14. Like
    rover got a reaction from robertocm in Problem with placing child forms on the main form   
    Re: WS_EX_CONTROLPARENT

    Greetings GEOSoft and Melba23

    @MartinGr
    you can prevent a child dialog with WS_EX_CONTROLPARENT style
    from being dragged with a WM_NCHITTEST message handler.


    some background reference to the issue with the WS_EX_CONTROLPARENT style for anyone else reading this post.
    without that style, the child dialog is tabbed as one control.
    see Trac ticket #1115 for the reason this style has the side effect
    of making an AutoIt class child gui draggable.

    Ticket #1115 (closed Bug: No Bug)
    documentation for GuiCreate error
    http://www.autoitscript.com/trac/autoit/ticket/1115


    a modification of GEOSoft's example above
    showing tabbing between controls on all three forms.


    ;#include <WinAPI.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $Frm_Child_1, $Frm_Child_2 _Main() Func _Main() Local $bShow = False, $Msg Local $Frm_Main = GUICreate("Test Form", 300, 500, -1, -1) GUISetBkColor(0x00FF00) GUICtrlCreateButton("Main", 120, 470, 60, 30) $Frm_Child_1 = GUICreate("First Child", 300, 200, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Frm_Main) Local $Btn_Disp = GUICtrlCreateButton("Toggle", 120, 90, 60, 30) GUISetBkColor(0xFF0000) GUISetState(@SW_SHOW, $Frm_Child_1) $Frm_Child_2 = GUICreate("Second Child", 300, 250, 0, 220, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Frm_Main) GUISetBkColor(0x0000FF) GUICtrlCreateButton("Button1", 10, 20, 60, 30) GUICtrlCreateButton("Button2", 80, 20, 60, 30) GUICtrlCreateButton("Button3", 160, 20, 60, 30) GUICtrlCreateButton("Button4", 230, 20, 60, 30) GUIRegisterMsg($WM_NCHITTEST, "_WM_NCHITTEST") ;comment this line, and child forms with WS_EX_CONTROLPARENT style are draggable GUISetState(@SW_SHOW, $Frm_Main) While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit Case $Btn_Disp If $bShow Then GUISetState(@SW_HIDE, $Frm_Child_2) Else GUISetState(@SW_SHOW, $Frm_Child_2) EndIf $bShow = NOT $bShow EndSwitch WEnd EndFunc Func _WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) #forceref $iMsg, $iwParam, $ilParam Switch Number($hWnd) Case Number($Frm_Child_1), Number($Frm_Child_2) ;Local $iCode = _WinAPI_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam) ;If $iCode = 2 Then Return 1 ;Return $iCode Return 1 EndSwitch Return $GUI_RUNDEFMSG EndFunc
  15. Like
    rover got a reaction from Subz in Modify drag&drop behavior for RichEdit text?   
    I've solved the issue with the non-standard text drag and drop behaviour.
    RichEdit text drag and drop operations now work the same as Wordpad with this modification.

    The GetDragDropEffect callback has been modified to determine if the drag and drop operation is within the RichEdit, or between it and another source/destination.

    $pdwEffect in the IRichEditOleCallback::GetDragDropEffect method is returning 3 (DROPEFFECT_COPY + DROPEFFECT_MOVE) for every drag and drop event.

    It should be:
    DROPEFFECT_COPY = 1 for no key or Ctrl key dragging between source and destination. (The drag cursor should have the + box for DROPEFFECT_COPY)
    DROPEFFECT_MOVE = 2 for Alt key dragging between source and destination.
    DROPEFFECT_COPY + DROPEFFECT_MOVE = 3 for dragging text within source RichEdit with no key, Ctrl or Alt key (Key modifiers alter the drag behaviour within the same RichEdit)

    References:

    IRichEditOleCallback::GetDragDropEffect method
    http://msdn.microsoft.com/en-us/library/windows/desktop/bb774319(v=vs.85).aspx
    pdwEffect Type: LPDWORD
    Pointer to the variable that contains the effect used by a rich edit control.
    When fDrag is TRUE, on return, its content is set to the effect allowable by the rich edit control.
    When fDrag is FALSE, on return, the variable is set to the effect to use.

    IDropSource::QueryContinueDrag method
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms690076(v=vs.85).aspx
    grfKeyState [in]: The current state of the keyboard modifier keys on the keyboard.
    Possible values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

    Disclaimer:
    If you are going to try this, please make a backup or use a renamed copy of GuiRichEdit.au3

    Note: As of v3.3.8.0, you need to download the version of GuiRichEdit.au3 in post #7


    Edit: Added additional handle checking, and MouseCoordMode option

    I was getting the odd case where text dragged from Wordpad to an AutoIt RichEdit was cut instead of copied.
    The problem is probably the least reliable area of this code: getting the source and destination handles.
    (and not all draggable text sources/destinations will have readable handles)

    This code just demonstrates the D&D issues.
    The proper fix is probably some COM object magic

    I noticed, memory usage increases with added text, but doesn't decrease when text deleted (occurs without this fix)


    Replacement GetDragDropEffect function and vars for GuiRichEdit.au3


    ;Replace the function and add the vars to GuiRichEdit.au3 Global Const $DROPEFFECT_COPY = 1 Global Const $DROPEFFECT_MOVE = 2 Global Const $MK_ALT = 0x20 Global Const $MK_CONTROL = 0x8 Global $iMode, $hDragSource ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __RichCom_Object_GetDragDropEffect ; Description ...: ; Syntax.........: __RichCom_Object_GetDragDropEffect($pObject, $fDrag, $grfKeyState, $pdwEffect) ; Parameters ....: ; Return values .: ; Author ........: ; Modified.......: rover 2k12 ; Remarks .......: Patch to demonstrate issue with RichEdit defaulting to DROPEFFECT_COPY+DROPEFFECT_MOVE for drag and drop events between source/destination ($pdwEffect value = 3) ; ...............: Drop Effect should change depending on source/destination. Key modifiers should work the same way as Wordpads RichEdit (MS WordPad would be a RichEdit standard I assume?) ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __RichCom_Object_GetDragDropEffect($pObject, $fDrag, $grfKeyState, $pdwEffect) #forceref $pObject, $fDrag, $grfKeyState, $pdwEffect If $fDrag Then ;only sent once at start of drag within same edit or between edits in script process ;TRUE if the query is for a IDropTarget::DragEnter or IDropTarget::DragOver. FALSE if the query is for IDropTarget::Drop. $hDragSource = _WinAPI_GetFocus() ;get drag source handle (only used for comparing to another AutoIt Richedit control) Return $_GCR_E_NOTIMPL EndIf If $grfKeyState = ($MK_CONTROL + $MK_ALT) Then $grfKeyState = 0 ; A Ctrl/Alt key combination does a drag copy between windows, so might as well allow for it. Switch $grfKeyState ;= 0 or key modifier only when mouse released, now we set the drop effect Case 0, $MK_CONTROL, $MK_ALT ;_WinAPI_GetFocus() not working here, always returns source handle of 1st richedit when over 2nd richedit in same gui Local $tDROPEFFECT = DllStructCreate("dword", Ptr($pdwEffect)) Local $tPoint = DllStructCreate($tagPOINT) Local $iOpt = Opt("MouseCoordMode", 1) DllStructSetData($tPoint, "x", MouseGetPos(0)) DllStructSetData($tPoint, "y", MouseGetPos(1)) Opt("MouseCoordMode", $iOpt) Local $hWnd = _WinAPI_WindowFromPoint($tPoint) $iMode = $DROPEFFECT_COPY ;default: $MK_LBUTTON Or $MK_RBUTTON - DD between source/destination If $grfKeyState = $MK_ALT Then $iMode = $DROPEFFECT_MOVE ;DD between source/destination If $hDragSource = $hWnd And (IsHWnd($hDragSource) + IsHWnd($hWnd)) <> 0 Then $iMode = $DROPEFFECT_COPY + $DROPEFFECT_MOVE ;DD within same edit (No key, $MK_ALT or $MK_CONTROL modifier keys) DllStructSetData($tDROPEFFECT, 1, $iMode) $hDragSource = 0 ;reset source handle (not set for a drag from an external process ($fDrag = False )) EndSwitch Return $_GCR_E_NOTIMPL EndFunc ;==>__RichCom_Object_GetDragDropEffect
    Example with restored selected text after drag event


    #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #Include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> #include <WinAPI.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Global $iDLLUser32 = DllOpen("User32.dll"), $hRich1, $hRich2 _DualRichEdit() Func _DualRichEdit() Local $hForm = GUICreate("", 600, 300, -1, -1,-1 ,BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") GUICtrlCreateLabel("First Rich Text Field", 20, 20) GUICtrlCreateLabel("Second Rich Text Field", 300, 20) GUICtrlCreateLabel("Enter text into the first field ... then highlight it and drag/drop it into the second field.", 20, 250, 560, -1) GUICtrlSetFont(-1, 11, 400, -1, "Arial") GUICtrlCreateLabel("I need the dropped text to remain in the first field ... and preferably remain highlighted.", 20, 270, 560, -1) GUICtrlSetFont(-1, 10, 800, -1, "Arial") $hRich1 = _GUICtrlRichEdit_Create($hForm, "", 20, 40, 200, 200, BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL)) _GUICtrlRichEdit_SetEventMask($hRich1, $ENM_DRAGDROPDONE) _GUIScrollBars_ShowScrollBar($hRich1, $SB_VERT, True) ;GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;does not work with UDF controls (-1 only works with native AutoIt controls) $hRich2 = _GUICtrlRichEdit_Create($hForm, "", 300, 40, 200, 200, BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL)) _GUICtrlRichEdit_SetEventMask($hRich2, $ENM_DRAGDROPDONE) _GUIScrollBars_ShowScrollBar($hRich2, $SB_VERT, True) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Sleep(50) WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam) #forceref $hWnd, $iMsg, $iWparam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $iLparam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch __WinAPI_GetClassName($hWndFrom) ;replace with handles, Case $_GRE_sRTFClassName ;if not restoring text selection on multiple richedits Switch $iCode Case $EN_DRAGDROPDONE If $hWndFrom <> _WinAPI_GetFocus() Then ;re-show selected text only on drag beween edits _GUICtrlRichEdit_HideSelection($hWndFrom, False) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func __WinAPI_GetClassName($hWnd) Local $aResult = DllCall($iDLLUser32, "int", "GetClassNameW", "hwnd", $hWnd, "wstr", "", "int", 4096) If @error Then Return "" Return $aResult[2] EndFunc ;==>__WinAPI_GetClassName Func Terminate() _GUICtrlRichEdit_Destroy($hRich1) _GUICtrlRichEdit_Destroy($hRich2) Exit EndFunc
  16. Like
    rover got a reaction from Seminko in Win 7 Display detect   
    C:WindowsSystem32DisplaySwitch.exe

    DisplaySwitch.exe /internal - Switch to Primary only
    DisplaySwitch.exe /external - Switch to Secondary only
    DisplaySwitch.exe /clone - Clone desktop on both screens (Not HDCP compliant!)
    DisplaySwitch.exe /extend - Extend desktop to both screens
  17. Like
    rover got a reaction from Decibel in Working example of GetTextColor()/GetBkColor()   
    Get text and background colour from standard controls

    How to retrieve the data you already have...

    Not a very useful thing, as it only works for in-process standard controls, but there you go.


    This example is based on code by Prog@ndy and Malkey in this thread:
    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    Standard Controls do not store colour in their Device Context. (CS_OWNDC)
    Using GetTextColor() on the controls DC returns 0xFFFFFF, (COLOR_WINDOW)
    the default value in the WNDCLASS structure. The parent window sets the colour (CS_PARENTDC)

    By sending a WM_CTLCOLORSTATIC message to the controls parent window.
    we can have it write to a temporary memory DC and then use GetTextColor/GetBkColor.



    The four functions return the RGB colours of visible, hidden or disabled Standard Controls
    on active, inactive, hidden, disabled, locked or minimized AutoIt GUI forms.

    The following form/control classes have been tested in XP/VISTA x86:

    AutoIt v3 GUI, Static (Label), Edit(Edit/Input), Button (Ownerdrawn/Classic Theme PushButton**, Group, Radio, CheckBox), ListBox, ComboBox



    _GuiCtrlGetTextColorEx() - get RGB text colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GuiCtrlGetBkColorEx() - get RGB background colour of visible/hidden/disabled in-process* controls.
    on an active, inactive, hidden, locked, disabled or minimized gui.

    _GUIGetBkColorEx() - get RGB background colour of active, inactive, hidden, locked, disabled or
    minimized in-process* forms. - the only feature this adds over existing forum examples is getting colour from a minimized gui

    _GuiCtrlGetColorEx() - all-in-one testing version with ownerdrawn/themed button testing
    Use the separate functions _GUICtrlGetTextColorEx() and_GUICtrlGetBkColorEx() instead of this


    *This UDF only supports controls in the current script process. It does not work with external process controls.

    Nor does it support controls that are painted on (colour not set by WM_CTLCOLORSTATIC message)
    themed controls or Common Controls (they have their own methods to retrieve colour)

    Does not return transparent layered window attributes, use _WinAPI_GetLayeredWindowAttributes()

    Disabled and/or hidden controls will still return their enabled colours,
    the WM_CTLCOLORSTATIC message does not return the system colours for disabled controls.

    **NOTE: ownerdrawn buttons with no set background color default to the COLOR_BTNFACE system colour,
    but the returned background mode is OPAQUE and the colour is the underlying colour of the parent gui,
    so GetPixel() is required to get the actual colour.

    There will probably be some conditions or OS versions where this code will return incorrect or no colour.


    Other get control colour examples:

    Get GUI Background color? is there such a thing??


    GUICtrlGetColor()
    ?do=embed' frameborder='0' data-embedContent>

    GUICtrlGetBkColor() - Get the background color of a control


    Get colour get label colour



    Example:
    Get text, background colour and background mode from four standard controls (visible/hidden/disabled)
    while looping through the following gui states: active, inactive, hidden, minimized, locked and disabled.



    ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include "_GetCtrlColorEx.au3" #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> Opt('MustDeclareVars', 1) Global $aColour, $aStr[4] = ["Edit", "Static 1", "Static 2", "Button "] Global $hGui = GUICreate('Get Control Colours', 230, 200) GUISetBkColor(0xABCDEF) Global $cFst = GUICtrlCreateInput('Edit', 20, 10, 160, 20);, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xFAFAFF) GUICtrlCreateLabel("Static 1", 20, 45, 160, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) GUICtrlSetColor(-1, 0x191970) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel("Static 2", 20, 80, 160, 20) GUICtrlSetColor(-1, 0xFFE9A9) GUICtrlSetBkColor(-1, 0x6E7B80) GUICtrlCreateButton("Button", 20, 115, 160, 25) ;Ownerdrawn GUICtrlSetColor(-1, 0xFAFAFF) GUICtrlSetBkColor(-1, 0x494949) ;classic theme ;DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", "", "wstr", "") GUISetState() For $i = 0 To 6 Switch $i Case 0 ConsoleWrite("+ ACTIVE ====================" & @CRLF) Case 1 Sleep(1000) ConsoleWrite("+ INACTIVE ==================" & @CRLF) _WinAPI_SetWindowPos($hGui, $HWND_BOTTOM, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Case 2 Sleep(1000) _WinAPI_SetWindowPos($hGui, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_SHOWWINDOW, $SWP_NOSIZE, $SWP_NOMOVE)) Sleep(1000) ConsoleWrite("+ HIDDEN ====================" & @CRLF) GUISetState(@SW_HIDE) Case 3 Sleep(1000) GUISetState(@SW_SHOW) Sleep(1000) ConsoleWrite("+ MINIMIZED ==================" & @CRLF) GUISetState(@SW_MINIMIZE) Case 4 Sleep(1000) GUISetState(@SW_RESTORE) ConsoleWrite("+ LOCKED ======================" & @CRLF) GUISetState(@SW_LOCK) Case 5 Sleep(1000) GUISetState(@SW_UNLOCK) ConsoleWrite("+ DISABLED ====================" & @CRLF) GUISetState(@SW_DISABLE) Sleep(1000) Case 6 GUISetState(@SW_ENABLE) ConsoleWrite("+ CONTROLS HIDDEN/DISABLED =====" & @CRLF) For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_DISABLE) GUICtrlSetState($j, $GUI_HIDE) Next Sleep(1000) EndSwitch For $k = $cFst To ($cFst+3) $aColour = _GUICtrlGetColorEx($k, 1) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & $aColour[0][0] & @CRLF) ConsoleWrite("+ "&$aStr[$k-$cFst]&" Text Colour: " & _GUICtrlGetTextColorEx($k, 1) & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & $aColour[1][0] & " - " & $aColour[1][1] & @CRLF) ConsoleWrite("- "&$aStr[$k-$cFst]&" BkGnd Colour: " & _GUICtrlGetBkColorEx($k, 1) & " - Mode: " & @extended & @CRLF & @CRLF) Next ConsoleWrite("> GUI BkGnd Colour: " & _GUIGetBkColorEx($hGui, 1) & @CRLF & @CRLF) Next For $j = $cFst To ($cFst+3) GUICtrlSetState($j, $GUI_ENABLE) GUICtrlSetState($j, $GUI_SHOW) Next Do Until GUIGetMsg() = -3 Exit_GetCtrlColorEx.au3
  18. Like
    rover got a reaction from robertocm in How to detect whether a excel file is openned..   
    Hi Rota

    Here's an example of monitoring a file for open handles
    script opens a file with exclusive access and fails if file already open by another application.

    this code wont work with some programs and files that don't seem to keep an open file handle.
    e.g. open a text file with a text editor (TextPad) and _FileInUse() reports no open handles
    works fine with programs like Word and Excel etc.

    Example

    Opt('MustDeclareVars', 1) Local $file = "C:\ABC.XLS" Local $bFileOpen If Not FileExists($file) And ConsoleWrite("!FileExists error: " & $file & @crlf) Then Exit While 1 Sleep(10) $bFileOpen = _FileInUse($file, 1) If $bFileOpen = -1 And ConsoleWrite("!_FileInUse() error" & @crlf & '>Error code: ' & @error & @crlf) Then Exit ConsoleWrite('-FileInUse = ' & ($bFileOpen <> 0) & @crlf & '>Error code: ' & @error & @crlf) If Not $bFileOpen Then ConsoleWrite("! File: "& $file &" is not in use" & @CRLF) Exit EndIf WEnd ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc
  19. Like
    rover got a reaction from AnonymousX in Remove GUI title bar icon   
    Replace the icon with a blank


    $hGUI = GUICreate("No Icon", 300, 200) GUISetIcon(@AutoItExe, -2, $hGUI) GUISetState() Do Until GUIGetMsg() = -3
  20. Like
    rover got a reaction from robertocm in Custom ListView - icons / checkboxes / multiline / edit in place   
    One more thing

    Your timing is good...

    This example is more relevant to your questions regarding the Outlook multiline listview.

    To get two or more fonts per line (in this case normal and bold) DrawText is called twice per line.
    Draw the left most text, set the left rect element to the width of the leftmost text plus a few added pixels to indent, then draw the right most text.

    Text metrics measuring code is needed to replace the hard coded values used for setting left rect and top rect GetStringWidth code added for left rect

    The number of drawtext calls can be cut down by using multiline text with linefeeds,
    but then you can't set indentation and font colour/bold per line

    The example is optimized for speed with dll pseudo handles for dllcalls, stripped down/optimized listview functions and global resources (fonts/pens/brush)
    for re-use in the WM_DRAWITEM message handler

    Edit: added _GUICtrlListView_GetStringWidth
    Edit: corrected ODS_SELECTED multiple item selection, added optional themed/unthemed custom coloured select bar demonstration (try the listview states in Vista/Win7),
    closed theme handle, added themes parts and states usage example, added optional remove line separators when item selection themed, clarified a few things

    Edit: Added combo for Button or *Listview theme parts, Added resize of theme rect for Listview parts
    *Listview group header theme has a better gradient than button in Vista+


    ;coded by rover 2k12 #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> Opt("GUIDataSeparatorChar", "|") Global Const $ODA_SELECT = 0x2 Global Const $ODA_FOCUS = 0x4 Global Const $ODS_SELECTED = 0x0001 Global Const $ODT_LISTVIEW = 102 Global Const $ODA_DRAWENTIRE = 0x1 Global $iDllGDI = DllOpen("gdi32.dll") Global $iDllUSER32 = DllOpen("user32.dll") Global $iDllUxtheme = DllOpen("uxtheme.dll") ;global resources for WM_DRAWITEM - optimize speed Global $aFont[2] $aFont[0] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_HEAVY, False, False, False, _ $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Calibri') $aFont[1] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_MEDIUM, False, False, False, _ $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Calibri') Global $hPen1 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF3EAE7) Global $hPen2 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF4E8E6) Global $hBrush = _WinAPI_CreateSolidBrush(0xEEDDBB) ;Theme Parts and States ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx ;Part - vsstyle.h Global Const $BP_PUSHBUTTON = 1 Global Const $LVP_GROUPHEADER = 6 ;State - vsstyle.h Global Enum $PBS_NORMAL=1,$PBS_HOT,$PBS_PRESSED,$PBS_DISABLED,$PBS_DEFAULTED Global Enum $LVGH_CLOSEHOT=10,$LVGH_CLOSESELECTED,$LVGH_CLOSESELECTEDHOT,$LVGH_CLOSESELECTEDNOTFOCUSED ;this allows you to theme individual items for your own needs, not just if items are selected ;the same as customdrawing item and subitem colours ;XP+ Global $sTheme = 'Button' Global $iThemePart = $BP_PUSHBUTTON Global $iThemeState = $PBS_NORMAL ; Vista+ ;Global $sTheme = 'Listview' ;Global $iThemePart = $LVP_GROUPHEADER ;Global $iThemeState = $LVGH_CLOSEMIXEDSELECTION Global $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme) $hTheme = $hTheme[0] ;global structs for WM_DRAWITEM - optimize speed ;rect, text buffer and LVITEM structures Global $tLVRect = DllStructCreate($tagRECT) Global $tLVText = DllStructCreate("wchar[4096]") Global $tLVITEM = DllStructCreate($tagLVITEM) Global $pLVITEM = DllStructGetPtr($tLVITEM) DllStructSetData($tLVITEM, "TextMax", 4096) DllStructSetData($tLVITEM, "SubItem", 0) DllStructSetData($tLVITEM, "Text", DllStructGetPtr($tLVText)) ; WM_MEASUREITEM allows setting the row height Global $iListView_row_height = 130 Global $hListView ;must be declared before listview created GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;placed here, WM_MEASUREITEM can now be unregistered in the handler (deleting or adding items after unregistering maintains row height setting this way) ; --------------------------------------------------- $hGUI = GUICreate("Ownerdrawn multiline ListView", 324, 425) $cListView = GUICtrlCreateListView("", 2, 2, 320, 268, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS)) $hListView = GUICtrlGetHandle($cListView) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance _GUICtrlListView_AddColumn($hListView, "", 298) Global $aTextHdr[4] = ["From:", "Sent:", "To:", "Subject:"] For $row = 1 To 10 _GUICtrlListView_AddItem($hListView, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _ "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics") Next ;adjust listview size for number of items shown - for efficient painting and to eliminate issue of a click on bottom item causing a jump to next item Local $iY = _GUICtrlListView_ApproximateViewHeight($hListView, _GUICtrlListView_GetCounterPage($hListView)) GUICtrlSetPos($cListView, 2, 2, 320, $iY + 4) Global $cSelect = GUICtrlCreateButton("Themed Select", 2, $iY + 8, 120, 23) Global $cTheme = GUICtrlCreateCombo("Button", 120+2, $iY + 9, 60) GUICtrlSetData(-1, "Listview", "Button") Global $cState = GUICtrlCreateCombo("1 NORMAL", 180+4, $iY + 9, 80) GUICtrlSetData(-1, "2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL") Global $cLabel = GUICtrlCreateLabel("Select Item"&@CRLF&"Style", 260+8, $iY + 8) GUISetState() ; Loop until user exits While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cTheme DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme) Switch GUICtrlRead($cTheme) Case "Button" $sTheme = "Button" $iThemePart = $BP_PUSHBUTTON GUICtrlSetData($cState, "|1 NORMAL|2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL") Case "Listview" $sTheme = "Listview" $iThemePart = $LVP_GROUPHEADER GUICtrlSetData($cState, "|10|11|12|13", "11") EndSwitch $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', GUICtrlRead($cTheme)) $hTheme = $hTheme[0] $iThemeState = Number(StringLeft(GUICtrlRead($cState), 2)) _WinAPI_InvalidateRect($hListView) Case $cState $iThemeState = Number(StringLeft(GUICtrlRead($cState), 2)) _WinAPI_InvalidateRect($hListView) Case $cSelect If Not $hTheme Then GUICtrlSetData($cSelect, "Themed Select") $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme) $hTheme = $hTheme[0] Else GUICtrlSetData($cSelect, "Unthemed Select") DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme) $hTheme = 0 EndIf _WinAPI_InvalidateRect($hListView) EndSwitch WEnd GUIDelete() DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme) _WinAPI_DeleteObject($hPen1) _WinAPI_DeleteObject($hPen2) _WinAPI_DeleteObject($hBrush) For $i = 0 To UBound($aFont) - 1 If $aFont[$i] Then _WinAPI_DeleteObject($aFont[$i]) Next Exit 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 GUIRegisterMsg($WM_MEASUREITEM, "") ; unregister message handler call this after last ownerdrawn listview created - message no longer sent Return 1 EndFunc ;==>WM_MEASUREITEM Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC $tDRAWITEMSTRUCT = DllStructCreate( _ "uint cType;" & _ "uint cID;" & _ "uint itmID;" & _ "uint itmAction;" & _ "uint itmState;" & _ "hwnd hItm;" & _ "handle hDC;" & _ "long itmRect[4];" & _ "ulong_ptr itmData" _ , $lParam) If DllStructGetData($tDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG $cID = DllStructGetData($tDRAWITEMSTRUCT, "cID") $itmID = DllStructGetData($tDRAWITEMSTRUCT, "itmID") $itmAction = DllStructGetData($tDRAWITEMSTRUCT, "itmAction") $itmState = DllStructGetData($tDRAWITEMSTRUCT, "itmState") $hItm = DllStructGetData($tDRAWITEMSTRUCT, "hItm") $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC") Switch $cID ; will look for ControlID, not window handle. Case $cListView Switch $itmAction Case $ODA_DRAWENTIRE __WM_DRAWITEM_ListView($hItm, $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hDC) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Func __WM_DRAWITEM_ListView(ByRef $hLV, ByRef $tDRAWITEMSTRUCT, ByRef $cID, ByRef $itmID, ByRef $itmAction, ByRef $itmState, ByRef $hDC) Local $iTxtCol, $bSelected = BitAND($itmState, $ODS_SELECTED), $iTextFormatting = BitOR($DT_LEFT, $DT_WORDBREAK) If Not $bSelected Then $iTxtCol = 0xB79588 Else ;selected $iTxtCol = 0x494949 ;Theme Parts and States ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx Local $pItemRect = DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect") If $hTheme Then If $sTheme = "Listview" Then Local $tItemRect = DllStructCreate($tagRect, $pItemRect) DllStructSetData($tItemRect, 1, DllStructGetData($tItemRect, 1)+1) DllStructSetData($tItemRect, 2, DllStructGetData($tItemRect, 2)+1) DllStructSetData($tItemRect, 3, DllStructGetData($tItemRect, 3)-1) DllStructSetData($tItemRect, 4, DllStructGetData($tItemRect, 4)-1) $pItemRect = DllStructGetPtr($tItemRect) EndIf DllCall($iDllUxtheme, 'uint', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hDC, 'int', $iThemePart, 'int', $iThemeState, 'ptr', $pItemRect, 'ptr', 0) Else DllCall($iDllUSER32, "int", "FillRect", "handle", $hDC, "ptr", DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), "handle", $hBrush) EndIf EndIf GUICtrlSendMsg($cID, $LVM_GETITEMTEXTW, $itmID, $pLVITEM) Local $aSubItmText = StringSplit(DllStructGetData($tLVText, 1), "|", 2) DllStructSetData($tLVText, 1, "") DllStructSetData($tLVRect, "Top", 0) DllStructSetData($tLVRect, "Left", $LVIR_BOUNDS) GUICtrlSendMsg($cID, $LVM_GETSUBITEMRECT, $itmID, DllStructGetPtr($tLVRect)) Local $iLeft = DllStructGetData($tLVRect, 1) + 6 ;Left Local $iTop = DllStructGetData($tLVRect, 2) ;Top DllStructSetData($tLVRect, 1, $iLeft) ;Left Switch $hLV Case $hListView Local $iColPrev = __WinAPI_SetTextColor($hDC, 0x000000) ;save previous font and text colour Local $hFontOld = __WinAPI_SelectObject($hDC, $aFont[0]) ;Bold ;------------------------------------------------------------ ;multiline, but no per line indentation or colour ;DllStructSetData($tLVRect, 2, $iTop+2) ;__WinAPI_DrawText($hDC, "From:"&@CRLF&"Sent:"&@CRLF&"To:"&@CRLF&"Subject:", $tLVRect, $iTextFormatting) ;------------------------------------------------------------ DllStructSetData($tLVRect, 2, $iTop + 2) __WinAPI_DrawText($hDC, $aTextHdr[0], $tLVRect, $iTextFormatting) DllStructSetData($tLVRect, 2, $iTop + 20) __WinAPI_DrawText($hDC, $aTextHdr[1], $tLVRect, $iTextFormatting) DllStructSetData($tLVRect, 2, $iTop + 38) __WinAPI_DrawText($hDC, $aTextHdr[2], $tLVRect, $iTextFormatting) DllStructSetData($tLVRect, 2, $iTop + 56) __WinAPI_DrawText($hDC, $aTextHdr[3], $tLVRect, $iTextFormatting) __WinAPI_SelectObject($hDC, $aFont[1]) ;Normal ;------------------------------------------------------------ ;multiline, but no per line indentation or colour ;__WinAPI_SetTextColor($hDC, 0x494949) ;DllStructSetData($tLVRect, 1, $iLeft+50) ;DllStructSetData($tLVRect, 2, $iTop+2) ;__WinAPI_DrawText($hDC, $aSubItmText[0]&@CRLF&$aSubItmText[1]&@CRLF&$aSubItmText[2]&@CRLF&$aSubItmText[3], $tLVRect, $iTextFormatting) ;------------------------------------------------------------ __WinAPI_SetTextColor($hDC, 0xFF0000) DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[0]) + 5) DllStructSetData($tLVRect, 2, $iTop + 2) __WinAPI_DrawText($hDC, $aSubItmText[0], $tLVRect, $iTextFormatting) __WinAPI_SetTextColor($hDC, 0x494949) DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[1]) + 5) DllStructSetData($tLVRect, 2, $iTop + 20) __WinAPI_DrawText($hDC, $aSubItmText[1], $tLVRect, $iTextFormatting) DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[2]) + 5) DllStructSetData($tLVRect, 2, $iTop + 38) __WinAPI_DrawText($hDC, $aSubItmText[2], $tLVRect, $iTextFormatting) DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[3]) + 5) DllStructSetData($tLVRect, 2, $iTop + 56) __WinAPI_DrawText($hDC, $aSubItmText[3], $tLVRect, $iTextFormatting) __WinAPI_SetTextColor($hDC, $iTxtCol) DllStructSetData($tLVRect, 1, $iLeft + 2) DllStructSetData($tLVRect, 2, $iTop + 80) __WinAPI_DrawText($hDC, $aSubItmText[4], $tLVRect, $iTextFormatting) If $bSelected And $hTheme Then Return ;optional - don't paint lines when item selected - in this example only for benefit of themed selected items Local $obj_orig = __WinAPI_SelectObject($hDC, $hPen1) __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 2, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 2) __WinAPI_SelectObject($hDC, $hPen2) __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 3, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 3) __WinAPI_SelectObject($hDC, $obj_orig) ;__WinAPI_SelectObject($hDC, $hFontOld) ;__WinAPI_SetTextColor($hDC, $iColPrev) EndSwitch Return EndFunc ;==>__WM_DRAWITEM_ListView Func __WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2) DllCall($iDllGDI, "bool", "MoveToEx", "handle", $hDC, "int", $iX1, "int", $iY1, "ptr", 0) If @error Then Return SetError(@error, @extended, False) DllCall($iDllGDI, "bool", "LineTo", "handle", $hDC, "int", $iX2, "int", $iY2) If @error Then Return SetError(@error, @extended, False) Return True EndFunc ;==>__WinAPI_DrawLine Func __WinAPI_DrawText(ByRef $hDC, $sText, ByRef $tRect, ByRef $iFlags) DllCall($iDllUSER32, "int", "DrawTextW", "hwnd", $hDC, "wstr", $sText, "int", StringLen($sText), "struct*", $tRect, "int", $iFlags) EndFunc ;==>__WinAPI_DrawText Func __WinAPI_SetTextColor($hDC, $iColor) Local $aResult = DllCall($iDllGDI, "INT", "SetTextColor", "handle", $hDC, "dword", $iColor) If @error Then Return SetError(@error, @extended, -1) Return $aResult[0] EndFunc ;==>__WinAPI_SetTextColor Func __WinAPI_SelectObject($hDC, $hGDIObj) Local $aResult = DllCall($iDllGDI, "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc ;==>__WinAPI_SelectObject Func __GUICtrlListView_GetStringWidth($hWnd, $sString) Local $tBuffer = DllStructCreate("wchar Text[" & StringLen($sString) + 1 & "]") DllStructSetData($tBuffer, "Text", $sString) Local $iRet = GUICtrlSendMsg($hWnd, $LVM_GETSTRINGWIDTHW, 0, DllStructGetPtr($tBuffer)) Return $iRet EndFunc ;==>__GUICtrlListView_GetStringWidth
  21. Like
    rover got a reaction from uncommon in Context Menu and TreeView   
    This is the default behaviour of a treeview, no bug

    Right click notifications from the treeview must be hit tested for the item under the mouse
    so the item can be selected.


    #include <GuiConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $MenuParent, $gui, $contextmenu, $i, $n, $textitem, $Tree, $Child Global $Tree, $tNMHDR, $hWndFrom, $iIDFrom, $iCode, $fOnItem = False Main() While 1 Sleep(100) WEnd Func Main() $gui = GUICreate("Treeview Demo", 300, 500, -1, -1) $Tree = GUICtrlCreateTreeView(-1, -1, 300, 500) For $n = 1 to 9 $Parent = GUICtrlCreateTreeViewItem("Parent " & $n,$Tree) For $i = 1 to 3 $Child = GUICtrlCreateTreeViewItem("Child " & $n & "-" & $i,$Parent) contextMenu($Child) Next Next GUISetOnEvent($GUI_EVENT_CLOSE, 'Close') GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) EndFunc Func contextMenu($MenuParent) $contextmenu = GUICtrlCreateContextMenu($MenuParent) $textitem = GUICtrlCreateMenuItem("Delete", $contextmenu) GUICtrlSetOnEvent ( $textitem, "Delete" ) EndFunc Func Delete() ;If $fOnItem Then ;optionally block menu return from right click over non-item area ;$fOnItem = False _GUICtrlTreeView_Delete($Tree, _GUICtrlTreeView_GetSelection ($Tree)) ;EndIf EndFunc Func Close() Exit EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $Tree Switch $iCode Case $NM_RCLICK Local $tPoint = _WinAPI_GetMousePos(True, $hWndFrom), $tHitTest $tHitTest = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2)) ;If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEM) Then ;optionally block menu return from right click over non-item area ;$fOnItem = True Local $hItem = DllStructGetData($tHitTest, 'Item') If IsPtr($hItem) Then _GUICtrlTreeView_SelectItem($hWndFrom, $hItem) EndIf ;EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
  22. Like
    rover got a reaction from meoit in [SOLVED] detect unformatted disk size   
    code from WinAPIEx.au3 example folder
    works in WinPE 2.0


    #Include <WinAPIEx.au3> Opt('MustDeclareVars', 1) Global $tDISK_GEOMETRY_EX, $Drive = 0 While 1 $tDISK_GEOMETRY_EX = _WinAPI_GetDriveGeometryEx($Drive) If @error Then ExitLoop EndIf If Not $Drive Then ConsoleWrite('-------------------------------' & @CR) EndIf ConsoleWrite('Drive: ' & $Drive & @CR) ConsoleWrite('Cylinders: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'Cylinders') & @CR) ConsoleWrite('Tracks per Cylinder: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'TracksPerCylinder') & @CR) ConsoleWrite('Sectors per Track: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'SectorsPerTrack') & @CR) ConsoleWrite('Bytes per Sector: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'BytesPerSector') & ' bytes' & @CR) ConsoleWrite('Total Space: ' & DllStructGetData($tDISK_GEOMETRY_EX, 'DiskSize') & ' bytes' & @CR& @CR) ConsoleWrite('-------------------------------' & @CR) $Drive +=1 WEnd
  23. Like
    rover got a reaction from KristinaA in RichEdit colored text complications.   
    Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor) Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) ; RichEdit stores text as 2 Byte Unicode chars Local $iCp = _GUICtrlRichEdit_GetCharPosOfNextWord($hWnd, $iLength) _GUICtrlRichEdit_AppendText($hWnd, $sText) _GUICtrlRichEdit_SetSel($hWnd, $iCp-1, $iLength + StringLen($sText)) ; position in 2 Byte "Unicode" _GUICtrlRichEdit_SetCharColor($hWnd, $iColor) _GuiCtrlRichEdit_Deselect($hWnd) EndFunc
  24. Like
    rover got a reaction from mLipok in Button & _GUICtrlStatusBar_EmbedControl   
    @psandu.ro _GUICtrlStatusBar_Create() (CreateWindowEx API child window) is not a native AutoIt control, so it does not have its messages
    processed by the MessageLoop or OnEvent mode.
    you have to subclass the StatusBar window to receive messages from any embedded controls
    otherwise you have to read the control directly by control ID (GuiCtrlRead()) or by handle.
    try this example
    Cheers
    Edit replaced first example with code to handle button repaint and resizing
    as there are issues with embedded controls not being repainted or resized with parent gui

    ;the usual paint and resize issues apply with the StatusBar not being native AutoIt code ;Note: if using a resizable gui you need to recalculate StatusBar parts #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiButton.au3> Local $aparts[3] = [80, 160, -1] $hgui = GUICreate("StatusBar Embed Control", 400, 300, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX,$WS_MAXIMIZEBOX)) $button = GUICtrlCreateButton('Ok', 0, 0, 100, 20) $hstatus = _GUICtrlStatusBar_Create($hgui) _GUICtrlStatusBar_SetParts($hstatus, $aparts) _GUICtrlStatusBar_SetText($hstatus, "Part 1") _GUICtrlStatusBar_SetText($hstatus, "Part 2", 1) ;$hBtnStatusBar = _GUICtrlButton_Create($hgui, "Ok", 0, 0, 0, 0) $cBtnStatusBar = GUICtrlCreateButton('Ok', 0, 0) $hBtnStatusBar = GUICtrlGetHandle($cBtnStatusBar) $cBtnDummy = GUICtrlCreateDummy() _GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar) ; subclass StatusBar window: $wProcNew = DllCallbackRegister("_StatusBarWindowProc", "int", "hwnd;uint;wparam;lparam") $wProcOld = _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) GUIRegisterMsg($WM_SIZE, "_WM_SIZE") GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case -3 ;Delete StatusBar window callback function _WinAPI_SetWindowLong($hstatus, $GWL_WNDPROC, $wProcOld) DllCallbackFree($wProcNew) Exit 0 Case $button MsgBox(262144, '', 'Main form button is pressed!') Case $cBtnDummy MsgBox(262144, '', 'StatusBar button is pressed!') EndSwitch WEnd Func _WM_SIZE() _GUICtrlStatusBar_Resize($hstatus) Return $GUI_RUNDEFMSG EndFunc Func _StatusBarWindowProc($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Switch $Msg Case $WM_COMMAND Switch $lParam Case $hBtnStatusBar ;ConsoleWrite('-$nID = ' & $nID & @crlf) ;ConsoleWrite('-$nNotifyCode = ' & $nNotifyCode & @crlf) Switch $nNotifyCode Case $BN_CLICKED GUICtrlSendToDummy($cBtnDummy) ;ConsoleWrite("$BN_CLICKED" & @CRLF) EndSwitch EndSwitch Case $WM_NCPAINT ;update button position when StatusBar repainted (when gui resized or restored from minimized) ;must be better way of doing this _GUICtrlStatusBar_EmbedControl($hstatus, 2, $hBtnStatusBar) EndSwitch ; pass the unhandled messages to default WindowProc Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam) EndFunc ;==>_NewWindowProc
  25. Like
    rover got a reaction from mLipok in _GUICtrlStatusBar_SetText   
    statusbar text colour is a bit more problematic as it requires ownerdrawing and more code
    this example is a modified version of Rasim's demo with ownerdraw code added for statusbar part text and background colour

    Cheers

    to whom it may concern: please refrain from posting this code in the example scripts forum without author attribution.

    Edit Hi Rasim

    ;to whom it may concern: please refrain from posting this code in the example scripts forum with no attribution to the author. ;Author: rover ;Ownerdrawn StatusBar text font and colour demo ;set text colour and font for StatusBar parts ;modified version of demo by Rasim for setting StatusBar font ;http://www.autoitscript.com/forum/index.php?showtopic=88063 #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <FontConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hFont Global $aParts[3] = [125, 250] Global $aPartsText[2] = ["RED on Transparent", "BLUE on Transparent"] Global $hGUI = GUICreate("Statusbar custom font and colour demo", 400, 300) GUISetBkColor(0xE0FFFF) Global $hStatus = _GUICtrlStatusBar_Create($hGUI) _GUICtrlStatusBar_SetParts($hStatus, $aParts) ; add text and color to struct called in WM_DRAWITEM message handler Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000); Red on transparent background Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0); Blue on transparent background ;_GUICtrlStatusBar_SetText($hStatus, "", 0, $SBT_OWNERDRAW); text not set when ownerdrawn ;_GUICtrlStatusBar_SetText($hStatus, "", 1, $SBT_OWNERDRAW) _GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS") GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM") GUISetState() Sleep(3000) ;you can use the above _GUICtrlStatusBar_SetText() lines and set text and colour in the message handler ;or use _GUICtrlStatusBar_SetColor() to change text, text colour and part background colour more easily Local $iCnt = 0 Do $iCnt +=1 $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, "GOLD on BLACK", 0, 0xFFD700, 0) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, "BLUE on GOLD", 1, 0x0C0DC0, 0xFFD700) Sleep(500) $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0) Sleep(500) Until $iCnt = 5 Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") ;Author: Rasim $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;" & _ "uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) Local $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm"); retrieve statusbar handle Switch _WinAPI_GetClassName($hItm);an example of how message handler does not have to rely on having global variable for statusbar in advance ;Switch $hItm Case "msctls_statusbar32" ;Case $hStatus Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC") ; device context for statusbar for color and/or font Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID"); statusbar part number ; get 32-bit value in itmData when text has SBT_OWNERDRAW drawing type - pointer to struct with text and color Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData") Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam) ; create RECT structure from itmRect byte array for part metrics Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") ; metrics not same as non-ownerdrawn part for some reason, so 1 added for alignment DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)+1) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)+1) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) _WinAPI_SetBkMode($hDC, $TRANSPARENT); otherwise text background set to 0xFFFFFF _WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2)); set part text colour from struct If Not DllStructGetData($tParam, 4) Then; check if background should be transparent Local $iBkColor = DllStructGetData($tParam, 3), $hStatusDC, $hBrushBk $hStatusDC = _WinAPI_GetDC($hItm) $hBrushBk = _WinAPI_CreateSolidBrush($iBkColor) _WinAPI_FillRect($hStatusDC, DllStructGetPtr($tRect), $hBrushBk) _WinAPI_DeleteObject($hBrushBk) _WinAPI_ReleaseDC($hItm, $hStatusDC) EndIf ; draw text to DC (can also use gdi32 TextOutW and ExtTextOut API's) _WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRect, $DT_LEFT) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1) ;Author: rover - modified ownerdraw version of _GUICtrlStatusBar_SetText() from GuiStatusBar.au3 ;Includes RGB2BGR() - Author: Siao - http://www.autoitscript.com/forum/index.php?s=&showtopic=57161&view=findpost&p=433593 ;sets itmData element of statusbar DRAWITEMSTRUCT with pointer to struct with text and colour for part number If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd) Local $ret, $tStruct, $pStruct, $iBuffer ; In Microsoft Windows XP and earlier, the text for each part is limited to 127 characters. ; This limitation has been removed in Windows Vista. ; set sufficiently large buffer for use with Vista (can exceed XP limit of 128 chars) $tStruct = DllStructCreate("wchar Text[512];dword Color;dword BkColor;dword Trans") Switch $iBkColor Case -1 DllStructSetData($tStruct, "Trans", 1) Case Else $iBkColor = BitAND(BitShift(String(Binary($iBkColor)), 8), 0xFFFFFF) DllStructSetData($tStruct, "Trans", 0) DllStructSetData($tStruct, "BkColor", $iBkColor) EndSwitch $iColor = BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF); From RGB2BGR() Author: Siao DllStructSetData($tStruct, "Text", $sText) DllStructSetData($tStruct, "Color", $iColor) $pStruct = DllStructGetPtr($tStruct) If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID ;FOR INTERNAL STATUSBARS ONLY If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then $ret = _SendMessage($hWnd, $SB_SETTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr") Return $tStruct; returns struct to global variable EndIf Return 0 EndFunc ;==>_GUICtrlStatusBar_SetColor
×
×
  • Create New...