forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


VDS Table wizardry

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Jan 19, 2004 12:02 pm    Post subject: VDS Table wizardry Reply with quote

I just wanted to compliment CodeScript yet again, this time for his VDS Table element control package. I have found some very useful stuff in there.

I love the ability to drag and drop columns of the table. I'm wondering if anyone has figured out a way to save the order so that it can be restored the next time an app is run?

I wrote a unit to save and restore the column widths, and also to ensure a particular line in a table is visible (such as when adding an item to the end of the table.)

Code:
# Unit to save and restore TABLE element column widths
#DEFINE COMMAND,SaveColumnWidths
#DEFINE COMMAND,RestoreColumnWidths
#DEFINE COMMAND,EnsureVisible
:savecolumnwidths
  rem SAVECOLUMNWIDTHS tbTable, %%numcolumns
  if %1
    if @winexists(~%1)
      %N = 0
      repeat
        # LVM_GETCOLUMNWIDTH
        %W = @sendmsg(~%1,$101D,%N,0)
        if @greater(%W,0)
          registry write,DEFAULT,ColumnWidths\%1,Col %N,%W
        else
          %W = 0
        end
        %N = @succ(%N)
      until @zero(%W)@equal(%N,%2)
    end
  else
    error 2
  end
  exit

:restorecolumnwidths
  rem RESTORECOLUMNWIDTHS tbTable, %%numcolumns
  if %1
    if @winexists(~%1)
      %N = 0
      repeat
        # LVM_SETCOLUMNWIDTH
        %W = @regread(DEFAULT,ColumnWidths\%1,Col %N,0)
        if @greater(%W,0)
          %X = @sendmsg(~%1,$101E,%N,%W)
        end
        %N = @succ(%N)
      until @zero(%W)@equal(%N,%2)
    end
  else
    error 2
  end
  exit
 
:ensurevisible
  if %1
    if @winexists(~%1)
      if @greater(@count(%1),%2)
        # LVM_ENSUREVISIBLE
        %X = @sendmsg(~%1,$1013,%2,0)
      end
    end
  else
    error 2
  end
  exit


Note that you have to specify the number of columns. Originally I used the fact that LVM_GETCOLUMNWIDTH is supposed to return 0 if it fails, to exit the loop for getting the column widths. This worked fine under XP, but then I found that apps were apparently hanging on exit when run under Win98. It turns out that the value returned under Win98 if the column number doesn't exist is random: it may be the previous column number, zero, or a very large positive or negative number. So the routine was writing up to 65536 garbage values to the registry. Sad

Anyways, I just wondered if it would be possible to expand this unit by adding SaveColumnOrder and RestoreColumnOrder commands? I can't quite see how from the information CodeScript has given, so over to you guys...

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Jan 19, 2004 3:01 pm    Post subject: Reply with quote

I believe there is an API which gives you the column order as an array. That way, just save this array to the registry, and load it with the right API again the next time the table element is shown... Smile
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Jan 19, 2004 3:52 pm    Post subject: Reply with quote

This should do the trick... The "GET" parameter isn't working fully, but I don't know why... Rolling Eyes I think there is something wrong with the @val() things, because @len(%M) will give "20" as a value, which should be right...

Code:
  #define command,columnorder
  #define function,columnorder

  dialog create,Test,-1,0,400,200
  dialog add,table,table1,10,10,380,180,test1|test2|test3|test4|test5
  dialog show

  %X = @SENDMSG(@WINEXISTS(~TABLE1),@SUM($1000,54),0,$10)

  rem ColumnOrder set,<table name>,<array with the order: 1|2|3|4|5 is normal>
  ColumnOrder set,TABLE1,2|3|4|5|1

:Evloop
  wait event
  goto @event()

:Close
  rem @ColumnOrder(get,<table name>,<number of columns>)
  info @ColumnOrder(get,TABLE1,5)
  exit

:ColumnOrder
  if @equal(%1,SET)
    %A =
    %%TempCounter = 1
    while @greater(@pos(|,%3),0)
      %3 = @strdel(%3,1,@pos(|,%3))
      %%TempCounter = @succ(%%TempCounter)
    wend
    %A = @binary(DWORD,@substr(%3,1,1))@binary(DWORD,@substr(%3,3,3))@binary(DWORD,@substr(%3,5,5))@binary(DWORD,@substr(%3,7,7))@binary(DWORD,@substr(%3,9,9))@binary(DWORD,@substr(%3,11,11))@binary(DWORD,@substr(%3,13,13))@binary(DWORD,@substr(%3,15,15))@binary(DWORD,@substr(%3,17,17))@binary(DWORD,@substr(%3,19,19))@binary(DWORD,@substr(%3,21,21))@binary(DWORD,@substr(%3,23,23))@binary(DWORD,@substr(%3,25,25))
    %Z = @SENDMSG(@WINEXISTS(~%2),@SUM($1000,5Cool,%%TempCounter,@ADDR("%A"))
  end
  if @equal(%1,GET)
    %%TempCounter = 1
    %M = @BINARY(DWORD,0)@BINARY(DWORD,0)@BINARY(DWORD,0)@BINARY(DWORD,0)@BINARY(DWORD,0)
    %Z = @SENDMSG(@WINEXISTS(~%2),@SUM($1000,59),%3,@ADDR("%M"))
    %%TempCounter = 0
    %%Output =
    while @unequal(%%TempCounter,@len(%M))
      if @equal(%%Output,)
        %%Output = @val(@substr(%M,@succ(%%TempCounter),@sum(%%TempCounter,4)))
        else
          %%Output = %%Output|@val(@substr(%M,@succ(%%TempCounter),@sum(%%TempCounter,4)))
        end
        %%TempCounter = @sum(%%TempCounter,4)
      wend
      exit %%Output
    end
    exit


Last edited by Skit3000 on Mon Jan 19, 2004 5:07 pm; edited 2 times in total
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Jan 19, 2004 4:24 pm    Post subject: Reply with quote

Oh excellent! I'll give it a try.
_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Jan 19, 2004 4:55 pm    Post subject: Reply with quote

It works! Very Happy It should be @sum($1000,59) to get the order, not 58.
_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Jan 19, 2004 5:08 pm    Post subject: Reply with quote

I changed it in my example, as well as another little mistake. When outputting, it first showed the first column as "0", now it is showed as "1"... Smile
Back to top
View user's profile Send private message
trapper
Contributor
Contributor


Joined: 28 Jan 2005
Posts: 112
Location: Brisbane, Australia

PostPosted: Fri Feb 25, 2005 3:37 am    Post subject: Reply with quote

jules wrote:
It works! Very Happy It should be @sum($1000,59) to get the order, not 58.
Jules,

Would it be possible for you to incorporate the Save/Restore Column Order code from Skit3000 into your original Save/Restore Column Widths example?

Kind Regards.

_________________
John Trappett
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group