AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Drive Icons

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Markus M.



Joined: 17 Apr 2007
Posts: 14
Location: Stuttgart (Ger)

PostPosted: Thu Apr 19, 2007 3:01 pm    Post subject: Drive Icons Reply with quote



Quote:
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. Wink

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)


Code:


#NoEnv
#notrayicon
SendMode Input

; ########################### create GUI #######################

; --- Header ---

;header gradient
bg=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Gui, Font, s14 bold ,terminal
Gui, 1:Add, Text,x0 y0 w600 h4 c0000d0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000c0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000b0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000a0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000090 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000080 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000070 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000060 , %bg%
;line blow gradient
gui, add, text, x0 y+0 w565 h2 0x10,
;heading text
gui, font, s14 bold cblack,arial
gui, add, text, x13 y6 +backgroundtrans, Drive-Icons
gui, font, s14 cffffff,arial
gui, add, text, x11 y4 +backgroundtrans, Drive-Icons
;help "button"
gui,add,text,x537 y7 backgroundtrans cblack,?
gui,add,text,x535 y5 backgroundtrans cyellow gHelp,?

; --- UI controls ---

;listview
gui,font,,
Gui, Add, ListView, x10 y45 h250 w280 section gListKlick vListe AltSubmit -Multi -LV0x10 NoSort, Drive|Icon|Label  ; Create a ListView.

;Label: editfield & delete button
gui, add, text, ys section, Label:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelLabel,û
gui, font,,
gui, add, edit, yp+2 x+2 w150 vedit_label gTextFieldChange,

;Icon: editfield & delete button
gui, add, text, xs y+18, Icon:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelIcon,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_icon gTextFieldChange,
gui, add, button, x+3 yp+1 w25 hp-2 gIconwahl,...
;Icon: picture & errormessage
gui, add, picture, xs w32 h32 vIcon32,
gui,font,bold c990000,
gui add, text,xp yp vErrorMessage, Error: Icon file not found !
gui,font,,
guicontrol,hide,ErrorMessage

;buttons at bottom
gui, add, text, x0 y310 w565 h2 0x10,
gui, add, button,x430 w120 gbuttoncancel, &Close
gui, add, button,xp-130 w120 gDoIt vDoIt, &Apply

;show gui
Gui Show, w560,Drive-Icons

;initalize LV
FirstInit := true
gosub FillDriveList

return

;############################## EVENTS ###########################

;=================================================================
; apply changes
DoIt:
gui, submit, nohide

;dieser code gewinnt keinen schönheitspreis, also noch mal überarbeiten:
reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% . "\DefaultLabel"
If (edit_label = "")
{
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}
Else
{
  RegWrite,REG_SZ , HKEY_LOCAL_MACHINE, %reg_key%,, %edit_label%
}

reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% . "\DefaultIcon"
If (edit_icon = "")
{
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}
Else
{
  RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %reg_key%, ,%edit_icon%
}

If (edit_label = "") && (edit_icon = "")
{
  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% 
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}

 
IL_Destroy(ImageListID)
LV_Delete()
guicontrol,disable, DoIt
gehezu := ListenNr
gosub FillDriveList
return

;=================================================================
TextFieldChange:
GuiControlGet, wert, , %A_GuiControl%
if (A_GuiControl = "edit_label")
{
  if (LaufwMyLabel%ListenNr% <> wert)
    guicontrol,enable, DoIt 
  if (strlen(wert) = 0)
    guicontrol,disable,delLabel
  if (strlen(wert) > 0)
    guicontrol,enable,delLabel 
}

if (A_GuiControl = "edit_icon")
{
  if (LaufwMyIcon%ListenNr% <> wert)
    guicontrol,enable, DoIt   
  if (strlen(wert) = 0)
    guicontrol,disable,delIcon
  if (strlen(wert) > 0)
    guicontrol,enable,delIcon 
}

return


;=================================================================
; delete icon and/or label in editfield
Delete:
if (A_GuiControl = "delLabel")
{
  guicontrol,,edit_label,
  guicontrol,disable,delLabel
}

if (A_GuiControl = "delIcon")
{
  guicontrol,,edit_icon,   
  guicontrol,hide,Icon32
  guicontrol,disable,delIcon
}

return

;=================================================================
; ListView Events
ListKlick:

if (A_GuiEvent = "ColClick") or (A_GuiEvent = "K") or (A_GuiEvent = "f")
   return
 
ListenNr = %A_EventInfo% 

; LV item selected, continue with ControlUpdate


;=================================================================
;Update editfields, icon/errormassage and delete buttons, matching the selected drive from LV
ControlUpdate:

guicontrol,,edit_label,% LaufwMyLabel%ListenNr%
guicontrol,,edit_icon,% LaufwMyIcon%ListenNr%

IconFile := LaufwMyIcon%ListenNr%
StripIcon(IconFile,IconIndex)
IconIndex ++

if (LaufwMyIcon%ListenNr% <> "")
{
  guicontrol,enable,delIcon
  if (IconError%ListenNr% = true)
  {
    guicontrol,hide,Icon32
    guicontrol,show,ErrorMessage       
  }
  else
  {
    guicontrol,hide,ErrorMessage   
    guicontrol,show,Icon32
    guicontrol,,Icon32, *icon%iconindex% *w32 *h32 %IconFile% 
  }
}
else
{
  guicontrol,hide,Icon32
  guicontrol,hide,ErrorMessage   
  guicontrol,disable,delIcon
}

if (LaufwMyLabel%ListenNr% <> "")
{
  guicontrol,enable,delLabel
}
else
{
  guicontrol,disable,delLabel
}

  guicontrol,disable, DoIt
 
return

;=================================================================
; Browse Button
Iconwahl:

Gui, submit,nohide
IconFile := edit_icon
IconIndex := 0

StripIcon(IconFile,IconIndex)

gui, +disabled
ChooseIcon(IconFile, IconIndex, hGui)
gui, -disabled
gui, show

if instr(IconFile,"%SystemRoot%" )
{
  StringReplace, IconFile, IconFile, % "%SystemRoot%", %A_WinDir% , All
}

guicontrol,show,Icon32
guicontrol,,Icon32, % "*icon" . IconIndex+1 . " *w32 *h32 " . IconFile
guicontrol,enable,delIcon
guicontrol,hide,ErrorMessage

IconIndexText =
if (IconIndex <> 0)
IconIndexText = ,%IconIndex%
GuiControl,,edit_icon, %IconFile%%IconIndexText%

return

; ---- Bye bye ----
buttoncancel:
;guiescape:
GuiClose:

exitapp

;######################## Subroutines ##################

;=================================================================
FillDriveList:
;create IL and assign to LV.
ImageListID := IL_Create(24,0,0)
LV_SetImageList(ImageListID)

; this LV_ModifyCol command are just cosmetic surgery, when starting the app.
If (FirstInit = true )
{
  LV_ModifyCol(1,120)
  LV_ModifyCol(2,50)
  LV_ModifyCol(3,100)
  FirstInit := false
}

DriveGet, LaufwListe, list
AnzLaufw := StrLen(LaufwListe)
StringSplit, Laufwletter, LaufwListe ,,

loop, %AnzLaufw%
{
  DriveGet, LaufwTyp%A_Index%, type, % Laufwletter%A_Index% . ":"
  if (LaufwTyp%A_Index% = "FIXED") OR (LaufwTyp = "UNKNOWN")
    LaufwExIcon%A_Index% := 8+1
  if (LaufwTyp%A_Index% = "CDROM")
    LaufwExIcon%A_Index% := 11+1 
  if (LaufwTyp%A_Index% = "REMOVABLE")
    LaufwExIcon%A_Index% := 7+1 
  if (LaufwTyp%A_Index% = "RAMDISK")
    LaufwExIcon%A_Index% := 12+1 
  if (LaufwTyp%A_Index% = "NETWORK")
    LaufwExIcon%A_Index% := 9+1 

  ;eleminiate ugly noise from floppy drives (do not retrieve label from possible floppies)
  if  (Laufwletter%A_Index% <> "A") && (Laufwletter%A_Index% <> "B")
    DriveGet, LaufwExLabel%A_Index%, label, % Laufwletter%A_Index% . ":" 

  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultLabel"
  RegRead, LaufwMyLabel%A_Index%, HKEY_LOCAL_MACHINE, %reg_key%,
 
  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultIcon"
  RegRead, LaufwMyIcon%A_Index%, HKEY_LOCAL_MACHINE, %reg_key%,   
 
  if (LaufwMyIcon%A_Index% <> "") ; has own icon (specified in registry)
  {
    IconError%A_Index% := false
    IconIndikator := "   X   "
    IconFile := LaufwMyIcon%A_Index%
    StripIcon(IconFile,IconIndex)
    IconIndex++
    ; if icon file doesn't exist, create errormessage in LV
    ; use standard icon in IL
    IfNotExist, %IconFile%
    {
      IconError%A_Index% := true
      IL_Add(ImageListID,  "shell32.dll",LaufwExIcon%A_Index%)
      IconIndikator := "Error !"
    }
    else ; ok, add icon to IL
    {
      IL_Add(ImageListID,IconFile,IconIndex )       
    }
   

  }
  else ; no own icon, use standard icon from shell32.dll
  {
    IconIndikator :=
    IL_Add(ImageListID, "shell32.dll", LaufwExIcon%A_Index%)
  }
 
  LV_Add("Icon" . A_Index,A_Space  Laufwletter%A_Index% . ":" . A_Space LaufwExLabel%A_Index% ,IconIndikator ,LaufwMyLabel%A_Index%)
}


LV_ModifyCol()  ; Auto-adjust the column widths.


;select LV item
if (gehezu = "" )
  gehezu := 1
LV_Modify(gehezu, "Select")
LV_Modify(gehezu, "Focus")
controlfocus, SysListView321,Drive-Icons

return

;=================================================================
;split iconstring into filename and index
StripIcon(byRef IconFile, byRef IconIndex)
{
  find = ,
  StringGetPos, KommaPos, IconFile, %find%, R
  if (KommaPos > 0)
  {
    IconIndex := SubStr(IconFile, KommaPos+2)
    StringLeft,IconFile,IconFile,KommaPos
  }
  else
  {
    IconIndex := 0
  }

  Return
}

;=================================================================
; ChooseIcon
;by majkinetor, w2k fix by me

ChooseIcon(ByRef sIcon, ByRef idx, hGui=0) {                               
   
    VarSetCapacity(wIcon, 1025, 0)
    if sIcon !=
    {
        r := DllCall("MultiByteToWideChar"
             , "UInt", 0             ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
             , "UInt", 0             ; dwFlags
             , "Str", sIcon          ; LPSTR lpMultiByteStr
             , "Int", StrLen(sIcon)  ; cbMultiByte: -1=null terminated
             , "UInt", &wIcon        ; LPCWSTR lpWideCharStr
             , "Int", 1025)          ; cchWideChar: 0 to get required size

        if !r
            return 2
    }
   
    r := DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "uint", hGui, "uint", &wIcon, "uint", 1025, "intp", idx)
    if !r
        return 1

   len := DllCall("lstrlenW", "UInt", &wIcon)
   VarSetCapacity(sIcon, len, 0)
   r := DllCall("WideCharToMultiByte"
         , "UInt", 0           ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0           ; dwFlags
         , "UInt", &wIcon      ; LPCWSTR lpWideCharStr
         , "Int", len          ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", sIcon        ; LPSTR lpMultiByteStr
         , "Int", len          ; cbMultiByte: 0 to get required size
         , "UInt", 0           ; LPCSTR lpDefaultChar
         , "UInt", 0)          ; LPBOOL lpUsedDefaultChar

    if !r
        return 3
           
    return 0
}

;########################## Help ########################
; temp. soloution
Help:
gui +owndialogs
msgbox,
(
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. ;-)

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)
)
return


it is still beta. i posted it to get some ideas and bug reports.
did not tested on win95 and derivats (98, Me) and with networkdrives.
the code could be optimized at some places, because i'm still learnig ahk.
some variables have german names, that will be "fixed". i hope you can read the code anyway Wink

Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Thu Apr 19, 2007 3:09 pm    Post subject: Reply with quote

Very Happy Der kleine blaue Elephant ist echt mal ne Abwechslung zum Knut-Der Eisbär-Rummel. Macht zwar nix - ist aber so! Wink Cool
Back to top
Markus M.



Joined: 17 Apr 2007
Posts: 14
Location: Stuttgart (Ger)

PostPosted: Thu Apr 19, 2007 3:13 pm    Post subject: Reply with quote

KNUT Evil or Very Mad ich kann den namen schon nimmer hören. selbst die "ernsthaften" nachrichtesender wie n24 thematisieren diesen (sch)eis(s)bär.

Back to top
View user's profile Send private message
Arnoud



Joined: 24 Mar 2007
Posts: 15

PostPosted: Fri Apr 20, 2007 3:15 pm    Post subject: Reply with quote

Nice app

Seems to work fine on networkdrives.
Why does it take so long to retreive te drives? More than 15 seconds over here!!! (10 network, 3 local).

If i select an icon for a drive it is gone when i select another drive. Should be better to let a user aplly changes for all drives at once.
Back to top
View user's profile Send private message
Markus M.



Joined: 17 Apr 2007
Posts: 14
Location: Stuttgart (Ger)

PostPosted: Fri Apr 20, 2007 4:25 pm    Post subject: Reply with quote

thanx for your reply Smile

Arnoud wrote:
Nice app

Seems to work fine on networkdrives.
Why does it take so long to retreive te drives? More than 15 seconds over here!!! (10 network, 3 local).


it take about ~2 seconds to scan 13 local drives. i don't know why it takes so long with networkdrives. is it only at the first scan or always ?
i'll try to check this out when i'm at work at the end of next week.
maybe i should disable to retrieve the label from networkdrive as i did for floppies (a: and b: drives). but on the other hand it would not be very comfortable to have only the drive letters and not the names from the netdrives.


Arnoud wrote:

If i select an icon for a drive it is gone when i select another drive. Should be better to let a user aplly changes for all drives at once.


good point Wink i did not considered it as an disadvantage, but you're right. I'll gonna change this.

Back to top
View user's profile Send private message
daonlyfreez



Joined: 16 Mar 2005
Posts: 745
Location: Berlin

PostPosted: Sat Apr 21, 2007 11:29 am    Post subject: Reply with quote

Nice! Cool

Tip: Don't use the JavaScript [copy]-link, it breaks on the Ûs etcet.
_________________
(sorry, homesite offline atm)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group