Jump to content

Drag .lnk or . exe and extract icon


Recommended Posts

I made a "remote" for my PC in VB a while back. My only annoyance was each time I wanted to add a new application or function I would have to re-write it.

I wondered if it is possible to drop a file(.lnk or .exe) onto a GUI (a button perhaps?) and have the gui store the location of that into a .ini?

My real question is; is it possible to display the icon used by that shortcut on the gui?

Link to comment
Share on other sites

I believe you have to register $WM_DROPFILES. There should be some examples of this on the forum. ProgAndy made a drag and drop system totally in autoit, but that is probably over your head (i know it is over mine).

Thank you for your reply.

This is what I have

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

$Gui = GUICreate("Laiz",420,420,0,0,$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
$Go = GUICtrlCreateButton("Go!",0,0,42,25)
$Program = GUICtrlCreateInput("", 10, 30, 280, 20)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState(@SW_SHOW)

while 1
$Msg = GUIGetMsg()
if $Msg = $Go then
$Prog_1 = GUICtrlRead($Program)
$detail = FileGetShortcut($Prog_1)
MsgBox(0,"!",$details0])
$Icon = GUICtrlCreateIcon($detail[0],-1, 50, 175)
EndIf
WEnd

How do I make the icon that is created respond to a click?

This is now a Gui question so technically in the wrong forum. Sorry.

Edited by BitByteBit
Link to comment
Share on other sites

This works:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $GUI, $GO, $Program, $Prog_1, $Detail, $Icon = 0

$GUI = GUICreate("Laiz", 420, 420, 0, 0, -1, $WS_EX_ACCEPTFILES)
$GO = GUICtrlCreateButton("Go!", 0, 0, 42, 25)
$Program = GUICtrlCreateInput("", 10, 30, 280, 20)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GO
            $Prog_1 = GUICtrlRead($Program)
            $Detail = FileGetShortcut($Prog_1)
            If IsArray($Detail) Then
                MsgBox(0, "!", $Detail[0])
                $Icon = GUICtrlCreateIcon($Detail[0], -1, 50, 175)
            Else
                MsgBox(0, '', "That is not a shortcut!")
            EndIf
        Case $Icon
            If $Icon <> 0 Then
                MsgBox(0, '', "You clicked the icon")
            EndIf
    EndSwitch
    Sleep(25)
WEnd

By the way, a lot of people always post in the general help forum even if it is a gui problem. If it is just a quick question like this, it is fine (at least I think it is ok) to post in general help. If it is involved, you would be best to post in the gui forum so your post doesn't get buried in newer posts.

Link to comment
Share on other sites

Phew, I think I have it down now, check this out:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ButtonConstants.au3>
$Key = 1
dim $detail[1] , $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11



$Gui = GUICreate("Laiz",153, 175, 192, 124,$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
$Go = GUICtrlCreateButton("Go!",119, 129, 32, 21)
$Program = GUICtrlCreateInput("", 0, 129, 118, 18)
MakeButtonsonstart()

GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState(@SW_SHOW)

while 1
$Msg = GUIGetMsg()
if $Msg = $Go then
Start()
EndIf
WEnd

Func Start()
$Prog_1 = GUICtrlRead($Program)
$detail = FileGetShortcut($Prog_1)
Check()
MakeButton()
EndFunc

Func MakeButton()
Read()
if $1  <> "Not Found" then GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $1,1)
if $2  <> "Not Found" then GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $2,1)
if $3  <> "Not Found" then GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $3,1)
if $4  <> "Not Found" then GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $4,1)
if $5  <> "Not Found" then GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $5,1)
if $6  <> "Not Found" then GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $6,1)
if $7  <> "Not Found" then GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $7,1)
if $8  <> "Not Found" then GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $8,1)
if $9  <> "Not Found" then GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $9,1)
EndFunc


Func Check()
$Read = IniRead("C:\Vault.ini","Programs",$Key,"Not Found")
if $Read = "Not Found" then
Write()
EndIf
EndFunc

Func Write()
IniWrite("C:\Vault.ini","Programs",$Key,$detail[0])
$Key = $Key + 1
EndFunc

Func Read()
$1 = IniRead("C:\Vault.ini","Programs",1,"Not Found")
$2 = IniRead("C:\Vault.ini","Programs",2,"Not Found")
$3 = IniRead("C:\Vault.ini","Programs",3,"Not Found")
$4 = IniRead("C:\Vault.ini","Programs",4,"Not Found")
$5 = IniRead("C:\Vault.ini","Programs",5,"Not Found")
$6 = IniRead("C:\Vault.ini","Programs",6,"Not Found")
$7 = IniRead("C:\Vault.ini","Programs",7,"Not Found")
$8 = IniRead("C:\Vault.ini","Programs",8,"Not Found")
$9 = IniRead("C:\Vault.ini","Programs",9,"Not Found")
;$10 = IniRead("C:\Vault.ini","Programs",10,"Not Found")
;$11 = IniRead("C:\Vault.ini","Programs",11,"Not Found")
EndFunc


Func MakeButtonsonstart()
Read()
if $1  <> "Not Found" then GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $1,1)
if $2  <> "Not Found" then GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $2,1)
if $3  <> "Not Found" then GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $3,1)
if $4  <> "Not Found" then GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $4,1)
if $5  <> "Not Found" then GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $5,1)
if $6  <> "Not Found" then GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $6,1)
if $7  <> "Not Found" then GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $7,1)
if $8  <> "Not Found" then GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $8,1)
if $9  <> "Not Found" then GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $9,1)
EndFunc

Next thing is to make it so that you can drag a new icon onto an old button and have it overwrite the icon. Think I'll start on that one tomorrow though :)

Also to check if .exe or if .lnk, but I have an idea of how to do that.

Thank you VERY much for you help!!! I appreciate the time you spent putting together the code below! +rep :)

EDIT:

Oh snap, I'm going to have to go some seriously long way to make these buttons open the programs they correspond to.

Edited by BitByteBit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...