Two listbox questions

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Two listbox questions

Post by Phil Pendlebury » Wed Nov 18, 2020 12:49 pm

1. Is there any way to preselect multiple items in a list? I found an article from many years ago which did not seem to apply to now (using libfunction). (Note Listbox is already set to Multiselect).

Example, does not work.

Code: Select all

SetDialogProperty>Dialog1,MSListBox1,text,PHIL%CRLF%PETE%CRLF%MARCUS
SetDialogProperty>Dialog1,MSListBox1,SelectedItems,%PETE%CRLF%MARCUS
2. is there any way to show custom hint when hovering over an item in a list box.
Imagine I have the full path stored in an index, and the list box shows only the file but when I hover over the file I can show the full path.

I tried the various HINT properties but they all seem to apply only to the list box itself.

Note that at the moment I am using OnDblClick to show the full path but of course this deselects all selected items.

Cheers, P.
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Two listbox questions

Post by JRL » Thu Nov 19, 2020 4:48 pm

Phil,
Rewrote the old listbox preselect script to work with the version 12+ Dialogs.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Pre-Multiselect ListBox Example'
  ClientHeight = 350
  ClientWidth = 211
  Position = poScreenCenter
  object MSListBox1: tMSListBox
    Left = 45
    Top = 30
    Width = 121
    Height = 291
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 0
    SelectedIndex = -1
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
SetDialogProperty>Dialog1,MSListBox1,Text,item1%CRLF%item2%CRLF%item3%CRLF%item4%CRLF%item5%CRLF%item6%CRLF%item7%CRLF%item8%CRLF%item9%CRLF%item10%CRLF%item11%CRLF%item12%CRLF%item13%CRLF%item14
show>dialog1
Let>LB_SETSEL=389
//Run the following for each pre-chosen 0 based item selection
//The last number is the one to change 0 = the first item,
//3 = the fourth item, 5 = the sixth item, etc.
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,0
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,3
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,5
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,11
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,12
Label>Loop
  Wait>0.01
Goto>Loop

SRT>Quit
  Exit>0
END>Quit
For the hint issue you might try using the Listbox events. Here's a sample that just puts the displayed text in a dialog. Its a little flakey but it is just a possible example.

Code: Select all

Dialog>Dialog2
object Dialog2: TForm
  BorderStyle = bsNone
  Caption = 'CustomHint'
  ClientHeight = 29
  ClientWidth = 723
  object Label1: TLabel
    Left = 5
    Top = 8
    Width = 32
    Height = 13
    Caption = ''
  end
end
EndDialog>Dialog2


Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Pre-Multiselect ListBox Example'
  ClientHeight = 350
  ClientWidth = 211
  Position = poScreenCenter
  object MSListBox1: tMSListBox
    Left = 45
    Top = 30
    Width = 121
    Height = 291
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 0
    SelectedIndex = -1
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSListBox1,OnMouseEnter,srtHint
AddDialogHandler>Dialog1,MSListBox1,OnMouseLeave,srtHintOff
AddDialogHandler>Dialog1,,OnClose,Quit
SetDialogProperty>Dialog1,MSListBox1,Text,item1%CRLF%item2%CRLF%item3%CRLF%item4%CRLF%item5%CRLF%item6%CRLF%item7%CRLF%item8%CRLF%item9%CRLF%item10%CRLF%item11%CRLF%item12%CRLF%item13%CRLF%item14
show>dialog1
Let>LB_SETSEL=389
//Run the following for each pre-chosen 0 based item selection
//The last number is the one to change 0 = the first item,
//3 = the fourth item, 5 = the sixth item, etc.
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,0
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,3
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,5
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,11
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,12

GetTextInit

Label>Loop
  Wait>0.01
  If>getTextFlag=1
    GetCursorPos>Xpos,Ypos
    GetTextAtPoint>Xpos,Ypos,vStr,vStrPos
    MoveWindow>CustomHint,Xpos,Ypos
    Wait>0.7
    SetDialogProperty>Dialog2,Label1,Caption,vStr
    Wait>3
  EndIf
Goto>Loop

SRT>Quit
  Exit>0
END>Quit

SRT>srtHint
  Let>getTextFlag=1
  Show>Dialog2
END>srtHint

SRT>srtHintOff
  getTextFlag=0
  CloseDialog>Dialog2
END>srtHintOff

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Two listbox questions

Post by Phil Pendlebury » Fri Nov 20, 2020 4:42 pm

Hi JRL, Super kind of you to take the time to do that thanks.

I'll update this thread when I put in action with any further comments.

Thanks again, P
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Two listbox questions

Post by Phil Pendlebury » Fri Nov 20, 2020 4:50 pm

OK first observation, as you say the hints are flakey :-) but not only that, some kind of memory leak happened after closing the script.

Macro Scheduler application came up with error that system was out of resources after some time. I am not sure which part of the script is causing this but will attempt to narrow it down.

I'll keep trying though thanks again. :-)
Phil Pendlebury - Linktree

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts