Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to invoke WordPad in VB6 app

pw17pw17 Posts: 5Member
This is something that should be simple but is not. I cannot invoke WordPad for file that I created. The file type can be anything that I want it to be if that helps. The app has to run on all platforms present, past and future(Win9x +).
Note that I can invoke Notepad with Shell with no problem. And Shellex brings up Word which garbles up the file due to the long line lengths. Shell to Wordpad gets a 'file not found' error msg.
This app has to run on user systems across the universe so I cannot manually manipulate the registry.

How can I get Wordpad to come up, simply ??

Comments

  • HackmanCHackmanC Posts: 441Member
    [code]
    Try:
    Shell ("C:Archivos de programaWindows NTAccesorioswordpad.exe "" """)

    Private Sub MyShell(strParamDocument as String)
    Dim strProgram as String
    Dim strDocument as String

    If Dir(strParamDocument) = "" Then
    MsgBox "File not found."
    Else
    strProgram = Chr$(34) & "C:Program FilesWindows NTAccesorieswordpad.exe" & Chr$(34) ' Where Chr$(34) = "
    strDocument = Chr$(34) & strParamDocument & Chr$(34)
    End If

    Shell (strProgram & " " & strDocument)
    End Sub
    [/code]

    If you ensure the path is surrounded by ", you can be sure it will find it (Of course only if it exists).
    I don't remember the api function that gets the program file name to run for a specific file type, someone could refresh my memory, please?
    ----
    : This is something that should be simple but is not. I cannot invoke WordPad for file that I created. The file type can be anything that I want it to be if that helps. The app has to run on all platforms present, past and future(Win9x +).
    : Note that I can invoke Notepad with Shell with no problem. And Shellex brings up Word which garbles up the file due to the long line lengths. Shell to Wordpad gets a 'file not found' error msg.
    : This app has to run on user systems across the universe so I cannot manually manipulate the registry.
    :
    : How can I get Wordpad to come up, simply ??
    :
    :

  • pw17pw17 Posts: 5Member
    Ahhh, right away you are making an assumption about the location of WOrdpad. Remember my comment: This app has to run on user systems across the universe !!!

    I do not know the OS of the user nor where WOrdpad is located nor do I want to have to fix the damn thing for every new OS that comes into the world.

    Also, the ShellEx will open by a filetype, however, if the filetype is .Doc and the user has Word installed, then this is no good. Or, I can define my own filetype, but then I have special instructions on installation to the user to go manually open the special file, and manipulate Explorer to select Wordpad. THis I do not want to do.

    So, is there some way to invoke Wordpad without operating system dependencies as to its location ??
    PW



    : [code]
    : Try:
    : Shell ("C:Archivos de programaWindows NTAccesorioswordpad.exe "" """)
    :
    : Private Sub MyShell(strParamDocument as String)
    : Dim strProgram as String
    : Dim strDocument as String
    :
    : If Dir(strParamDocument) = "" Then
    : MsgBox "File not found."
    : Else
    : strProgram = Chr$(34) & "C:Program FilesWindows NTAccesorieswordpad.exe" & Chr$(34) ' Where Chr$(34) = "
    : strDocument = Chr$(34) & strParamDocument & Chr$(34)
    : End If
    :
    : Shell (strProgram & " " & strDocument)
    : End Sub
    : [/code]
    :
    : If you ensure the path is surrounded by ", you can be sure it will find it (Of course only if it exists).
    : I don't remember the api function that gets the program file name to run for a specific file type, someone could refresh my memory, please?
    : ----

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : Ahhh, right away you are making an assumption about the location of WOrdpad. Remember my comment: This app has to run on user systems across the universe !!!
    :
    : I do not know the OS of the user nor where WOrdpad is located nor do I want to have to fix the damn thing for every new OS that comes into the world.
    :
    : Also, the ShellEx will open by a filetype, however, if the filetype is .Doc and the user has Word installed, then this is no good. Or, I can define my own filetype, but then I have special instructions on installation to the user to go manually open the special file, and manipulate Explorer to select Wordpad. THis I do not want to do.
    :
    : So, is there some way to invoke Wordpad without operating system dependencies as to its location ??
    : PW
    :
    :
    :
    : : [code]
    : : Try:
    : : Shell ("C:Archivos de programaWindows NTAccesorioswordpad.exe "" """)
    : :
    : : Private Sub MyShell(strParamDocument as String)
    : : Dim strProgram as String
    : : Dim strDocument as String
    : :
    : : If Dir(strParamDocument) = "" Then
    : : MsgBox "File not found."
    : : Else
    : : strProgram = Chr$(34) & "C:Program FilesWindows NTAccesorieswordpad.exe" & Chr$(34) ' Where Chr$(34) = "
    : : strDocument = Chr$(34) & strParamDocument & Chr$(34)
    : : End If
    : :
    : : Shell (strProgram & " " & strDocument)
    : : End Sub
    : : [/code]
    : :
    : : If you ensure the path is surrounded by ", you can be sure it will find it (Of course only if it exists).
    : : I don't remember the api function that gets the program file name to run for a specific file type, someone could refresh my memory, please?
    : : ----
    :
    :

    So retrieve the information from the registry! That's always the same!

    Greets...
    Richard

  • pw17pw17 Posts: 5Member

    : So retrieve the information from the registry! That's always the same!
    :
    : Greets...
    : Richard
    :
    Hmmm, Richard. That sounds easy for you to say, but I don't have a clue about accessing the Registry from code(I've seen lots of stuff posted, but all of it is uncommented, therefore, unreadable and unusable).
    Accessing the Registry is probably the only way. Can I be sure that the registry will always look the same in the future?
    PW

  • kel1981bkel1981b Posts: 852Member
    [b][red]This message was edited by kel1981b at 2003-8-11 13:10:21[/red][/b][hr]
    :
    : : So retrieve the information from the registry! That's always the same!
    : :
    : : Greets...
    : : Richard
    : :
    : Hmmm, Richard. That sounds easy for you to say, but I don't have a clue about accessing the Registry from code(I've seen lots of stuff posted, but all of it is uncommented, therefore, unreadable and unusable).
    : Accessing the Registry is probably the only way. Can I be sure that the registry will always look the same in the future?
    : PW
    :
    :
    [blue]Using Microsoft product, you should not be sure in future. That's for sure [/blue]


  • GenjuroGenjuro Posts: 913Member
    [b][red]This message was edited by Genjuro at 2003-8-12 3:6:0[/red][/b][hr]
    : [b][red]This message was edited by kel1981b at 2003-8-11 13:10:21[/red][/b][hr]
    : :
    : : : So retrieve the information from the registry! That's always the same!
    : : :
    : : : Greets...
    : : : Richard
    : : :
    : : Hmmm, Richard. That sounds easy for you to say, but I don't have a clue about accessing the Registry from code(I've seen lots of stuff posted, but all of it is uncommented, therefore, unreadable and unusable).
    : : Accessing the Registry is probably the only way. Can I be sure that the registry will always look the same in the future?
    : : PW
    : :
    : :
    : [blue]Using Microsoft product, you should not be sure in future. That's for sure [/blue]

    I don't really think so, but anyway where would you look in the registry?
    Not to mention that Wordpad could be not installed.
    The easy way is scanning the disks and search for it (the "program files" folder is localized), but it would be way too slow.

    If I were you and wished to keep things simple, I'd use SaveSetting and GetSetting to store the info about where Wordpad is.
    The idea is:
    1) you try GetSetting to retrieve info about Wordpad.
    2) if GetSetting returns something meaningful (not the default value), then the program already knows where Wordpad is, and you access it from that location, and the problem's solved.
    3) If GetSetting returns the default value, then it is the first run of your program, so you scan the disk with Dir, and find it, then use SaveSetting so you won't scan the disk(s) again.

    Keep in mind that you could (simpler still), otherwise, create a "Configuration" form (many, many, many programs use that), and let users set up that path for you (easier still, but it requires user's collaboration).
    After all, it's their disk, and you aren't supposed to know how they arrange it.
    Heck, even Internet Explorer has such a configuration menu in which you have to type in program paths, after all.

    In any case, keep that path stored in the registry using Get/SaveSetting, or in a text file in the program folder.
    It's handy, and people expect *not* to type in things twice.


  • kel1981bkel1981b Posts: 852Member
    : [b][red]This message was edited by Genjuro at 2003-8-12 3:6:0[/red][/b][hr]
    : : [b][red]This message was edited by kel1981b at 2003-8-11 13:10:21[/red][/b][hr]
    : : :
    : : : : So retrieve the information from the registry! That's always the same!
    : : : :
    : : : : Greets...
    : : : : Richard
    : : : :
    : : : Hmmm, Richard. That sounds easy for you to say, but I don't have a clue about accessing the Registry from code(I've seen lots of stuff posted, but all of it is uncommented, therefore, unreadable and unusable).
    : : : Accessing the Registry is probably the only way. Can I be sure that the registry will always look the same in the future?
    : : : PW
    : : :
    : : :
    : : [blue]Using Microsoft product, you should not be sure in future. That's for sure [/blue]
    :
    : I don't really think so, but anyway where would you look in the registry?
    : Not to mention that Wordpad could be not installed.
    : The easy way is scanning the disks and search for it (the "program files" folder is localized), but it would be way too slow.
    [blue]Just one comment. Like pw17 said " Remember my comment: This app has to run on user systems across the universe !!!" So searching for "Program files" won't be that easy because name of this folder depends on which lingvistical version of Windows is used. Remember the HackmanC example? It's in Spanish. People from country where I were born use Russian version of Windows. In all those cases that folder will have different name. So there is no way to norrow search to folder. Only file name will remain the same "wordpad.exe". Therefore file must be searched and that will make search quite wide and, because of that, slow [/blue]
    :
    : If I were you and wished to keep things simple, I'd use SaveSetting and GetSetting to store the info about where Wordpad is.
    : The idea is:
    : 1) you try GetSetting to retrieve info about Wordpad.
    : 2) if GetSetting returns something meaningful (not the default value), then the program already knows where Wordpad is, and you access it from that location, and the problem's solved.
    : 3) If GetSetting returns the default value, then it is the first run of your program, so you scan the disk with Dir, and find it, then use SaveSetting so you won't scan the disk(s) again.
    :
    : Keep in mind that you could (simpler still), otherwise, create a "Configuration" form (many, many, many programs use that), and let users set up that path for you (easier still, but it requires user's collaboration).
    : After all, it's their disk, and you aren't supposed to know how they arrange it.
    : Heck, even Internet Explorer has such a configuration menu in which you have to type in program paths, after all.
    :
    : In any case, keep that path stored in the registry using Get/SaveSetting, or in a text file in the program folder.
    : It's handy, and people expect *not* to type in things twice.
    :
    :
    :

  • GenjuroGenjuro Posts: 913Member
    [b][red]This message was edited by Genjuro at 2003-8-12 5:52:42[/red][/b][hr]
    : : [b][red]This message was edited by Genjuro at 2003-8-12 3:6:0[/red][/b][hr]
    : : : [b][red]This message was edited by kel1981b at 2003-8-11 13:10:21[/red][/b][hr]
    : : : :
    : : : : : So retrieve the information from the registry! That's always the same!
    : : : : :
    : : : : : Greets...
    : : : : : Richard
    : : : : :
    : : : : Hmmm, Richard. That sounds easy for you to say, but I don't have a clue about accessing the Registry from code(I've seen lots of stuff posted, but all of it is uncommented, therefore, unreadable and unusable).
    : : : : Accessing the Registry is probably the only way. Can I be sure that the registry will always look the same in the future?
    : : : : PW
    : : : :
    : : : :
    : : : [blue]Using Microsoft product, you should not be sure in future. That's for sure [/blue]
    : :
    : : I don't really think so, but anyway where would you look in the registry?
    : : Not to mention that Wordpad could be not installed.
    : : The easy way is scanning the disks and search for it (the "program files" folder is localized), but it would be way too slow.

    : [blue]Just one comment. Like pw17 said " Remember my comment: This app has to run on user systems across the universe !!!" So searching for "Program files" won't be that easy because name of this folder depends on which lingvistical version of Windows is used. Remember the HackmanC example? It's in Spanish. People from country where I were born use Russian version of Windows. In all those cases that folder will have different name. So there is no way to norrow search to folder. Only file name will remain the same "wordpad.exe". Therefore file must be searched and that will make search quite wide and, because of that, slow [/blue]

    [red]
    Exactly what I said: slow. That's why I suggested: do it once, and never again. I took that into account, but if you don't know where a program is, either you search for it in the whole disk(s), or you let a user type it in.
    Unfortunately, in this case, if you don't want your users to type it in, then you either have to search it in the disk or in the registry.
    Mind that in my Registry I am sure Wordpad is never mentioned - neither home nor in the office. My ".doc" and ".rtf" extensions open with either Word Viewer or Word, for instance. So, if the registry is not a sure way to determine whether it exists or not, only scanning the disk remains. That's why - I repeat myself - many programs ask the user to manually specify *where* a program is... better still: what program they want to use for a defined scope. For instance, I could probably select Word, since it does whatever Wordpad does, and more. Sure, it's slower... unless it's already opened. And it's my (user) choice anyway.
    [/red]

    : :
    : : If I were you and wished to keep things simple, I'd use SaveSetting and GetSetting to store the info about where Wordpad is.
    : : The idea is:
    : : 1) you try GetSetting to retrieve info about Wordpad.
    : : 2) if GetSetting returns something meaningful (not the default value), then the program already knows where Wordpad is, and you access it from that location, and the problem's solved.
    : : 3) If GetSetting returns the default value, then it is the first run of your program, so you scan the disk with Dir, and find it, then use SaveSetting so you won't scan the disk(s) again.
    : :
    : : Keep in mind that you could (simpler still), otherwise, create a "Configuration" form (many, many, many programs use that), and let users set up that path for you (easier still, but it requires user's collaboration).
    : : After all, it's their disk, and you aren't supposed to know how they arrange it.
    : : Heck, even Internet Explorer has such a configuration menu in which you have to type in program paths, after all.
    : :
    : : In any case, keep that path stored in the registry using Get/SaveSetting, or in a text file in the program folder.
    : : It's handy, and people expect *not* to type in things twice.
    : :
    : :
    : :
    :
    :



  • pw17pw17 Posts: 5Member

    Thanks to all who have replied to this posting. The solution is more difficult than I first imagined. I am using the following KLUDGE to get around the problem, but am not happy with it.
    iTask = Shell("notepad.exe " & sExecPath & "Fileout.Doc", vbNormalFocus)

    Sleep 20
    iRet = WindowFromPoint(Screen.Width / 2, Screen.Height / 2) 'get msgbox center!!we hope
    SendKeys "{Enter}", True

    pHandle = OpenProcess(SYNCHRONIZE, False, iTask)

    'This doesn't work!
    iRet = WaitForSingleObject(pHandle, INFINITE)

    iRet = CloseHandle(pHandle)

    In the above, I invoke Notepad then issue SENDKEYS to reply to the noxious msgbox to redirect to Wordpad. The msgbox flashes briefly then WOrdpad is invoked. Note that the WAITFORSINGLEOBJECT request gets invoked immediately so I have to hope that the user closes WOrdpad without my knowledge.

    I think the solution is to read the registry to find Wordpad(I would hope it is always there since Notepad redirects ok), or else to provide my own WOrdpad look-alike in my distribution. So far I haven't found anything.

    PW17


  • GenjuroGenjuro Posts: 913Member
    : Thanks to all who have replied to this posting. The solution is more difficult than I first imagined. I am using the following KLUDGE to get around the problem, but am not happy with it.
    : iTask = Shell("notepad.exe " & sExecPath & "Fileout.Doc", vbNormalFocus)
    :
    : Sleep 20
    : iRet = WindowFromPoint(Screen.Width / 2, Screen.Height / 2) 'get msgbox center!!we hope
    : SendKeys "{Enter}", True
    :
    : pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
    :
    : 'This doesn't work!
    : iRet = WaitForSingleObject(pHandle, INFINITE)
    :
    : iRet = CloseHandle(pHandle)
    :
    : In the above, I invoke Notepad then issue SENDKEYS to reply to the noxious msgbox to redirect to Wordpad. The msgbox flashes briefly then WOrdpad is invoked. Note that the WAITFORSINGLEOBJECT request gets invoked immediately so I have to hope that the user closes WOrdpad without my knowledge.
    :
    : I think the solution is to read the registry to find Wordpad(I would hope it is always there since Notepad redirects ok), or else to provide my own WOrdpad look-alike in my distribution. So far I haven't found anything.
    :
    : PW17

    [red]
    Mmmmh... what if Wordpad isn't installed?
    Besides, you can invoke like that Notepad (I mean, without the full path) since it's in your "Path" environment variable, but Wordpad isn't in the same folder, and probably is not inside the "Path" environment variable, either.
    Again, in my opinion, it would be way easier to create a "config" form and have the users fill it.
    Or provide your own "wordpad". Which isn't that hard either.
    [/red]
Sign In or Register to comment.