Random_Task00 09-05-2001, 02:51 AM If i have a form which contains several command buttons, which when clicked open a different program (eg, Word, Excel, Explorer etc), what VB code would i use so when a user dragged and dropped a shortcut/icon onto the form it would add the shortcut to that program (with that icon possibly) onto the form permanently? I've got so far as to know ill have to use OLEDragDrop Event, but ive no idea how to...help?
Thanks
Laurent 09-05-2001, 05:56 AM i'm realy not sure if this can be done because once the programm is compiled yopu can change the interface unless you recompile it??? if there's a way i would like to know
I'll be among the best soon, very soon!!!
Random_Task00 09-05-2001, 08:01 AM billsoo said by adding file paths into an ini file, or into a registry setting or something you could do it...though that just confused matters for me...apparently it can be done, though no idea how ;-)
<P ID="edit"><FONT class="small"><EM>Edited by Random_Task00 on 09/05/01 09:03 AM.</EM></FONT></P>
BillSoo 09-05-2001, 09:14 AM You can use the registry to save application information. For instance, many programs save things like "last files opened" or "window size and position" etc. You could use the registry to store the files that make up your buttons. Use the GetSetting and SaveSetting commands. (I think that's the function names; I don't use the registry much since I prefer INI files).
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
If you know how to drag the shortcut onto your application during run-time, then you could re-load the form in its present state by saving it to the registry or an ini file like Bill Soo said. If this is the case, then we can help you with that specifically.
If dragging the shortcuts onto your form is where you're having problems, then that's a different issue. If you already know how to do this, could you post the code that you're using for that so that others could benefit?
"The face of a child can say it all, especially the mouth part of the face." - Jack Handy
BillSoo 09-05-2001, 11:15 AM Here is a quick example to get you started. However, it only works for EXE files. If you copy links, or help files or documents, you should use the SHELLEXECUTE API call instead of SHELL.
<pre><font color=blue>Option Explicit</font color=blue>
<font color=blue>Dim</font color=blue> nButtons <font color=blue>As Integer</font color=blue> <font color=green>'number of button controls</font color=green>
<font color=blue>Private Sub</font color=blue> Command1_Click(Index <font color=blue>As Integer</font color=blue>)
Shell Command1(Index).Tag, vbNormalFocus
<font color=blue>End Sub</font color=blue>
<font color=blue>Private Sub</font color=blue> Form_Load()
<font color=green>'me.oledropmode is set to 1 (Manual)</font color=green>
<font color=green>'command1.index is set to 0</font color=green>
<font color=green>'command1.visible is set to FALSE</font color=green>
<font color=green>'command1.style is set to 1 (Graphical)</font color=green>
<font color=blue>Dim</font color=blue> i <font color=blue>As Integer</font color=blue>
<font color=blue>Dim</font color=blue> n <font color=blue>As Integer</font color=blue>
<font color=blue>Dim</font color=blue> fn <font color=blue>As String</font color=blue>
n = <font color=blue>CInt</font color=blue>(GetSetting("FileLauncher", "Init", "nButtons", "0"))
nButtons = 0
<font color=blue>For</font color=blue> i = 1 <font color=blue>To</font color=blue> n
fn = Trim$(GetSetting("FileLauncher", "File" & <font color=blue>CStr</font color=blue>(i), "Path", vbNullString))
<font color=blue>If</font color=blue> Len(fn) <font color=blue>Then</font color=blue> LoadButton fn
<font color=blue>Next</font color=blue> i
<font color=blue>End Sub</font color=blue>
<font color=blue>Private Sub</font color=blue> Form_OLEDragDrop(Data <font color=blue>As</font color=blue> DataObject, Effect <font color=blue>As Long</font color=blue>, Button <font color=blue>As Integer</font color=blue>, Shift <font color=blue>As Integer</font color=blue>, X <font color=blue>As Single</font color=blue>, Y <font color=blue>As Single</font color=blue>)
<font color=blue>Dim</font color=blue> fn <font color=blue>As String</font color=blue>
fn = Data.Files(1) <font color=green>'get the name of the file that was dropped...</font color=green>
LoadButton fn
<font color=blue>End Sub</font color=blue>
<font color=blue>Private Sub</font color=blue> LoadButton(<font color=blue>ByVal</font color=blue> fn <font color=blue>As String</font color=blue>)
<font color=green>'loads a button with filename fn. Will create and move the button if required</font color=green>
<font color=blue>Dim</font color=blue> i <font color=blue>As Integer</font color=blue>
<font color=blue>If</font color=blue> nButtons <font color=blue>Then</font color=blue> <font color=green>'create a new button and place it below the others</font color=green>
Load Command1(nButtons)
Command1(nButtons).Top = Command1(nButtons - 1).Top + Command1(nButtons - 1).Height
<font color=blue>End If</font color=blue>
i = InStrRev(fn, "\")
<font color=blue>If</font color=blue> i <font color=blue>Then</font color=blue> Command1(nButtons).Caption = Mid$(fn, i + 1) <font color=blue>Else</font color=blue> Command1(nButtons).Caption = fn
Command1(nButtons).Tag = fn
Command1(nButtons).Visible = <font color=blue>True</font color=blue>
nButtons = nButtons + 1
<font color=blue>End Sub</font color=blue>
<font color=blue>Private Sub</font color=blue> Form_Unload(Cancel <font color=blue>As Integer</font color=blue>)
<font color=blue>Dim</font color=blue> i <font color=blue>As Integer</font color=blue>
SaveSetting "FileLauncher", "Init", "nButtons", <font color=blue>CStr</font color=blue>(nButtons)
<font color=blue>For</font color=blue> i = 1 <font color=blue>To</font color=blue> nButtons
SaveSetting "FileLauncher", "File" & <font color=blue>CStr</font color=blue>(i), "Path", <font color=blue>CStr</font color=blue>(Command1(i - 1).Tag)
<font color=blue>Next</font color=blue> i
<font color=blue>End Sub</font color=blue>
</pre>
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Whoah! That's pretty cool. I've never used the OLEDragDrop event before mainly because I'm usually working on either engineering type applications or personal applications. I added code to put the icon into the button, but it only works for EXE files, not shortcuts or non-exe files (I used ShellExecute instead of Shell). I guess I'd have to get the application that's associated with the file or read the pathname from the shortcut, but right now I don't have enough curiousity to do either. images/icons/laugh.gif
Thanks again, Bill.
"The face of a child can say it all, especially the mouth part of the face." - Jack Handy
Here's what I came up with. Note that this was just something I did to educate myself, so it could probably use some extra comments, some error-trapping, and a few other extras that I haven't put in partly out of laziness and partly because I've already spent more time on this than I could justify to myself since I'm doing this at workimages/icons/laugh.gif.
Anyway, the main form acts as a sort of "virtual desktop". You can drag icons from the real desktop onto the form and they auto-arrange in the order that you added them.
Double-clicking on an icon or the description (a picturebox & label, respectively) will launch the file, as will hitting the Enter key with one of the icons selected. You can tab through the icons as well.
You can't drag the icons around the form, however, like you can on the real desktop, partly because I wanted the ability to rearrange the icons when you resize the form.
Feel free to use the code in any way, shape, or form.
"The face of a child can say it all, especially the mouth part of the face." - Jack Handy
Random_Task00 09-07-2001, 06:56 PM Heh, to be as knowledgeable as you guys ;-)..thankyou very much for your help :-)
|