Page 2 of 2 FirstFirst 12
Results 41 to 68 of 68

Thread: Add application to files context menu and send selected files as parameters

  1. #41
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Add application to files context menu and send selected files as parameters

    sounds like your app is just not handling too many requests
    try putting doevents into the formload before linkexecute
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #42

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Thanks for your reply , i tried but it didn't work unfortunatly..I tried to put it at different places, before linkexecute and after it and in the event linkexecute, always i am getting the same result !!
    What is weird is that i took the example posted here but even this application gave the same result ! So it's not from my application, or there is something missing in the code, a property must be set ? Linkinvoke ? other ...Or that DDE is so slow so the computer can't support too many on same time and that's why i am getting the error !

    Please do you know any other way than DEE where i can do what i want ? i think there is OLE or COM way, but am not finding any article about, i found about OLE how to add OCX to use them with word and excel but am not finding a tutoriel for OLE to handle multiple instances...in case you have let me know and in case you have any other idea than the doevents please let me know, cuz now am blocked, can't go forward in my application

  3. #43
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Add application to files context menu and send selected files as parameters

    in the example i was working with, i am sure i used the change event of the hidden textbox, (when a link was poked to the textbox the change event would fire), to add the item to the list box, or what ever, i never noticed any restriction on the number of files it could handle, i am not sure now how many files i tried with, but it was quite a few, i was actually opening all the passed files, not just adding to a list
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #44
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Add application to files context menu and send selected files as parameters

    Quote Originally Posted by justgreat(Via Mail
    Dear sir,
    I saw your article about DDE, and it's very usefull for beginners with DEE! Great job! unfortunatly i am trying to do the same and am getting an error even with your own code and i will explain to you the problem, maybe you can help to solve it...
    I made an application that add to the registry the key HKEY_CLASSES_ROOT\*\Shell\Open With My Application\command...Once a user right click any file and hit the menu that i created "Open With My Application\", the file name is transfered to my application and my application will work on it...I tried to use your DEE example, so that when the user right click files in windows explorer and Open with my application, the new instance send to the old one the name of the file...The problem is that this is working when i select few number of files, but once i select lots of files (above 20 OR 50), i get the following Error :

    Foreign application won't perform DDE method or operation

    Do you have any idea to solve it ?
    Thanks for listing all the details in the Mail..

    Well the simple answer is .. the new instance will keep prompting the original instance of the application with DDE requests, however as the original app starts proccessing the requests, the reply time for each successive DDE request will increase. until eventualy it times out.

    Two things to do..
    Slow down the rate of sending the DDE requests. (perhaps add a timer and send a request at a rate of ~ 100- 200 ms..
    Or.
    Wait until all DDE Requests have been sent the start the proccess of opening all the files.

    If at all Posible sending me the VB6 Source so that i can look over. You can get hold of me on GremlinSA

    Gremmy....
    ____________________________________________

  5. #45

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Thanks a lot for this explication, now i can understand where the problem comes from, but to solve it, i don't know how to apply the 2 suggestions that you proposed, because the requests come from the windows context menu almost, except if you mean that on form load i add a timer that hide my form from user , hold on some time, send the request, then unload the instance ... instead of directly sending the request.
    Anyway, i will send you the source code it's gonna be better so that you see exactly what is going on....Can you send me in private your email in wich i can send you the source code ?

    thanks a lot again for your reply

  6. #46
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Add application to files context menu and send selected files as parameters

    Ok
    I've viewed the project you sent through to me...

    The number one thing i noticed is that you using recursive subs to parse all files from all sub directory's.. depending on how deep the directory's run, this can take quite some time..

    AND .. VB6 is single threaded.. (and before anyone bites me for it, Multi-threading is accomplished by incorporating API Calls)
    so while your application is 'Processing' the first DDE call, the rest wait until its finished, forming a long que, eventually the last ones will time out...

    Looking at your code i have two possible solutions..

    1) .. let the second instance of the application do all the hard work (Parse all the sub directory's) and DDE over the resulting CSV file list.

    2) .. When the First DDE request comes in, Add it to a list, start a 1 second timer (or even possibly less) .. Any further DDE requests are added to the list, and the timer is reset. when the time has expired then start parsing the files one request at a time...

    My personal opinion would be to use option 1..

    Gremmy....
    ____________________________________________

  7. #47

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Thanks for your reply !

    But the problem is happening in all cases even when entering the if related to files only not folders ...

    Just as reminder : i added 2 keys to the windows context menu, one that shows when user right click any file and the second one shows when user right click any folder..

    So the error occurs in both case, even if user just right clicked on files only (not any folder selected), as i said above when the number of files is important (more than 20-30 for expl) the error occurs.....

    here is the part for example , in wich the dde is not working and am not using anything recursive, i am adding the file name to the listbox called lstfiles and adding the short file name, to the listbox called LstShortFilesNames ...
    maybe the function ExistantElement () is considered as slow because it searchs if the file exists or not in the listbox before adding it (But no recursion at all in this part)


    The folder part that you are talking about is in the "else" (where i may use the recursion).....but in the files part i make almost nothing just checking if item exists, if not, adding short and long file name to 2 different listboxes and it's not working !

    vb Code:
    1. If sCmdStr(1) = "f" Then
    2. 'Addin a file
    3.  
    4. If Not ExistantElement(lstFiles, sCmdStr(0)) Then
    5. lstFiles.AddItem (sCmdStr(0))
    6. LstShortFilesNames.AddItem (GetDirOrShortFileName(sCmdStr(0), "file"))
    7. End If
    8.  
    9. 'here is the folder part you are talking about that may include recursion,
    10. 'but not all the times depends on the chkSelSubFolders.value !
    11.  
    12. Else
    13.     'Adding Files from folder
    14.         If sCmdStr(1) = "d" Then
    15.             Dim FolderFiles() As String
    16.             If frmOptions.chkSelSubFolders.Value = 1 Then
    17.                     FolderFiles = ListFiles(sCmdStr(0), True)
    18.                          Else
    19.                     FolderFiles = ListFiles(sCmdStr(0), False)
    20.             End If
    21.            
    22.             For i = 0 To UBound(FolderFiles)
    23.            
    24.                  
    25.                 If Not ExistantElement(lstFiles, FolderFiles(i)) And FolderFiles(i) <> "" Then
    26.                          
    27.                      lstFiles.AddItem (FolderFiles(i))
    28.                      LstShortFilesNames.AddItem (GetDirOrShortFileName(FolderFiles(i), "file"))
    29.                
    30.                 End If
    31.            
    32.             Next i
    33.    
    34.    
    35.         End If
    36.        
    37. End If

    After reading your comments, i think that even this part is too slow when you have a big number of files.

    vb Code:
    1. lstFiles.AddItem (sCmdStr(0))
    2. LstShortFilesNames.AddItem (GetDirOrShortFileName(sCmdStr(0), "file"))
    3.  
    4. 'GetDirOrShortFileName(sCmdStr(0), "file") is taking a path and returning the
    5. 'file short name !


    So please can you check again and let me know do you suggest to solve it ? and in case you can give me details where should i start the timer and where to stop it in the code, in case the solution is the timers and in case the solution is the other one, than where to let the instance make the hard job ?at what even and where exactly in the code ?



    NB: the recursion is only when i have
    vb Code:
    1. ListFiles( string, True)
    thanks again

  8. #48

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    I made tests after a question from vb5prgrmr and here is what i could notice !

    CASE 1 : APPLICATION IS NOT RUNNING

    I right clicked 50 files and made Open with my application,All is good, they were added to the listbox

    I right clicked 450 files and made Open with my application, After the file 286, i started getting the error message for all the rest of files (Lots of error messages to close lol)

    I right clicked after it 300 files and made Open with my application, the files were added without any error

    I right clicked 345 files,same thing, no problem files were added

    I right clicked 356 files and tried to add them, so 28 files were added to the listbox, and got error for all the rest

    I right clicked 350 files and tried to add them, so 96 files were added to the listbox, and got error for all the rest


    I right clicked 346 files and tried to add them, so 83 files were added to the listbox, and got error for all the rest


    I right clicked 345 files again and tried to add them, so 83 files were added to the listbox, and got error for all the rest


    I right clicked 344 files again and tried to add them, so also 83 files were added to the listbox, and got error for all the rest


    I MADE AGAIN After a half Hour tried to right click 50 files to open with my application, and this time only 4 were added to the listbox and got error message for all the rest !


    CASE 2 : APPLICATION ALREADY RUNNING

    I made also many tests, i could sometimes add 6 files on times with no error, sometimes even at 5 files i get the error, sometimes at 8, sometimes adding 10 files cause the error ...what is sure is that i never got it when i add <= 3 Files

  9. #49

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    I am trying to think about the solutions that you proposed but am not understanding well

    Quote Originally Posted by SAGremlin View Post
    1) .. let the second instance of the application do all the hard work (Parse all the sub directory's) and DDE over the resulting CSV file list.
    So instead of making the work on link_execute i make it on form_load when a new instance is opened ?
    But i don't think this will solve the problem cuz as i said, the problem is not only when i have folders, but even if i am simply adding files !
    And it happened also with a bigger number of files, when i test it with the code of your tutorial so the problem is not the code but the speed !I mean the main program is getting lots of link_execute on time and unable to make them!
    [B]Is there a way, to tell each new instance Wait Untill previous one finish it's work than you start your job ?[/B]

    Quote Originally Posted by SAGremlin View Post
    2) .. When the First DDE request comes in, Add it to a list, start a 1 second timer (or even possibly less) .. Any further DDE requests are added to the list, and the timer is reset. when the time has expired then start parsing the files one request at a time...
    So let us say i added a timer of 1 second at the beginning of link_execute, and at the end i reset it, then what should i do ? i didn't understand well the solution ? how to detect that i finished getting commands from all instances and that now i can start processing ?

  10. #50

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    The reply in this thread wasn't bad, please can you check my 2 questions to avoid that i repeat them here, maybe you can help, i am still facing these 2 problems

    http://www.vbforums.com/showpost.php...42&postcount=9

    http://www.vbforums.com/showpost.php...6&postcount=10

    I hope you can help and thanks for your support again

  11. #51

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Please anyone has an answer to these 2 questions ? Maybe i had to keep them in this thread so that people can see and reply, so i will copy them again , please if anyone has an answer or any hint ?

    1) i would like to know if there is a way to detect that all files names are transfered (all instances finished from transfering the files name) - very important for me because i need to know that the listbox received all the files names, before i start working on the files


    2) if the user closed the windows explorer from which he right click on the files to send to my application, even if the program.exe(main instance) is still showing (not closed), the transfer of files name stop, do you have an idea how to solve this ? Programs like winzip, if the user closed the windows explorer, show a dialog box like if the files continues beeing transfer

  12. #52
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Add application to files context menu and send selected files as parameters

    The only last thought that I have is that when you recieve these files from the DDE link in the existing program, is that you just make a list of those files and wait until you are no longer recieving those DDE links before you take action on those files.


    Good Luck
    Option Explicit should not be an Option!

  13. #53

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Quote Originally Posted by vb5prgrmr View Post
    The only last thought that I have is that when you recieve these files from the DDE link in the existing program, is that you just make a list of those files and wait until you are no longer recieving those DDE links before you take action on those files.


    Good Luck

    thanks man, that's exactly what i want, but my question was how to detect that am not receiving anything anymore ? If i know how, i wouldn't post the question lol
    By the way, i am no longer using DDE i found that using send message API is better , but the idea is the same, how to detect that am not recieving anymore the files and that the list is complete ?
    If you can tell me how in DDE , even if it's not the same way as for SendMessage api

    thanks again

  14. #54
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Add application to files context menu and send selected files as parameters

    Well how are you doing it with sendmessage? Using a hidden textbox? Change event>Disable/enable timer (1000) set variable with GetTickCount API, add file to list/string/array>timer event>Check to see if last file sent is > GetTickCount API - 1000 (one second ago or greater last file was recieved).

    I believe something like this if done efficiently might solve your problem...


    Just a thought...





    Good Luck
    Option Explicit should not be an Option!

  15. #55

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Thank you,

    Nope i am not using a hidden textbox.

    At the beginning i was using the SendMessage with WM_COPYDATA based on the Code provided by Xiphias3 Here that shows how to pass a string from an application to it's primary instance. This code works good

    Then LaVolpe passed me in this thread a usefull link that shows how to use WM_COPYDATA to pass an array of strings instead of simple strings ... Didn't try it yet, but it's so similar to first one, so it has to work and That's why i am going to do today, because with this way, i will be able to make more work in the instance before it passes the file name to the primary instance, so that the primary instance get the less possible job to do wich is good because it will receive many Send message if the user selects many files.
    Now all that the primary instance has to do, is to check if the file exists in the list or not, if not than it adds it...Once all files are added, here the primary instance start processing them....
    So To go back to my question, you suggest me to use timers ? How to manage them ? i mean what is the part that i have to do inside the timer ? when to set it's value to 1000 and when to turn it off 0 ?(i didn't understand well your previous post about timers)

    Thanks Again to all of you for your support

  16. #56
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Add application to files context menu and send selected files as parameters

    When you recieve the data is when you get the current time (GetTickCount API if you wish). This is also when you enable your timer or other non resource using timer (SetWaitableTimer). You would also store the information into whatever method you have decided upon.

    Then when the timer goes off, you check the time to see if 1 second has pass since the last time you recieve information. If so, then turn off the timer and do your thing. If not, wait for the timer to go off again.



    Good Luck
    Option Explicit should not be an Option!

  17. #57

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Quote Originally Posted by vb5prgrmr View Post
    When you recieve the data is when you get the current time (GetTickCount API if you wish). This is also when you enable your timer or other non resource using timer (SetWaitableTimer). You would also store the information into whatever method you have decided upon.

    Then when the timer goes off, you check the time to see if 1 second has pass since the last time you recieve information. If so, then turn off the timer and do your thing. If not, wait for the timer to go off again.



    Good Luck
    Thanks for your reply, sorry but i am a bit confused...i am not understanding why i need the timer if i am already using the GetTickCount API ?

    Let us say i receive the data in the Public Function WndProc
    here i should get the time with GetTickCount ?
    Then you said i enable the timer for 1 second ?
    then i continue working inside the Function WndProc
    if after 1 second the timer finished i check again the time with GetTickCount to see if 1 second has pass ? why ? if the timer is set to 1 second and it fires that means the 1 second pass already so why to check again with the GetTickCount ?


    Please can you explain again because it seems i ddin't understand your algorithm !

  18. #58
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add application to files context menu and send selected files as parameters

    If your Timers Interval is set to 1000, you don't need GetTickCount - that would only be useful to get extra accuracy (which isn't important in this case).

    However, rather than just Enable the timer, you will need to Disable it and then Enable it (so that the Interval restarts).

  19. #59
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Add application to files context menu and send selected files as parameters

    Si's got it right...

    My thought was the first message is recieved and the timer starts waiting upon its event to fire all the while you are processing those messages and setting the value of a variable with get the GetTickCount API. It was really in the hopes for program responsiveness because when the event fires you could test the difference between the message recieved GetTickCount and the timers GetTickCount and if the interval was large enough (100, 150, 250 milliseconds), then you could start processing. The thought was, was that you would have recieved all the file names by the time 1 second was up but just in case if the threshold was to low as in you might still be recieving messages, then you would continue to wait. But then again I really did not explain it well previously.

    Now, back to Si's version. Perhaps to make the program more responsive you might want to play with the timer settings and reduce the interval of the timer.



    Good Luck
    Option Explicit should not be an Option!

  20. #60

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Thanks man, please confirm me if i got you ,

    What you say is that, each time i enter the part in wich i receive the data, i disabled the timer, i make what i have to do, once finished i enable it with 1 seconds value...
    if the timer fires this means i spent 1 second without getting any message from my application and that i can start processing the files (the timer will include the call to the procedure that will process the passed files) .
    did i get it well ?
    If yes please tell me, do i use the timers or the API, if api is better i am ready to use it, i need the better solution, because i didn't make this part yet, so i can do it as it should once for all instead of starting something and discovering that i had a better choice late...

    waiting your suggestion

  21. #61
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add application to files context menu and send selected files as parameters

    You have got it.

    The timer will be fine... for something like this using API's isn't worth the effort.

  22. #62

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    thank you
    Is there anyway to let him wait less time than 1 second and make sure that am not losing any message ? something like estimate the time i should wait instead of getting a constant of 1 second ?

  23. #63
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Add application to files context menu and send selected files as parameters

    Well, the more you build into your recieve message function, the longer it will take to execute and thus increase the likelyhood that you will backup the message que to your application....

    Okay where is it...

    Okay, can't find it....

    Must be because I'm using the wrong keywords but I thought this site's codebank had an alternative to using doevents and what it did was to read and process messages that were in the que and the thought was.... (does 2+2=4 yet?) the thought was you might be able to use it... but then again...

    Okay, I'm back from that thought tangent... Now where was I. Oh yeah! The more you put in there the longer it will take...

    Okay, here comes another tangent.... THREADS!!!!

    Whew! Now hopefully this tangent business is all over with... ...and so you would build up the messages que. You want that recieving piece of code to operate as fast as possible. I mean it is possible to come up with some sort of averaging algorithm that takes/uses GetTickCount along with some addition and division or you could like I posted earlier, reduce the timers interval to less than 1 second...



    Good Luck
    Option Explicit should not be an Option!

  24. #64

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    I am keep advancing on my application with your help, please tell me is there a way to add a relative path to the registry for my application ? or i should add a full path like D:\Documents and Settings\MyUser\Desktop\Myapplication.exe ?
    i can't add simply Myapplication.exe ? so that wherever is my application windows will locate it and open it ?
    I am asking because i find this better and i found in the registry some values like %root etc...so i said maybe there is a way to specify a relative path or simply the name of the exe....
    waiting your reply and thanks in advance

  25. #65
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add application to files context menu and send selected files as parameters

    There isn't a way to leave out the path, and even if there was it wouldn't be a good idea... not only would it take several minutes for Windows to find it, but also if there was more than one program with the same name how would Windows know which one to use?

    The things you have seen like &#37;system% etc are actually full paths - they are just a shorter way of writing them (and are only available for certain special folders).

    Using a path written out in full is the best thing you can do, because it is easier and safer than the alternatives.

  26. #66

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    Guys, due to your help i could advance a lot on my application..10x a lot....Once i finish it, i will close this thread, but there is something "weird" maybe i am getting :

    In fact i added my application as you told me to the :

    HKEY_CLASSES_ROOT\*\Shell\Open With MyProg


    All is working good,i mean the user right click on any file, he got my program name on windows context menu and my application receive the file name ...great !

    but i noticed that if i double click on some files with extensions that windows haven't associate them to some applications, my programme is launched, any idea why ? This is not happening with all extensions by the way, i could get this with .swf, or .exp or .lib ..
    i don't have an application installed to open them, so when the user double click instead of getting the windows menu that usually tells, select an application to open this file with, i get my program launched !
    I tried with other extensions like .abc, .asd etc.. and it's not doing this, i am getting the normal windows that tell me to select with wich application i want to open !

    Any idea why ? and how to avoid this ?

  27. #67
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add application to files context menu and send selected files as parameters

    Right-click on a file, and see what option is shown in bold - that is the action that will be performed when you double-click on the file.

    I don't know enough about Windows shell integration to know what caused the current situation, or how to fix it.

  28. #68

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Add application to files context menu and send selected files as parameters

    thanks si_the_geek, i am not finding a solution for that, do you suggest me to post it on different forum than vb or different section ?
    I noticed the following : for the file type that they are openning with my application .swf, .lib, etc...as you said if i make right click, i see on bold my application appearing, but for other file type that they are not opened with my application, my application doesnt appear on bold, but the default "Open" ...

    I noticed also, that in the HKEY_CLASSES_ROOT\*\Shell\ , there is only my application, but if i added another one that has a name with alphabetical order less than mine ,then, when you right click the .swf, .lib etc... windows try to open them with the new added one , not my application,

    so to conclude, it seems windows is automatically trying to open some extensions with the first key that exists in the registry HKEY_CLASSES_ROOT\*\Shell\ ....

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width