Ich versuche mich gerade an der farbigen Darstellung bei dem Syslink-Control.
Dazu muss man das WC_LINK-Window mit $LWS_USECUSTOMTEXT aufrufen. Soweit funktioniert das auch. Es wird auch in der Window-Proc unter $WM_NOTIFY das $NM_CUSTOMTEXT aufgerufen.
Aber irgendwie wird die Struktur falsch zurückgegeben.
Laut MSDN soll die Struktur so aussehen:
typedef struct tagNMCUSTOMTEXT {
NMHDR hdr;
HDC hDC;
LPCWSTR lpString;
int nCount;
LPRECT lpRect;
UINT uFormat;
BOOL fLink;
} NMCUSTOMTEXT, *LPNMCUSTOMTEXT;
Ich habe daraus dieses hier für AutoIt gemacht:
Global Const $tagNMCUSTOMTEXT = 'struct;' & $tagNMHDR & ';handle hDC;ptr lpString;int nCount;' & $tagRECT & ';uint uFormat;bool fLink;endstruct'
Das funktioniert auch, bis auf die letzten beiden Werte. Bei "uFormat" kommt immer "0" oder "1" raus, was eigentlich bei "fLink" stehen sollte und "fLink" bekommt Zufallswerte (bei jedem Start etwas anderes, was wohl darauf hindeutet, dass über die Struktur hinaus gelesen wird). Habe ich bei der Struktur-Definition einen Fehler gemacht? Oder woran kann das liegen?
Hier mal mein Script (edit: korrigiertes Script)
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StructureConstants.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIGdiInternals.au3>
#include <WinAPIHObj.au3>
#include <WinAPIInternals.au3>
#include <WinAPIShellEx.au3>
#include <WinAPISysInternals.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; This function ensures that the common control DLL (Comctl32.dll) is loaded,
; and registers ICC_LINK_CLASS from the DLL.
; Minimum supported client: Windows Vista
If Not _WinAPI_Init_ICC_LINK_CLASS() Then Exit
#Region *** Structs and Constants for the Syslink-Control ***
; The LITEM struct used to set and retrieve information about a link item.
Global Const $tagLITEM = 'struct;uint mask;int iLink;uint state;uint stateMask;wchar szID[48];wchar szURL[2083];endstruct'
; The NMLINK struct contains notification information. Send this structure with the NM_CLICK or NM_RETURN messages.
Global Const $tagNMLINK = 'struct;' & $tagNMHDR & ';' & $tagLITEM & ';endstruct'
; The NMCUSTOMTEXT struct contains information used with custom text notification.
Global Const $tagNMCUSTOMTEXT = 'struct;' & $tagNMHDR & ';handle hDC;ptr lpString;int nCount;ptr lpRect;uint uFormat;bool fLink;endstruct'
Global Const $NM_CUSTOMTEXT = $NM_FIRST - 24 ; Notifies a control's parent window about custom text operations. This notification code is sent in the form of a WM_NOTIFY message.
Global Const $LM_HITTEST = $WM_USER + 0x300 ; Determines whether the user clicked the specified link.
Global Const $LM_GETIDEALHEIGHT = $WM_USER + 0x301 ; Retrieves the preferred height of a link for the control's current width.
Global Const $LM_GETIDEALSIZE = $LM_GETIDEALHEIGHT ; Retrieves the preferred height of a link for the control's current width.
Global Const $LM_SETITEM = $WM_USER + 0x302 ; Sets the states and attributes of an item.
Global Const $LM_GETITEM = $WM_USER + 0x303 ; Retrieves the states and attributes of an item.
Global Const $LIF_ITEMINDEX = 0x00000001 ; Retrieve the numeric item index. Items are always accessed by index, therefore you must always set this flag and assign a value to iLink. To obtain the item ID you must set both LIF_ITEMINDEX and LIF_ITEMID.
Global Const $LIF_STATE = 0x00000002 ; Use stateMask to get or set the state of the link.
Global Const $LIF_ITEMID = 0x00000004 ; Specify the item by the ID value given in szID.
Global Const $LIF_URL = 0x00000008 ; Set or get the URL for this item.
Global Const $LIS_FOCUSED = 0x00000001 ; The link has the keyboard focus. Pressing ENTER sends an NM_CLICK notification.
Global Const $LIS_ENABLED = 0x00000002 ; The link can respond to user input. This is the default unless the entire control was created with WS_DISABLED. In this case, all links are disabled.
Global Const $LIS_VISITED = 0x00000004 ; The link has been visited by the user. Changing the URL to one that has not been visited causes this flag to be cleared.
Global Const $LIS_HOTTRACK = 0x00000008 ; Indicates that the syslink control will highlight in a different color (COLOR_HIGHLIGHT) when the mouse hovers over the control.
Global Const $LIS_DEFAULTCOLORS = 0x00000010 ; Enable custom text colors to be used.
Global Const $LWS_TRANSPARENT = 0x0001 ; The background mix mode is transparent.
Global Const $LWS_IGNORERETURN = 0x0002 ; When the link has keyboard focus and the user presses Enter, the keystroke is ignored by the control and passed to the host dialog box.
Global Const $LWS_NOPREFIX = 0x0004 ; Windows Vista. If the text contains an ampersand, it is treated as a literal character rather than the prefix to a shortcut key.
Global Const $LWS_USEVISUALSTYLE = 0x0008 ; Windows Vista. The link is displayed in the current visual style.
Global Const $LWS_USECUSTOMTEXT = 0x0010 ; Windows Vista. An NM_CUSTOMTEXT notification is sent when the control is drawn, so that the application can supply text dynamically.
Global Const $LWS_RIGHT = 0x0020 ; Windows Vista. The text is right-justified.
#EndRegion *** Structs and Constants for the Syslink-Control ***
Opt('GUIOnEventMode', 1)
Global Const $g_iBkColor = 0xFFFFFF, $g_iTxtColor = 0404040
Global $g_hMainGui = GUICreate('Syslink example', 640, 300)
GUISetBkColor($g_iBkColor, $g_hMainGui)
GUISetOnEvent($GUI_EVENT_CLOSE, '_CloseMainGui')
Global $g_sText = 'AutoIt' & @CRLF & _
'© 1999-2022 Jonathan Bennett' & @CRLF & _
'Homepage: <a href="https://www.autoitscript.com/site/autoit/">www.autoitscript.com</a>' & @CRLF & _
'Homepage deutsch: <a href="https://autoit.de/wcf/">autoit.de</a>' & @CRLF & _
'Onlinehilfe deutsch: <a href="https://autoit.de/onlinehilfe/online/html/index.htm">autoit.de/onlinehilfe</a>'
Global $g_hSyslink = _WinAPI_CreateWindowEx(0, $WC_LINK, $g_sText, _
BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $LWS_TRANSPARENT, $LWS_USECUSTOMTEXT), _
10, 10, 620, 200, $g_hMainGui)
Global $g_hFont = _WinAPI_CreateFont(32, 0, 0, 0, 400, True, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, 0, 'Verdana')
_SendMessage($g_hSyslink, $WM_SETFONT, $g_hFont, True)
Global $g_hSyslinkProc = DllCallbackRegister('_SyslinkProc', 'lresult', _
'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
Global $g_pSyslinkProc = DllCallbackGetPtr($g_hSyslinkProc)
_WinAPI_SetWindowSubclass($g_hMainGui, $g_pSyslinkProc, 1000, 0)
Global $g_idClose = GUICtrlCreateButton('Close', 240, 230, 120, 30)
GUICtrlSetFont(-1, 14, 400, 0, 'Verdana')
GUICtrlSetOnEvent(-1, '_CloseMainGui')
GUICtrlSetState(-1, $GUI_FOCUS)
GUISetState(@SW_SHOW, $g_hMainGui)
WinWaitClose($g_hMainGui)
DllCallbackFree($g_hSyslinkProc)
Exit
Func _CloseMainGui()
_WinAPI_RemoveWindowSubclass($g_hMainGui, $g_pSyslinkProc, 1000)
_WinAPI_DeleteObject($g_hFont)
_WinAPI_DestroyWindow($g_hSyslink)
GUIDelete($g_hMainGui)
EndFunc ;==>_CloseMainGui
Func _SyslinkProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
#forceref $iID, $pData
Switch $iMsg
Case $WM_CTLCOLORSTATIC ; Farben beim Syslink festlegen
; $lParam = Static-hWnd, $wParam = Static-hDC
; Textfarbe fuer die Schrift (im BGR-Format)
_WinAPI_SetTextColor($wParam, _WinAPI_SwitchColor($g_iTxtColor))
Return 0
Case $WM_NOTIFY
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Switch $tNMHDR.Code
Case $NM_CLICK, $NM_RETURN ; Mausklick oder <RETURN> auf einen Link
Local $tNMLINK = DllStructCreate($tagNMLINK, $lParam)
ShellExecute($tNMLINK.szURL)
Case $NM_CUSTOMTEXT ; funktioniert nur, wenn beim Syslink-Style "$LWS_USECUSTOMTEXT" vorhanden ist!
Local $tNMCUSTOMTEXT = DllStructCreate($tagNMCUSTOMTEXT, $lParam)
If $tNMCUSTOMTEXT.nCount > 0 Then ; nur wenn die Textlaenge groesser 0 ist
If $tNMCUSTOMTEXT.fLink Then ; und es sich um einen Link handelt
Local $tSyslink = DllStructCreate('wchar text[' & $tNMCUSTOMTEXT.nCount & ']', $tNMCUSTOMTEXT.lpString)
Switch $tSyslink.text ; je nach Link unterschiedliche Farben setzen (im BGR-Format)
Case 'www.autoitscript.com'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x4444BB)
Case 'autoit.de'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x44BB00)
Case 'autoit.de/onlinehilfe'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0xBB4444)
Case Else
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x44BBBB)
EndSwitch
EndIf
EndIf
EndSwitch
EndSwitch
Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_SyslinkProc
Func _Syslink_SetItem($hSyslink, $iIndex, $iState = -1, $sUrl = '')
If Not IsHWnd($hSyslink) Then Return SetError(1, 0, False)
Local $tLITEM = DllStructCreate($tagLITEM), $ret
$tLITEM.mask = BitOR($LIF_ITEMINDEX, ($iState > -1 ? $LIF_STATE : 0), ($sUrl <> '' ? $LIF_URL : 0))
$tLITEM.iLink = $iIndex
If $iState > -1 Then
$tLITEM.state = $iState
$tLITEM.stateMask = $iState
EndIf
If $sUrl <> '' Then $tLITEM.szURL = $sUrl
$ret = _SendMessage($hSyslink, $LM_SETITEM, 0, DllStructGetPtr($tLITEM))
Return $ret <> 0
EndFunc ;==>_Syslink_SetItem
Func _WinAPI_Init_ICC_LINK_CLASS()
Local Const $tagINITCOMMONCONTROLSEX = 'struct;dword dwSize;dword dwICC;endstruct;'
Local Const $ICC_LINK_CLASS = 0x00008000
Local $tINITCOMMONCONTROLSEX = DllStructCreate($tagINITCOMMONCONTROLSEX)
$tINITCOMMONCONTROLSEX.dwSize = DllStructGetSize($tINITCOMMONCONTROLSEX)
$tINITCOMMONCONTROLSEX.dwICC = $ICC_LINK_CLASS
Local $aResult = DllCall('comctl32', 'bool', 'InitCommonControlsEx', 'ptr', DllStructGetPtr($tINITCOMMONCONTROLSEX))
Return $aResult[0] == 1
EndFunc ;==>_WinAPI_Init_ICC_LINK_CLASS
Alles anzeigen