Sign in to follow this  
Followers 0

GUIListViewSysLink UDF!


18 posts in this topic

Posted (edited)

Hi!

This whole concept belongs to rasim, and the idea of SysLink control inside ListView belongs to ptrex! He proposed it, and i thought that this will be a good challenge/practic for me! :P

Here we go...

#CS
    Name:               GUIListViewSysLink.au3
    Description:        Functions to set Hyperlink (via SysLink control) for ListView items.
    Author:             G.Sandler (a.k.a MrCreatoR), initial concept idea by R.Gilman (a.k.a rasim), this UDF idea by ptrex!
    AutoIt version:     3.2.12.1 - 3.3.8.1
    UDF version:        1.2
#CE

Example:

#include "GUIListViewSysLink.au3"

$hGUI = GUICreate("ListView with SysLink Control!", 420, 530, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))

$hListView1 = GUICtrlCreateListView("Files|Path|Links", 10, 10, 400, 240, BitOR($LVS_REPORT, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlCreateListViewItem("AutoIT|C:\Program Files\AutoIt3", $hListView1)
GUICtrlCreateListViewItem("Opera|C:\Program Files\Opera", $hListView1)
GUICtrlCreateListViewItem("Script|C:\MyScripts", $hListView1)

$nSysLinkBkColor = 0xC0C0C0
$nSysLinkStockObject = $LTGRAY_BRUSH

$hListView2 = GUICtrlCreateListView("Name|Links", 10, 270, 400, 240, BitOR($LVS_REPORT, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlCreateListViewItem("Some Name", $hListView2)

$hSysLink1  = _GUICtrlListView_SysLinkCreate($hListView1, "AutoIt Script Home Page", "http://autoitscript.com", 0, 2)
_GUICtrlListView_SysLinkSetFont(-1, "Tahoma", 9.5)

$hSysLink2  = _GUICtrlListView_SysLinkCreate($hListView1, "Opera Home Page", "http://opera.com", 1, 2)
_GUICtrlListView_SysLinkSetFont(-1, "Tahoma", 9.5)

$hSysLink3  = _GUICtrlListView_SysLinkCreate($hListView1, "My Scripts Home Page?", "http://creator-lab.ucoz.ru", 2, 2)
_GUICtrlListView_SysLinkSetFont(-1, "Tahoma", 9.5)

$hSysLink1_2  = _GUICtrlListView_SysLinkCreate($hListView2, "Some other Home Page", "http://creator-lab.ucoz.ru", 0, 1)
_GUICtrlListView_SysLinkSetFont(-1, "Arial", 10.5)

GUICtrlSetBkColor($hListView1, $nSysLinkBkColor)
GUICtrlSetBkColor($hListView2, $nSysLinkBkColor)

GUICtrlSendMsg($hListView1, $LVM_SETCOLUMNWIDTH, 0, 80)
GUICtrlSendMsg($hListView1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg($hListView1, $LVM_SETCOLUMNWIDTH, 2, 120)

GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 0, 230)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 1, 115)

;Here we add ID to the $hSysLink1
_GUICtrlListView_SysLinkSetLinkInfo($hSysLink1, "http://autoitscript.com", "AutoIt")

;And now we check if it was added :)
$aInfo = _GUICtrlListView_SysLinkGetLinkInfo($hSysLink1)
$sInfo = StringFormat("Info For $hSysLink1:\n\nSysLink State\t\t= %i\nURL\t\t\t= %s\nID\t\t\t= %s\nParent ListView Handle\t= %s", _
    $aInfo[1], $aInfo[2], $aInfo[3], $aInfo[4])

ConsoleWrite($sInfo)

GUISetState(@SW_SHOW, $hGUI)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

The UDF and this example attached bellow.

P.S

Feedbacks and bug reports are always welcome!

GUIListViewSysLink_1.2.zip

ListView_SysLink_1.1.zip

ListView_SysLink_1.0.zip

Test Version (with Label control):

ListView_Link_TestVersion.zip

History version:

v1.2 [13.01.2013]

* AutoIt 3.3.8.1 compatibility.

* UDF renamed to GUIListViewSysLink.au3.

* Fixed issue when clicking on link does not executed properly.

* Fixed an issue with wrong SysLink control position set after resizing.

If "Display window content when draging" is disabled in Performance options, resizing was wrong.

v1.1 [21.10.2008]

+ Added handler to activate the main window when SysLink control is focused.

This handler also set hot cursor ($OCR_NO) while user trying to drag the SysLink control.

+ Added 2 more functions:

_GUICtrlListView_SysLinkSetLinkInfo() - Sets link information.

_GUICtrlListView_SysLinkGetLinkInfo() - Gets link information.

+ Added WM_CTLCOLORSTATIC registration to set bk color for the SysLink control.

(To change the color just set $nSysLinkBkColor variable to desired color).

* Rewrited parameters for the _GUICtrlListView_SysLinkCreate() function...

* $sTextFormat splitted into different 3 parameters: $sTitle, $sLink and $iLnkID.

* Added $iFillItemText - Allows to fill item text (SysLink text),

so the LV item will have the same text as SysLink control. Default is 1.

* Fixed inactive GUI window after executing url.

v1.0 [10.10.2008]

* First release.

Enjoy! Posted Image

Edited by MrCreatoR

Share this post


Link to post
Share on other sites



Posted

MrCreatoR

Good work. Thank you! :P

Share this post


Link to post
Share on other sites

Posted

Very Nice! Thanks!

Share this post


Link to post
Share on other sites

Posted

@MrCreatoR

This is realy perfect.

Great job !! :P

Thanks again.

Regards,

ptrex

Share this post


Link to post
Share on other sites

Posted

Good work here... a suggestion I'd make is to get the back ground color of the listview and paint the background color of the CreateWindowEx the same :(... You two seem to feed of each other well :P .

Share this post


Link to post
Share on other sites

Posted

@SmOke_N

I am just kicking the ball, it is MrCreatoR and ProgAndy who is scoring here !! :P

Anyhow this is a very nice addition to the standard listView.

Regards,

ptrex

Share this post


Link to post
Share on other sites

Posted

@SmOke_N

I am just kicking the ball, it is MrCreatoR and ProgAndy who is scoring here !! :P

Anyhow this is a very nice addition to the standard listView.

Regards,

ptrex

I was speaking of Rasim :( ... Both have produced some nice Listview alternatives/options. That's who I was referring to by feeding well off of one another (I mistyped in my other post, I put "Feed of" rather than "Feed off").

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks for the feedbacks!

@SmOke_N

a suggestion I'd make is to get the back ground color of the listview and paint the background color of the CreateWindowEx the same

Actualy i tried that, i spent on this issue more time than on building the UDF itself :(

How to set background color for window created with _WinAPI_CreateWindowEx() ?

And what is the best way to get Background color of ListView control?

This one not working:

$hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hLV)
$hDC = $hDC[0]

$nColor = DllCall("GDI32.dll", "int", "GetBkColor", "hwnd", $hDC)

It returns FFFFFF (white) always :P

Edited by MrCreatoR

Share this post


Link to post
Share on other sites

Posted

For setting the bg color, experiment with the WM_CTLCOLOR* messages. I don't know which one, if any, that a syslink control sends though. Here's the msdn -

http://msdn.microsoft.com/en-us/library/bb432504(VS.85).aspx

I don't see a call on 32 bit system for SysLink control ...

Thanks for the feedbacks!

@SmOke_N

Actualy i tried that, i spent on this issue more time than on building the UDF itself :(

How to set background color for window created with _WinAPI_CreateWindowEx() ?

And what is the best way to get Background color of ListView control?

This one not working:

$hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hLV)
$hDC = $hDC[0]

$nColor = DllCall("GDI32.dll", "int", "GetBkColor", "hwnd", $hDC)

It returns FFFFFF (white) always :P

This is a similar issue I had here: http://www.autoitscript.com/forum/index.php?showtopic=65802

I reformatted it a bit using wraithdu's and googles suggestion: http://cboard.cprogramming.com/archive/ind...hp/t-91110.html :

Func _GUISetSysLinkBkColor($h_parent, $h_wnd, $i_color = 0xFFFFFF)
	Local Const $GCL__HBRBACKGROUND	 = -10
	Local Const $RDW__ERASE			 = 0x04
	Local Const $RDW__INVALIDATE		= 0x01
	Local Const $RDW__ALLCHILDREN	   = 0x080
	Local Const $RDW__UPDATENOW		 = 0x100
	Local Const $WM__CTLCOLORSTATIC	 = 0x00138

	Local $i_color_bgr = _
						BitOR(BitShift(BitAND($i_color, 0x000000FF), 16), _
						BitAND($i_color, 0x0000FF00), _
						BitShift(BitAND($i_color, 0x00FF0000),16))
						
	Local $h_dc = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hSysLink1)
	If @error Then Return SetError(1, 0, 0)
	
	Local $h_sm = DllCall("User32.dll", "hwnd", "SendMessage", "hwnd", $h_parent, "uint", $WM__CTLCOLORSTATIC, "wparam", $h_dc[0], "lparam", $h_wnd)
	If @error Then Return SetError(2, 0, 0)
	
	Local $i_scl = DllCall("User32.dll", "int", "SetClassLongA", "hwnd", $h_wnd, "int", $GCL__HBRBACKGROUND, "dword", $h_sm[0])
	If @error Then Return SetError(3, 0, 0)
	
	DllCall("User32.dll", "int", "DeleteObject", "long", $i_scl[0])
	DllCall("User32.dll", "int", "InvalidateRect", "hwnd", $h_wnd, "int", 0, "int", 1)
	DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $h_wnd, "int", 0, "int", 0, "uint", _
				BitOR($RDW__ERASE, $RDW__INVALIDATE, $RDW__ALLCHILDREN, $RDW__UPDATENOW))
	DllCall("User32.dll", "int", "UpdateWindow", "hwnd", $h_wnd)
	DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $h_wnd, "hwnd", $h_dc[0])
	Return 1
EndFunc
But still the same issue :idea: ... I'll be curious to see this be accomplished for more than one reason obviously :) ...

Share this post


Link to post
Share on other sites

Posted

I spent 2 more hours (or maybe more) on this, this function has suffered a lot from me :P But no luck either :)

In the end(?) i came up with two workarounds:

1) Change the background color of ListView control :( - Not so preferable.

2) Instead of SysLink control use standard labels on top of new GUI (as framework), and handle the clicks with some timer function.

For the first one just add this to the top of _GUICtrlListView_SysLinkCreate function:

	Local $nBkColor = _WinAPI_GetSysColor($COLOR_3DFACE)
	GUICtrlSetBkColor($hWnd, $nBkColor)

(before «If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)»).

About the second one, later i will post test-version (to see if it's good enough :idea: ).

Share this post


Link to post
Share on other sites

Posted

UDF updated!

History:

; v1.0 [10.10.2008, 02:20]

; First release.

;

; v1.1 [21.10.2008, 00:03]

; - Added handler to activate the main window when SysLink control is focused.

; This handler also set hot cursor ($OCR_NO) while user trying to drag the SysLink control.

;

; - Added 2 more functions:

; _GUICtrlListView_SysLinkSetLinkInfo() - Sets link information.

; _GUICtrlListView_SysLinkGetLinkInfo() - Gets link information.

;

; - Added WM_CTLCOLORSTATIC registration to set bk color for the SysLink control.

; (To change the color just set $nSysLinkBkColor variable to desired color).

;

; - Rewrited parameters for the _GUICtrlListView_SysLinkCreate() function...

; * $sTextFormat splitted into different 3 parameters: $sTitle, $sLink and $iLnkID.

; * Added $iFillItemText - Allows to fill item text (SysLink text),

; so the LV item will have the same text as SysLink control. Default is 1.

;

; - Fixed inactive GUI window after executing url.

I also added mentioned before Test version (with Label control), please see first post.

Share this post


Link to post
Share on other sites

Posted

hummm getting in 3.3.6.1 an error message :unsure:

C:\Program Files\AutoIt3\Include\_ListView_SysLink.au3(59,31) : ERROR: $HDN_FIRST previously declared as a 'Const'

Global Const $HDN_FIRST = -300

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\~\test3.au3 - 1 error(s), 0 warning(s)

maybe u can do something whit it :>

i don't ;)

Share this post


Link to post
Share on other sites

Posted (edited)

Delete the line with the error message, it's already been declared in one of the other included files, HeaderConstants.au3 in this case.

EDIT:typo

Edited by BrewManNH

Share this post


Link to post
Share on other sites

Posted

This is awesome and it helped me to create a link for my tool... but if i click on the link nothing happens how to make work ?

Share this post


Link to post
Share on other sites

Posted

Update (after 4 years! :lmao: ):

v1.2 [13.01.2013]

* AutoIt 3.3.8.1 compatibility.

* UDF renamed to GUIListViewSysLink.au3.

* Fixed issue when clicking on link does not executed properly.

* Fixed an issue with wrong SysLink control position set after resizing.

If "Display window content when draging" is disabled in Performance options, resizing was wrong.

Share this post


Link to post
Share on other sites

Posted

Hello MrCreatoR,

I recently found your solution for the hyperlinks for listviews and found it really helpfull. I almost got my Autoit applicaton running however stumbled over a problem I have difficulties to resolve. It might be quite trivial for you and hopefully you can help. I am using your GUIListViewSysLink code to actually show hyperlinks in a listview which have prior been extracted from a text file. Hence the string containing the address (in my case it will be a file path) will need to be stored assigned to a variabel first and then will need to be handed over to your function. Here is the line of code where the problem starts:

...

_GUICtrlListView_SysLinkCreate($listview, "Update", $link, $i-1, 4)

...

Here the $link variable contains a simple string such as "C:tempupdate.bat". and it really needs to be a variable to allow changing hyperlinks. When executing my code I don't get a hyperlink in the corresponding column but rather something like:
<a href="C:tempupdate.bat""

I might have forgotton some other parameters. Could you help me out here? I hope the info I provided is sufficient.

Would really appreciate your help.

Regards,

hudehade

Share this post


Link to post
Share on other sites

Posted

When executing my code I don't get a hyperlink in the corresponding column but rather something like:

<a href="C:tempupdate.bat""

 

Hi,

I have tested the issue with variable, and it's working fine:

$sLink = 'c:\test.txt'
$hSysLink  = _GUICtrlListView_SysLinkCreate($hListView, "Update", $sLink, 0, 1)

Perhaps something wrong with the index values, can you show me the full code? Or a part with the ListView and UDF called in a loop?

Share this post


Link to post
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
Sign in to follow this  
Followers 0