 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
aw1ace
Joined: 14 May 2008 Posts: 11
|
Posted: Wed May 21, 2008 5:16 pm Post subject: |
|
|
@ Tekl
| Quote: | | So I have to use LV_ColorInitiate instead of LVX_Setup? |
Yes,
LV_ColorInitiate(LvVar, Color=255, Gui_Number=1, Control="")
Just delcare this line after the gui%#%, show
| Quote: | | Can I call it for the same Control more than one time or how do I specify to wich ListView (I want to use more than one) the LVX_SetColour is send? |
Example:
For Default GUI and LV:
LV_ColorInitiate("MyListViewVar", 0xebf02f)
For #1 GUI:
LV_ColorInitiate("MyListViewVar", 0xebf02f, 1, "WhateverControl")
For #2 GUI:
LV_ColorInitiate("MyListViewVar", 0xebf02f, 2, "WhateverControl") _________________ -Ace |
|
| Back to top |
|
 |
Tekl
Joined: 24 Sep 2004 Posts: 814 Location: Germany
|
Posted: Wed May 21, 2008 5:18 pm Post subject: |
|
|
And I can mix it up?
After Changing Gui 1 and 2 I want to change Gui 1 again. _________________ Tekl |
|
| Back to top |
|
 |
aw1ace
Joined: 14 May 2008 Posts: 11
|
Posted: Wed May 21, 2008 5:21 pm Post subject: |
|
|
@ Tekl
Sorry, I have not tested swapping back and forth from GUI. I do not see that being a problem, as I said, as long as WM_Nofity is updating there should not be an issue. Just try calling the LV_ColorInitiate after each gui, show ? _________________ -Ace |
|
| Back to top |
|
 |
Tekl
Joined: 24 Sep 2004 Posts: 814 Location: Germany
|
Posted: Wed May 21, 2008 5:22 pm Post subject: |
|
|
Ok, I'll try it. With the original code it is not working even with one GUI and calling the LVX_Setup twice. _________________ Tekl |
|
| Back to top |
|
 |
aw1ace
Joined: 14 May 2008 Posts: 11
|
Posted: Wed May 21, 2008 5:29 pm Post subject: |
|
|
@ Tekl
Actually, All you need to do is call
LV_ColorInitiate(0xebf02f)
I am not sure why I had the listview var in there, only need to specify control if using a different one. I re-copied an updated code below.
| Code: | /*
HiLite - Ace
*Enable onClick Highlighting and Scroll Highlighting
*Made for the Listviews without altsubmit as there is no "Normal" events fired
Remarks:
LV_ColorInitiate( HiLite_Color) - is to be added in your startup to initialize Highlighting
*Use Color in Hex format, Example Call - LV_ColorInitiate(0xebf02f)
Buffer - Set number of lines visible above or below highlighted line while scrolling
*Default value = 1
Call MouseDown() and MouseUp() in your WheelUp/WheelDown Hotkeys or whatever you want to make the ListView Scroll with
-----Do Not need to add but can enhance preformance-----
-----I used -0x8 because of click+drag ablitiy on my listview----
#MaxHotkeysPerInterval - Set this or the Scroll hotkeys will trigger Interval Errors
-0x8 - Add this to listview , will disable Listview highlighting, this is needed if you have g_label for listview and want other events fired
*/
LV_ColorInitiate(Color=255, Gui_Number=1, Control="") { ; initiatize listview color change procedure, Default HiLite_Color = Blue (255) BGR
Global
HiLite_Color := Color
If !Control
Control = SysListView321
Gui, %Gui_Number%:+Lastfound
Gui_ID := WinExist()
ControlGet, hw_LVX_HiLite, HWND,, %Control%, Ahk_ID %Gui_ID%
OnMessage( 0x4E, "WM_NOTIFY" )
}
MouseDown(Buffer=1) {
Global
DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max) ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
If !ScrollPos ; Set ScrollPos to 1 if empty, this is used inplace of lv_getnext()
ScrollPos = 1
If ScrollPos > %max% ; Ensure that LvX function does not draw in row that doest not exist and error out
Return
ScrollPos++ ; Increment Scrolldown position by 1
LV_Modify(ScrollPos + Buffer, "+vis") ; Add buffer to bottom of highlighted text - Increase "Buffer" to add more lines
LVX_SetColour(ScrollPos, HiLite_Color) ; Highlights current selected row, ScrollPos, Background_Color
Return
}
MouseUp(Buffer=1) {
Global
DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max) ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
min+=1 ; Set min = to 1 or LvX function tries to draw on line 0 and errors out
If ScrollPos < %min% or !ScrollPos ; Ensure that LvX function does not draw at row 0 and error
Return
ScrollPos-- ; DeIncrement Scrolldown position by 1
LV_Modify(ScrollPos - Buffer, "+vis") ; Add buffer to Top of highlighted text - Incraese "Buffer" to add more lines
LVX_SetColour(ScrollPos, HiLite_Color) ; Highlights current selected row, ScrollPos, Background_Color
Return
}
WM_NOTIFY( p_w, p_l, p_m ) {
Global
Critical
Current_Line := NumGet(p_l + 36)+1 ; Get Current Selected Row
If ( DllCall("GetFocus") = hw_LVX_HiLite ) { ; Control has Keyboard Focus?
SendMessage, 4140, Current_Line-1, 2, , Ahk_ID %hw_LVX_HiLite% ; LVM_GETITEMSTATE
If ( ErrorLevel = 2 ) { ; LVIS_SELECTED
NumPut(0x2, p_l + 16) ; LVITEM->stateMask ; LVIS_SELECTED
SendMessage, 4139, Current_Line-1, p_l, , Ahk_ID %hw_LVX_HiLite% ; Disable Highlighting
ScrollPos := Current_Line ; Set Clicked Highlighted line = scrollposition
LVX_SetColour(Current_Line, HiLite_Color) ; Color Current_Line + Background +Text color is available but not sent in this case
Return, 0x00000010 ; CDRF_NOTIFYPOSTPAINT
}
}
If (NumGet(p_l + 0) == NumGet(lvx))
Return, LVX_Notify(p_w, p_l, p_m)
}
/* Function: LVX_Notify
Handler for WM_NOTIFY events on ListView controls. Do not use this function.
*/
LVX_Notify(p_w, p_l, p_m) {
Global lvx
If (NumGet(p_l + 0) == NumGet(lvx) and NumGet(p_l + 8, 0, "Int") == -12) {
st := NumGet(p_l + 12)
If st = 1
Return, 0x20
Else If (st == 0x10001) {
a := NumGet(p_l + 36) * 9 + 9
If NumGet(lvx, a)
NumPut(NumGet(lvx, a - 4), p_l + 48), NumPut(NumGet(lvx, a), p_l + 52)
}
}
}
/* Function: LVX_SetColour
Set the background and/or text colour of a specific row on a ListView control.
Parameters:
index - row index (1-based)
back - (optional) background row colour, must be hex code in RGB format (default: 0xffffff)
text - (optional) similar to above, except for font colour (default: 0x000000)
Remarks:
Sorting will not affect coloured rows.
*/
LVX_SetColour(Index, HiLite=255, Text="") {
Global lvx, hw_LVX_HiLite
LVX_SetEditHotkeys() ; Enable Default Hotkeys
SendMessage,4100,0,0, ,Ahk_ID %hw_LVX_HiLite% ; Get Total Number of rows for highlighting VarCapacity
VarSetCapacity(lvx, 4 + ErrorLevel * 9, 0) ; Total rows is needed when capacity is initialized so all rows can be drawn on
NumPut(hw_LVX_HiLite + 0, lvx)
A := (Index - 1) * 9 + 5
If Text
NumPut(LVX_RevBGR(Text) + 0, lvx, A)
NumPut(LVX_RevBGR(HiLite) + 0, lvx, A + 4)
WinSet, Redraw, ,Ahk_ID %hw_LVX_HiLite%
}
/* Function: LVX_RevBGR
Helper function for internal use. Converts RGB to BGR.
Parameters:
i - BGR hex code
*/
LVX_RevBGR(i) {
Return, (i & 0xff) << 16 | (i & 0xffff) >> 8 << 8 | i >> 16
}
/* Function: LVX_SetEditHotkeys
Change accept/cancel hotkeys in cell editing mode.
Parameters:
enter - comma seperated list of hotkey names/modifiers that will save
the current input text and close editing mode
esc - same as above but will ignore text entry (i.e. to cancel)
Remarks:
The default hotkeys are Enter and Esc (Escape) respectively,
and such will be used if either parameter is blank or omitted.
*/
LVX_SetEditHotkeys(enter = "Enter,NumpadEnter", esc = "Esc") {
Global lvx, lvxb
Static h1, h0
If (enter == ~1) {
If esc > 0
{
lvxb = 0
Hotkey, IfWinNotActive, Ahk_ID %esc%
}
Loop, Parse, h1, `,
Hotkey, %A_LoopField%, _lvxb
Loop, Parse, h0, `,
Hotkey, %A_LoopField%, _lvxc
Hotkey, IfWinActive
Return
}
If !enter
h1 = %enter%
If !esc
h0 = %esc%
}
_lvxc: ; these labels are for internal use:
lvxb++
_lvxb:
lvxb++
LVX_SetEditHotkeys(~1, -1)
Return
;----------------------------------------------------------------------------------
;LvX - Titan
; License:
; o Version 1.04 by Titan <http://www.autohotkey.net/~Titan/#lvx>
; o zlib License <http://www.autohotkey.net/~Titan/zlib.txt>
; http://www.autohotkey.com/forum/topic26541.html&highlight=lvx |
_________________ -Ace |
|
| Back to top |
|
 |
hughman
Joined: 11 Feb 2007 Posts: 92
|
Posted: Mon Apr 13, 2009 2:35 pm Post subject: |
|
|
Below is my code, why the background color can't not be changed?
In fact , I wrote anothor code which is almost the same as this one, but can work. I have not found out the reason.
| Code: |
Gui, +lastfound +AlwaysOnTop
Gui, Add, ListView, x5 w200 h400 Grid AltSubmit Checked v_lvItems, a|b|c|d
Gui, Show, x810 W210 NoActivate
LVX_Setup(_lvItems)
Loop, Read, list.txt
{
_aPatient3 =
StringSplit, _aPatient, A_LoopReadLine, %A_Tab%
LV_Add("-Check", A_Index, _aPatient3, _aPatient1, _aPatient2)
;If !( Mod( A_Index, 2 ) )
; LVX_SetColour(A_Index, 0xF3F7FA, 0x000000)
}
Loop, 4
LV_ModifyCol(A_Index, "AutoHdr Center")
Loop, % LV_GetCount()
{
If !( Mod( A_Index, 2 ) )
LVX_SetColour(A_Index, 0xF3F7FA, 0x000000)
}
#Include lib\LVX.ahk
|
|
|
| Back to top |
|
 |
aw1ace
Joined: 14 May 2008 Posts: 11
|
Posted: Mon Apr 13, 2009 4:19 pm Post subject: |
|
|
I tested your code and found two issues:
1. 0xF3F7FA changed to 0xff8000 Not sure what color 0xF3F7FA is??
2. LVX_Setup(_lvItems) changed to LVX_Setup("_lvItems")
Below works fine:
| Quote: |
Gui, +lastfound +AlwaysOnTop
Gui, Add, ListView, x5 w200 h400 Grid AltSubmit Checked v_lvItems, a|b|c|d
Gui, Show, x810 W210 NoActivate
LVX_Setup("_lvItems")
Loop, Read, list.txt
{
_aPatient3 =
StringSplit, _aPatient, A_LoopReadLine, %A_Tab%
LV_Add("-Check", A_Index, _aPatient3, _aPatient1, _aPatient2)
;If !( Mod( A_Index, 2 ) )
; LVX_SetColour(A_Index, 0xF3F7FA, 0x000000)
}
Loop, 4
LV_ModifyCol(A_Index, "AutoHdr Center")
Loop, % LV_GetCount()
{
If !( Mod( A_Index, 2 ) )
LVX_SetColour(A_Index, 0xff8000, 0xffff00)
}
#Include lib\LVX.ahk |
_________________ -Ace |
|
| Back to top |
|
 |
ribbs2521
Joined: 28 Sep 2007 Posts: 225 Location: New York
|
Posted: Mon Apr 13, 2009 11:02 pm Post subject: |
|
|
| First off, thanks for this code, I use it all of the time. I was wondering if there is a way to color different cells in the same line different colors. Is there a way I could color the first five cells of a row only so I could keep the rest the original white background? |
|
| Back to top |
|
 |
hughman
Joined: 11 Feb 2007 Posts: 92
|
Posted: Tue Apr 14, 2009 2:43 am Post subject: |
|
|
| aw1ace wrote: | I tested your code and found two issues:
1. 0xF3F7FA changed to 0xff8000 Not sure what color 0xF3F7FA is??
2. LVX_Setup(_lvItems) changed to LVX_Setup("_lvItems")
|
Ops~~~ thank u |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Apr 17, 2009 12:31 pm Post subject: |
|
|
| ribbs2521 wrote: | | First off, thanks for this code, I use it all of the time. I was wondering if there is a way to color different cells in the same line different colors. Is there a way I could color the first five cells of a row only so I could keep the rest the original white background? |
this might be it: lva cell coloring |
|
| Back to top |
|
 |
jchristl
Joined: 13 Jan 2006 Posts: 29
|
Posted: Fri Jul 03, 2009 1:22 pm Post subject: Strange placement |
|
|
first of all this code is awesome, and is something I wish was implemented into the autohotkey code directly.
Here is my code. Ultimately I'd like this to allow multilpe rows of numbers be added, changed or deleted, and then passed back into another gui, as comma separated numbers.
For some reason when I double click, it puts the edit box down below.
| Code: |
LVX_Setup("MyListView")
BoxJobList:
Gui, Add, Button, x106 y27 w40 h20 , New
Gui, Add, Button, x146 y27 w40 h20 , Del
Gui, Add, Text, x35 y26 w40 h20 , Numbers:
Gui, Add, ListView, x36 y50 w153 r15 gMyListView grid -Hdr vMyListView,
Gui, Add, Button, x27 y332 w75 h23 , OK
Gui, Add, Button, x125 y332 w75 h23 , Cancel
Gui, Show, x521 y300 h371 w233, New GUI Window
Return
GuiEscape:
ButtonCancel:
GuiClose:
Gui, Destroy
ExitApp
Return
ButtonOK:
Gui, submit ; Populates variables from Gui
Gui, Destroy
ExitApp
Return
MyListView:
if A_GuiEvent = DoubleClick
{
LVX_CellEdit()
}
Return
ButtonNew:
LV_Add("",vMyListView)
Return
ButtonDel:
Return
#Include LVX.ahk
|
Anyone know what is wrong? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|