Jump to content

ContextHelp


rasim
 Share

Recommended Posts

Hi All! Hope this UDF someday be useful for yours greats scripts :)

Posted Image

UDF:

#include-once
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $HH_DISPLAY_TEXT_POPUP = 0xE
Global Const $HH_CLOSE_ALL = 0x12

Global $HH_POPUP
Global $DllHandle = DllOpen("HHCtrl.ocx")

Global $aControls[1] = [0]
Global $aText[1] = [0]
Global $aTextColor[1] = [0]
Global $aBkColor[1] = [0]
Global $aFontFormat[1] = [0]

$HH_POPUP = DllStructCreate("int cbStruct;hwnd hinst;uint idString;ptr pszText;long pt[2];dword clrForeground;" & _
                            "dword clrBackground;long rcMargins[4];ptr pszFont")

DllStructSetData($HH_POPUP, "cbStruct", DllStructGetSize($HH_POPUP))
DllStructSetData($HH_POPUP, "idString", 0)
DllStructSetData($HH_POPUP, "rcMargins", -1, 1)
DllStructSetData($HH_POPUP, "rcMargins", -1, 2)
DllStructSetData($HH_POPUP, "rcMargins", -1, 3)
DllStructSetData($HH_POPUP, "rcMargins", -1, 4)

GUIRegisterMsg($WM_HELP, "WM_HELP")

; #FUNCTION# =============================================================
; Name............: _ContextHelp_SetText
; Description.....: Sets context help text for control
; Syntax..........: _ContextHelp_SetText($hControl, $sText)
; Parameter(s)....: $hControl - Handle or ID to the control
;                   $sText    - Text which be showed
; Return value(s).: Success - None
;                   Failure - Sets @error to 1
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Tested on Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_SetText($hControl, $sText)
    If Not $hControl Then Return SetError(1, 0, 0)
    If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl)
    
    Local $iElement = _CheckControl($hControl)
    $aText[$iElement] = $sText
EndFunc   ;==>_ContextHelp_SetText

; #FUNCTION# =============================================================
; Name............: _ContextHelp_SetTextColor
; Description.....: Sets color for context help text
; Syntax..........: _ContextHelp_SetTextColor($hControl, $sTextColor)
; Parameter(s)....: $hControl   - Handle or ID to the control
;                   $sTextColor - Color in HEX value
; Return value(s).: Success - None
;                   Failure - Sets @error to 1
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Tested on Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_SetTextColor($hControl, $sTextColor)
    If Not $hControl Then Return SetError(1, 0, 0)
    If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl)
    
    Local $iElement = _CheckControl($hControl)
    $aTextColor[$iElement] = RGB2BGR($sTextColor)
EndFunc   ;==>_ContextHelp_SetTextColor

; #FUNCTION# =============================================================
; Name............: _ContextHelp_SetBkColor
; Description.....: Sets the background color for a context help window
; Syntax..........: _ContextHelp_SetBkColor($hControl, $sBkColor)
; Parameter(s)....: $hControl   - Handle or ID to the control
;                   $sBkColor   - Color in HEX value
; Return value(s).: Success - None
;                   Failure - Sets @error to 1
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Tested on Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_SetBkColor($hControl, $sBkColor)
    If Not $hControl Then Return SetError(1, 0, 0)
    If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl)
    
    Local $iElement = _CheckControl($hControl)
    $aBkColor[$iElement] = RGB2BGR($sBkColor)
EndFunc   ;==>_ContextHelp_SetBkColor

; #FUNCTION# =============================================================
; Name............: _ContextHelp_SetFont
; Description.....: Sets the font, font size and font attributes for a context help text
; Syntax..........: _ContextHelp_SetFont($hControl, $sFontName [, $sFontSize = 8.5 [, $sFontFormat = "NORMAL"]]])
; Parameter(s)....: $hControl    - Handle or ID to the control
;                   $sFontName   - The name of the font
;                   $sFontSize   - [optional] Font size (default is 8.5)
;                   $sFontFormat - [optional] Font attributes e.g.: BOLD, ITALIC, UNDERLINED
;                   +you can use a several font attributes, just indicate theirs via space
; Return value(s).: Success - None
;                   Failure - Sets @error to 1
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Tested on Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_SetFont($hControl, $sFontName, $sFontSize = 8.5, $sFontFormat = "NORMAL")
    If Not $hControl Then Return SetError(1, 0, 0)
    If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl)
    
    Local $iElement = _CheckControl($hControl)
    $aFontFormat[$iElement] = $sFontName & ", " & $sFontSize & ", , " & $sFontFormat
EndFunc   ;==>_ContextHelp_SetFont

; #FUNCTION# =============================================================
; Name............: _CheckControl
; Description.....: Finds the control handle in the array contains a controls handles
; Syntax..........: _CheckControl($hControl)
; Parameter(s)....: $hControl - Handle to the control
; Return value(s).: Last element number from the array contains a controls handles
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Only for internal use
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _CheckControl($hControl)
    Local $i
    If $aControls[0] = 0 Then
        Return _ContextHelp_Create($hControl)
    EndIf
    
    For $i = 1 To $aControls[0]
        If $hControl = $aControls[$i] Then
            Return $i
        EndIf
    Next
    
    Return _ContextHelp_Create($hControl)
EndFunc   ;==>_CheckControl

; #FUNCTION# =============================================================
; Name............: _ContextHelp_Create
; Description.....: Redims arrays with parameters and sets default parameters
; Syntax..........: _ContextHelp_Create($hControl)
; Parameter(s)....: $hControl - Handle to the control
; Return value(s).: Last element number from the array contains a controls handles
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Only for internal use
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_Create($hControl)
    $aControls[0] += 1
    ReDim $aControls[$aControls[0] + 1]
    $aControls[$aControls[0]] = $hControl
    
    $aText[0] += 1
    ReDim $aText[$aText[0] + 1]
    $aText[$aText[0]] = "What's that?"
    
    $aTextColor[0] += 1
    ReDim $aTextColor[$aTextColor[0] + 1]
    $aTextColor[$aTextColor[0]] = -1
    
    $aBkColor[0] += 1
    ReDim $aBkColor[$aBkColor[0] + 1]
    $aBkColor[$aBkColor[0]] = -1
    
    $aFontFormat[0] += 1
    ReDim $aFontFormat[$aFontFormat[0] + 1]
    $aFontFormat[$aFontFormat[0]] = "MS Sans Serif, 8.5, , NORMAL"
    
    Return $aControls[0]
EndFunc   ;==>_ContextHelp_Create

; #FUNCTION# =============================================================
; Name............: _ContextHelp_Popup
; Description.....: Displaying a context help for controls
; Syntax..........: _ContextHelp_Popup()
; Parameter(s)....: None
; Return value(s).: None
; Requirement(s)..: AutoIt 3.2.12.0
; Note(s).........: Only for internal use
; Author(s).......: R.Gilman (a.k.a. rasim)
; ========================================================================
Func _ContextHelp_Popup()
    DllCall($DllHandle, "hwnd", "HtmlHelp", "hwnd", 0, "str", 0, _
            "int", $HH_DISPLAY_TEXT_POPUP, "dword", DllStructGetPtr($HH_POPUP))
EndFunc   ;==>_ContextHelp_Popup

; #FUNCTION# =============================================================
; Name............: RGB2BGR
; Description.....: Convert a RGB color mode to a BGR color mode
; Syntax..........: RGB2BGR($sColor)
; Parameter(s)....: $sColor - The color in HEX value
; Return value(s).: Converted color in HEX value
; Requirement(s)..: 
; Note(s).........: 
; Author(s).......: Siao
; ========================================================================
Func RGB2BGR($sColor)
    Return BitAND(BitShift(String(Binary($sColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR

Func WM_HELP($hWnd, $Msg, $wParam, $lParam)
    Local $HELPINFO, $hControl, $tFont, $tText, $i
    
    $HELPINFO = DllStructCreate("int cbSize;int iContextType;int iCtrlId;hwnd hItemHandle;" & _
                                "dword dwContextId;long MousePos[2]", $lParam)
    
    $hControl = DllStructGetData($HELPINFO, "hItemHandle")
    
    $tFont = DllStructCreate("char Font[256]")
    $tText = DllStructCreate("char Text[256]")
    
    For $i = 1 To $aControls[0]
        If $hControl = $aControls[$i] Then
            DllStructSetData($tText, "Text", $aText[$i])
            DllStructSetData($tFont, "Font", $aFontFormat[$i])
            
            DllStructSetData($HH_POPUP, "pszText", DllStructGetPtr($tText))
            DllStructSetData($HH_POPUP, "pszFont", DllStructGetPtr($tFont))
            
            DllStructSetData($HH_POPUP, "clrForeground", $aTextColor[$i])
            DllStructSetData($HH_POPUP, "clrBackground", $aBkColor[$i])
            
            DllStructSetData($HH_POPUP, "pt", DllStructGetData($HELPINFO, "MousePos", 1), 1)
            DllStructSetData($HH_POPUP, "pt", DllStructGetData($HELPINFO, "MousePos", 2), 2)
            
            _ContextHelp_Popup()
        EndIf
    Next
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HELP

Func OnAutoitExit()
    DllCall($DllHandle, "hwnd", "HtmlHelp", "hwnd", 0, "str", 0, "uint", $HH_CLOSE_ALL, "dword", 0)
    $HH_POPUP = 0
    DllClose($DllHandle)
EndFunc   ;==>OnAutoitExitoÝ÷ ÙÊ%¢ºç¬¥©ì·)^

Note:

Works correctly in the AutoIt latest version 3.2.12.0

Link to comment
Share on other sites

@rasim

You are accessing a COM dll using DLLCall ?

Mightbe going the long way.

Try this.

$Hh = ObjCreate("Internet.HHCtrl")
$Hh.TextPopup ("Test it, working" & @CrLf & _
"AU3 is great ...", "Lucida Console,8", 1, 1, 1, 1)
Sleep (3000)
$Hh.TextPopup ("Hello Script-Coding!" & @CrLf & _
"HH Ctrl", "Courier New,36", 1, 1, 1, 1)
Sleep (3000) 
$Hh = ""

Regards,

ptrex

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...