KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

System Icons

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sun Jun 13, 2004 10:18 pm    Post subject: System Icons Reply with quote

Shawn and Kasul,
Thank You for your help with this script.
Shawn, Gave me the ToolBarMenu and the StatusBar.
Kasul, Gave the recursive TreeView Structure.

I am playing with the use of Icons, I am adding and useing ico files and
it is working.

It seems like there could be a better way to add Icons. Is there a way to
import these Icons or referance them like the ones in System files like:
"C:\WINNT\system32\SHELL32.dll"

Here is the Script:

Ideas? Question

Code:

SetConsole("Hide")

Break On

$System = CreateObject("Kixtart.System")

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 192,192,192
$Form.ControlBox = "True"
$Form.DrawGrid = "True"
$Form.FontBold = "False"
$Form.FontItalic = "False"
$Form.FontName = "Microsoft Sans Serif"
$Form.FontSize = 8.25
$Form.FontUnderline = "False"
$Form.ForeColor = 0,0,0
$Form.FormBorderStyle = 2
$Form.Height = 450
$Form.Left = 0
$Form.MaximizeBox = "True"
$Form.MinimizeBox = "True"
$Form.SizeGripStyle = 0
$Form.StartPosition = 4
$Form.Tag = ""
$Form.Text = "TreeView Test"
$Form.Top = 0
$Form.ToolTipText = ""
$Form.TopMost = "False"
$Form.Width = 816
$Form.WindowState = 0
;**************************************

;                     ("Object Text", Left, Top, Width, Hight)
$Form.Menu = $System.MainMenu()
$Form.Menu.Style = 1
$Form.Menu.ImageList = $System.BuiltinImageList()

$FileMenu = $Form.Menu.MenuItems.Add("File")

$ExitMenu = $FileMenu.MenuItems.Add("Exit","quit()","Ctrl+X")
$ExitMenu.ImageIndex = 60

$ViewMenu = $Form.Menu.MenuItems.Add("View")

$SmallViewMenu = $ViewMenu.MenuItems.Add("Icons")
$SmallViewMenu.OnClick = "OnViewClick(2)"

$ListViewMenu = $ViewMenu.MenuItems.Add("List")
$LIstViewMenu.OnClick = "OnViewClick(3)"

$DetailsMenu = $ViewMenu.MenuItems.Add("Details")
$DetailsMenu.OnClick = "OnViewClick(1)"

$ToolBar = $Form.GroupBox()
$ToolBar.Height = 30
$ToolBar.Dock = "Top"

$StatusBar = $Form.StatusBar()
$StatusBar.Dock = "Bottom"

$StatusGroupBox = $Form.Controls.GroupBox("",10,345,500,20)
$StatusGroupBox.Dock = 2

;                     ("Object Text", Left, Top, Width, Hight)
$TextBox1 = $StatusGroupBox.Controls.RichTextBox("",5,5,250,23)
$TextBox1.TextAlign = 1
$TextBox1.Dock =3

$Splitter1 = $StatusGroupBox.Splitter()
$Splitter1.Dock = 3
$Splitter1.OnMouseMove = "GetFormWidth()"

$ProgressBar1 = $StatusGroupBox.Controls.ProgressBar()
$ProgressBar1.BackColor = 212,208,200
$ProgressBar1.Height = 23
$ProgressBar1.Left = 199
$ProgressBar1.Top = 5
$ProgressBar1.Width = 200
$ProgressBar1.Maximum = 100
$ProgressBar1.Minimum = 0
$ProgressBar1.Style = 1
$ProgressBar1.Step = 10
$ProgressBar1.Dock = 3

;                     ("Object Text", Left, Top, Width, Hight)
$GroupBox = $Form.Controls.GroupBox("",5,5,800,400)
$GroupBox.Dock = 5

;                     ("Object Text", Left, Top, Width, Hight)
$TreeView = $GroupBox.Controls.TreeView("TreeView",5,5,250,200)
$TreeView.ImageList = $System.BuiltinImageList()
$TreeView.OnAfterSelect = "OnAfterSelect()"
$TreeView.ShowRootLines = 1
$TreeView.Sorted = "True"
$TreeView.ShowPlusMinus = "True"
$TreeView.Dock = 3

$Splitter2 = $GroupBox.Splitter()
$Splitter2.Dock = 3
$Splitter2.OnMouseMove = "GetFormWidth()"

;                     ("Object Text", Left, Top, Width, Hight)
$ListView = $GroupBox.Controls.ListView("",0,5,625,200)
$ListView.SmallImageList = $System.BuiltinImageList()
$ListView.GridLines = "False"
$ListView.AutoArrange = "True"
$ListView.BorderStyle = 2
$ListView.Dock = 3

$Splitter3 = $GroupBox.Splitter()
$Splitter3.Dock = 3
$Splitter3.OnMouseMove = "GetFormWidth()"

;                     ("Object Text", Left, Top, Width, Hight)
$ButtonGroupBox = $GroupBox.Controls.GroupBox("",0,5,85,75)
$ButtonGroupBox.Dock = 5
$ButtonGroupBox.OnMouseMove = "GetFormWidth()"
$ButtonGroupBox.OnMouseEnter = "GetFormWidth()"
$ButtonGroupBox.OnMouseLeave = "GetFormWidth()"

;                     ("Object Text", Left, Top, Width, Hight)
$Button1 = $ButtonGroupBox.Controls.Button("OK",5,10,75,23)

;                     ("Object Text", Left, Top, Width, Hight)
$Button2 = $ButtonGroupBox.Controls.Button("Cancel",5,40,75,23)
$Button2.OnClick = "quit()"

;Adding Icons to SmallImageList
$ = $Form.SmallImageList.Images.Add("C:\Icons\Desktop.ico")            ;68
$ = $Form.SmallImageList.Images.Add("C:\Icons\My Computer.ico")         ;69
$ = $Form.SmallImageList.Images.Add("C:\Icons\Floppy Drive.ico")         ;70
$ = $Form.SmallImageList.Images.Add("C:\Icons\Hard Drive.ico")         ;71
$ = $Form.SmallImageList.Images.Add("C:\Icons\CD Rom.ico")            ;72
$ = $Form.SmallImageList.Images.Add("C:\Icons\Network Drive.ico")      ;73
$ = $Form.SmallImageList.Images.Add("C:\Icons\My Documents.ico")         ;74
$ = $Form.SmallImageList.Images.Add("C:\Icons\My Pictures.ico")         ;75
$ = $Form.SmallImageList.Images.Add("C:\Icons\My Data Sources.ico")      ;76
$ = $Form.SmallImageList.Images.Add("C:\Icons\Network Places.ico")      ;77
$ = $Form.SmallImageList.Images.Add("C:\Icons\Network Folder.ico")      ;78
$ = $Form.SmallImageList.Images.Add("C:\Icons\Recycle Bin.ico")         ;79

$ = $Form.SmallImageList.Images.Add("C:\Icons\Application Extension.ico")   ;80
$ = $Form.SmallImageList.Images.Add("C:\Icons\Bitmap Image.ico")         ;81
$ = $Form.SmallImageList.Images.Add("C:\Icons\Configuration Settings.ico")   ;82
$ = $Form.SmallImageList.Images.Add("C:\Icons\Kix Script.ico")         ;83
$ = $Form.SmallImageList.Images.Add("C:\Icons\SCR.ico")            ;84
$ = $Form.SmallImageList.Images.Add("C:\Icons\Text Document.ico")      ;85
$ = $Form.SmallImageList.Images.Add("C:\Icons\UnKnown Application.ico")   ;86
$ = $Form.SmallImageList.Images.Add("C:\Icons\UnKnown File Type.ico")      ;87
$ = $Form.SmallImageList.Images.Add("C:\Icons\System File.ico")         ;88
$ = $Form.SmallImageList.Images.Add("C:\Icons\MS-DOS Batch File.ico")      ;89
;$ = $Form.SmallImageList.Images.Add("C:\Icons\")      ;88

;                     ("Column Name",Width,justification)
$NameColumn = $ListView.Columns.Add("Name",200,0)
$SizeColumn = $ListView.Columns.Add("Size",100,1)
$TypeColumn = $ListView.Columns.Add("Type",100,0)
$LastAccessedColumn = $ListView.Columns.Add("Last Accessed",,0)
$LastModifiedColumn = $ListView.Columns.Add("Last Modified",,0)

$Computer = @WKSTA

LoadTree($Computer,$TreeView)

$Form.Show

While $Form.Visible
   GetFormWidth()
   $=Execute($Form.DoEvents())
Loop

Exit 1

Function LoadTree($Computer,$TreeView)
   
   Break On
   
   ;********* FORM CREATE BEGIN **********
   $ProgressForm = CreateObject('Kixtart.Form')
   $ProgressForm.BackColor = 192,192,192
   $ProgressForm.ControlBox = "True"
   $ProgressForm.DrawGrid = "True"
   $ProgressForm.FontBold = "False"
   $ProgressForm.FontItalic = "False"
   $ProgressForm.FontName = "Microsoft Sans Serif"
   $ProgressForm.FontSize = 8.25
   $ProgressForm.FontUnderline = "False"
   $ProgressForm.ForeColor = 0,0,0
   $ProgressForm.FormBorderStyle = 4
   $ProgressForm.Height = 140
   $ProgressForm.Left = 0
   $ProgressForm.MaximizeBox = "True"
   $ProgressForm.MinimizeBox = "True"
   $ProgressForm.SizeGripStyle = 0
   $ProgressForm.StartPosition = 4
   $ProgressForm.Tag = ""
   $ProgressForm.Text = "TreeView Structure"
   $ProgressForm.Top = 0
   $ProgressForm.ToolTipText = ""
   $ProgressForm.TopMost = "False"
   $ProgressForm.Width = 450
   $ProgressForm.WindowState = 0
   ;********* FORM CREATE END **********
   
   ;************* ProgressBar **************
   $ProgressBar = $ProgressForm.Controls.ProgressBar
   $ProgressBar.Anchor = 5
   $ProgressBar.BackColor = 192,192,192
   $ProgressBar.Enabled = "True"
   $ProgressBar.Height = 23
   $ProgressBar.Left = 10
   $ProgressBar.Maximum = 100
   $ProgressBar.Minimum = 0
   $ProgressBar.Style = 1
   $ProgressBar.Step = 10
   $ProgressBar.Tag = ""
   $ProgressBar.Top = 80
   $ProgressBar.Visible = "True"
   $ProgressBar.Width = 420
   ;*************************************
   
   ;************* ProgressBarLabel **************
   $ProgressBarLabel = $ProgressForm.Controls.Label("",10,20,200,23)
   $ProgressBarLabel.Text = "Loading Directory Tree for: " + $Computer
   ;*************************************
   
   ;************* ProgressBarInfo **************
   $ProgressBarInfo = $ProgressForm.Controls.Label("",10,50,400,46)
   $ProgressBarInfo.Text = ""
   ;*************************************
   
   $ProgressForm.Show
   
   GetTree($Computer,$TreeView)
   
   $ProgressForm.Hide

   While $ProgressForm.Visible
     $=Execute($ProgressForm.DoEvents())
   Loop
   
   Exit 1

EndFunction


Function changeProgressbar($Step)
   
   $Count1 = $Count1 + $Step
   If $Count1 > 100
      $Count1 = 0
   EndIf
   $ProgressBar.Value = $Count1
   
   Sleep 0.05
   
EndFunction

Function GetFormWidth()
   
   $FormWidth = $TreeView.Width + $Splitter2.Width + $ListView.Width + $Splitter3.Width + $Button1.Width + 20
   $StatusBarWidth = $TextBox1.width + $Splitter1.Width + $ProgressBar1.Width + 20
   $Form.Width = $FormWidth
   If $StatusBarWidth = $FormWidth OR $StatusBarWidth > $FormWidth
      $TextBox1.width = $FormWidth - $ProgressBar1.Width - $Splitter1.Width
   EndIf
   
EndFunction

Function GetTree($Computer,$ParentNode,Optional $Path)

   Dim $objDrives, $objDrive, $Node, $RootNode, $objSubfolders, $objSubfolder
   If Left($Computer,2)="\\" $Computer=SubStr($Computer,3) EndIf
   ;If NOT $objWMIService
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
   ;EndIf
   If $Path=""
      $ParentNode.Clear
      $RootNode=$ParentNode.Nodes.Add($Computer,69,69)
      $objDrives = $objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
      For Each $objDrive In $objDrives
         $DriveIcon=0
         ;? $objDrive.DeviceID+"\"
         Select
            Case $objDrive.DriveType = 2
               $DriveIcon=70
            Case $objDrive.DriveType = 3 OR $objDrive.DriveType = 6
               $DriveIcon=71
            Case $objDrive.DriveType = 5
               $DriveIcon=72
         EndSelect
         If $DriveIcon
            $Node = $RootNode.Nodes.Add($objDrive.DeviceID + "\",$DriveIcon,$DriveIcon)
            ;? $objDrive.DeviceID+"\"
            GetTree($Computer,$Node,$objDrive.DeviceID + "\")
         EndIf
      Next
   Else ;path<>""
      If Ubound(Split($Path,"\"))>1 Exit EndIf ; Limits to 1 Level
      ;? "Path= " + $Path + "Parent= " + $ParentNode.text
      $objSubfolders = $objWMIService.ExecQuery ("Associators of {Win32_Directory.Name='$Path'} Where AssocClass = Win32_Subdirectory ResultRole = PartComponent")
      For Each $objSubfolder In $objSubfolders
         $Node=$ParentNode.Nodes.Add($objSubfolder.FileName,45,46)
         $ProgressBarInfo.Text = $Path + IIf(Right($Path,1) = "\","","\") + $objSubfolder.FileName
         changeProgressbar(1)
         GetTree($Computer,$Node,$ProgressBarInfo.Text)
      Next
   EndIf

EndFunction

Function EnumerateFilesInFolder($Computer,$Folder)
   
   $Slash = Right($Folder,2)
   If $Slash = ":\"
      $Root = $Folder
      $Folder = "."
   EndIf
   $Count1 = 0
   $ProgressBar1.Value = 0
   ;$ListView.BeginUpdate()
   $ListView.Items.Clear()
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
   $colFiles = $objWMIService.ExecQuery("Select * from CIM_DataFile where Path = '\\$Folder\\'")
   If $colFiles
      For Each $objFile in $colFiles
         TrimFileNameOffPath($objFile.Name)
         $x = InStr($FileNamePath,$Root)
         If $x > 0
            AdvanceProgressBar1(1)
            $FileSize = $objFile.FileSize
            TrimFileNameOffPath($objFile.Name)
            $FileType = $objFile.FileType
            $FileLastAccessed = $objFile.LastAccessed
            $FileLastModified = $objFile.LastModified
            Select
               Case $FileType = "Application Extension"
                  $FileIcon = 80
               Case $FileType = "Bitmap Image"
                  $FileIcon = 81
               Case $FileType = "Configuration Settings"
                  $FileIcon = 82
               Case $FileType = "Kix Script"
                  $FileIcon = 83
               Case $FileType = "SCR"
                  $FileIcon = 84
               Case $FileType = "Text Document"
                  $FileIcon = 85
               Case $FileType = "Application"
                  $FileIcon = 86
               Case $FileType = "System File"
                  $FileIcon = 88
               Case $FileType = "MS-DOS Batch File"
                  $FileIcon = 89
               Case 1
                  $FileIcon = 87
            EndSelect
            $Item = $ListView.Items.Add($FileName,$FileIcon)
            ;$Item.SubItems(0).Text = $FileName
            $Item.SubItems(1).Text = $FileSize + " KB"
            $Item.SubItems(2).Text = $FileType
            GetDateAndTime($FileLastAccessed)
            $Item.SubItems(3).Text = $Month + "/" + $Day + "/" + $Year + " " + $Hour + ":" + $Min
            GetDateAndTime($FileLastModified)
            $Item.SubItems(4).Text = $Month + "/" + $Day + "/" + $Year + " " + $Hour + ":" + $Min
         EndIf
      Next
      ;$ListView.EndUpdate()
      $StatusBar.Text = $path;
   Else
      $StatusBar.Text = @SERROR
   EndIf
   $ProgressBar1.Value = 0
   
EndFunction

Function OnAfterSelect()
   
   Dim $node, $path, $fso, $filefolder, $file, $item, $column, $SelectedNode, $ClickedNode
   
   $Form.Cursor = $System.CursorStyle.Default;
   $SelectedNode = $TreeView.SelectedNode
   $ClickedNode = $TreeView.ImageIndex
   $TextBox1.Text = $SelectedNode.Text
   
   $node = $TreeView.SelectedNode
   If NOT $Node
      $Form.Cursor = $System.CursorStyle.Normal;
      Return
   EndIf
   $Form.Cursor = $System.CursorStyle.WaitCursor;
   $path = TVGetFullPath($node)
   $StatusBar.Text = "Refreshing folder " + $path + ". Please wait...";
   If $path
      EnumerateFilesInFolder($Computer,$SelectedNode.Text)
   EndIf
   $Form.Cursor = $System.CursorStyle.Default;
   Return;
   
EndFunction

Function TrimFileNameOffPath($FullPath)

   Dim $i
   For $i = 1 to (Len($FullPath))
      If SubStr($FullPath, $i, 1) = Chr(92)
         $FileNameLength = Len($FullPath) - ($i - 1)
         $FileName = SubStr($FullPath, ($i + 1), $FileNameLength)
         $FileNamePath = SubStr($FullPath, 1, (Len($FullPath) - $FileNameLength + 1))
      EndIf
   Next

EndFunction

Function GetDateAndTime($Number)
   
   $Year = SubStr($Number,1,4)
   $Month = SubStr($Number,5,2)
   $Day = SubStr($Number,7,2)
   $Hour = SubStr($Number,9,2)
   $Min = SubStr($Number,11,2)
   
EndFunction

Function AdvanceProgressBar1($Step)

   $Count1 = $Count1 + $Step
   If $Count1 > 100
      $Count1 = 0
   EndIf
   $ProgressBar1.Value = $Count1
   
   Sleep 0.05

EndFunction

Function OnViewClick($view)

   $ListView.View = $view

EndFunction

Function TVGetFullPath($node, Optional $delim)

   Dim $path
   
   If NOT $Delim
      $Delim = "\"
   EndIf
   $path = $node.Text
   $parent = $node.parent
   If $parent
      $path = TVGetFullPath($parent,$delim) + $delim + $node.Text
   EndIf
   $TVGetFullPath = $path

EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Tue Jun 15, 2004 12:58 pm    Post subject: Reply with quote

not sure shawn yet added the functionality but it should be coming if not in the RC3 yet.
and as he is working on loading dll icon-libraries, I'm working on script that will produce them.

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Tue Jun 03, 2008 8:28 pm    Post subject: Working with Icons... Reply with quote

Hope you don't mind me resurrecting this Benny69, but in my search for information on icons it poses more questions than it answers.

If I scan the contents of a folder and extract a list of files:
for each file in the list I enumerate the file suffix, look it up in the classes section of the registry and follow the information to the permanant handler application string which opens the file type in question.

Now I have a file name and the application path.

I want to use the default icon in the application exe to place next to the filename (Minus its suffix) in a listview menu.
In reading your code above I am unsure where it is derrived and so how to use the $fileicon values.

As I don't KNOW what file types I will be seeing I can't pre define icons numbers as you did in the case statement so want to use the default for the application. How do I code such a line if say the filename was
"%profilename%\my documents\my music\test.mp3" and the corresponding application was "C:\Program Files\Windows Media Player\wmplayer.exe"

$Item = $ListView.Items.Add($FileName,$FileIcon)
;$Item.SubItems(0).Text = $FileName

My schme lets me down here when I encounter a .lnk file.
I need to enumerate the filename to which the .lnk points to so then am able to do the query of class above and get the icon.
I have found UDF to generate .lnk files but cant see the method to query them.

CAN YOU HELP ??
________
Hemp


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Mart
KiXforms Regular
KiXforms Regular


Joined: 03 Oct 2005
Posts: 57
Location: Rotterdam - Netherlands

PostPosted: Wed Jun 04, 2008 7:54 am    Post subject: Reply with quote

Mace,

On the part of .lnk files and the app they point to you have some options.

On kixtart.org there are several UDF's that get the shortcut properties.
For example: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=182375&Searchpage=1&Main=24784&Words=shortcut&topic=0&Search=true#Post182375

_________________
Mart

- He's chained forever to a world that's departed.....It's not enough, it's not enough - Sorrow by Pink Floyd.
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Jun 04, 2008 8:37 am    Post subject: Looks Good, well spotted. Reply with quote

Looks like it should do the job.

With such an array, not quite sure HOW I would return the multiple values without assigning to global variables.
Will have to experiment Smile
________
Roll Blunts
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting 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 cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group