Ich habe mich mal noch etwas mehr damit beschäftigt und speziell ging es mir um die Möglichkeit die Farben der Links zu ändern, sodass man auch einen dunklen Hintergrund benutzen kann.
Ich habe mal ein Beispielscript erstellt, bei dem statt der Callback-Routine nur GuiRegisterMsg verwendet wird (ist für Anfänger vielleicht einfacher zu verstehen):
AutoIt
#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 <WinAPISysInternals.au3>
#include <WindowsConstants.au3>
; This example works in 32bit and 64bit mode (n/y)
#AutoIt3Wrapper_UseX64=y
; 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 ***
#Region *** Example gui and syslink control ***
Opt('GUIOnEventMode', 1) ; Enable OnEventMode
Global Const $g_iBkColor = 0x303030, $g_iTxtColor = 0xE0E0E0
Global $g_hMainGui = GUICreate('Syslink example 2023/02/01', 640, 220)
GUISetBkColor($g_iBkColor, $g_hMainGui)
GUISetOnEvent($GUI_EVENT_CLOSE, '_CloseMainGui')
; create the text including the links (as in HTML)
Global $g_sText = 'This example was created by Oscar (autoit.de).' & @CRLF & @CRLF & _
'AutoIt © 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>'
; create syslink control
Global $g_hSyslink = _WinAPI_CreateWindowEx(0, $WC_LINK, $g_sText, _
BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $LWS_TRANSPARENT, $LWS_USECUSTOMTEXT), _
20, 10, 620, 200, $g_hMainGui)
; create desired font
Global $g_hFont = _WinAPI_CreateFont(32, 0, 0, 0, $FW_SEMIBOLD, True, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, 0, 'Times New Roman')
; and send the font to the syslink control
_SendMessage($g_hSyslink, $WM_SETFONT, $g_hFont, True)
GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
GUISetState(@SW_SHOW, $g_hMainGui)
WinWaitClose($g_hMainGui) ; wait until the main window is closed
Exit
#EndRegion *** Example gui and syslink control ***
Func _CloseMainGui()
_WinAPI_DeleteObject($g_hFont) ; delete font
_WinAPI_DestroyWindow($g_hSyslink) ; destroy syslink control
GUIDelete($g_hMainGui) ; close the main window (leads to exit)
EndFunc ;==>_CloseMainGui
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
Switch $tNMHDR.hWndFrom ; which Control send the message?
Case $g_hSyslink ; when syslink control
Switch $tNMHDR.Code ; which code?
Case $NM_CLICK, $NM_RETURN ; mouseclick or <RETURN> on a link
Local $tNMLINK = DllStructCreate($tagNMLINK, $lParam)
ShellExecute($tNMLINK.szURL)
Case $NM_CUSTOMTEXT ; only works if "$LWS_USECUSTOMTEXT" is present at the syslink style!
Local $tNMCUSTOMTEXT = DllStructCreate($tagNMCUSTOMTEXT, $lParam)
If $tNMCUSTOMTEXT.nCount > 0 Then ; if the text length is greater than 0
If $tNMCUSTOMTEXT.fLink Then ; if it is a link
Local $tSyslink = DllStructCreate('wchar text[' & $tNMCUSTOMTEXT.nCount & ']', $tNMCUSTOMTEXT.lpString)
Switch $tSyslink.text ; set different colors depending on the link (BGR format)
Case 'www.autoitscript.com'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x4444FF)
Case 'autoit.de'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x44FF00)
Case 'autoit.de/onlinehilfe'
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0xFFEE22)
Case Else
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, 0x44FFFF)
EndSwitch
Else ; if no link, then it is the caption
_WinAPI_SetTextColor($tNMCUSTOMTEXT.hDC, _WinAPI_SwitchColor($g_iTxtColor))
EndIf
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
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
Screenshot: