CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2006
    Posts
    221

    Getting file name and extenssion

    Dear All,

    When we open a doc file and ms office is not installed on system then window open a screen to ask this file with different installed software or telling the information that software is not present.
    At this time I want to know the file information like file name and extension. So that i could be able to open this with my software.

    Please tell me how can i get this in vc++.

    Expecting a favorable reply.

    Thanks in advance

  2. #2
    Join Date
    Apr 2008
    Posts
    725

    Re: Getting file name and extenssion

    please explain again what you are trying to do? open something with your software? why not just browse to your exe file and double-click?

  3. #3
    Join Date
    May 2009
    Location
    China
    Posts
    8

    Re: Getting file name and extenssion

    You mean that you want to open the file with your own software automatically if windows can't identify it? How about specifying the file's default handling software?

  4. #4
    Join Date
    Nov 2006
    Posts
    221

    Re: Getting file name and extenssion

    oops I thought that I am explaining this in the simplest language.
    I try to clear out in simple way.

    When I open a file and there is no software to open this a window comes that ask the user to open this file with other software. Means would have all the file information which is necessary to open the file like complete file name.

    I want to know this information only.
    Thanks for your reply

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Getting file name and extenssion

    When that file pops up, browse to your executable and select it for opening the document. After that, windows will shown it in the default list. And you can check to always open with your document.

    However, you can register your application to be the default to open some document.
    http://biajee.blogspot.com/2006/02/f...ion-under.html
    http://social.msdn.microsoft.com/For...c-eb012267eb37
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Nov 2006
    Posts
    221

    Re: Getting file name and extenssion

    Quote Originally Posted by cilu View Post
    When that file pops up, browse to your executable and select it for opening the document. After that, windows will shown it in the default list. And you can check to always open with your document.

    However, you can register your application to be the default to open some document.
    http://biajee.blogspot.com/2006/02/f...ion-under.html
    http://social.msdn.microsoft.com/For...c-eb012267eb37

    Thanks for your reply cilu but this is not my answer which I am looking.
    I dont want to browse these file, I need to trace the file open command in vc++ for all files means which file user going to open and its relative software is not present.

    Or is there any way to trace and modify the file open dialog.

    Thanks
    Last edited by sulabh120881; May 12th, 2009 at 01:00 AM.

  7. #7
    Join Date
    Nov 2006
    Posts
    221

    Re: Getting file name and extenssion

    Hi All
    Please help to resolve this issue if possible.

    Thanks

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Getting file name and extenssion

    I think what he's asking is how does the operating system know which applications may be able to open the specific file and how can he get the same list.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting file name and extenssion

    It seems he is asking for more of a dynamic solution where his program gets notified when a file association isn't present (but before the browse dialog has been presented).

    I don't know of any direct solution, but I do know how the file associations work so maybe this will be helpful.

    There isn't a list of these associations per say, but they are all stored in the registry. It's a two step process to determine if there is a file association for a given file extension.

    The first part of the association is stored in the registry under:
    Code:
    HKEY_CLASSES_ROOT\<.ext>
    where <.ext> is the file extension. Under this key, there will be a 'pointer' to the second part of the association. This is found under the (Default) value.

    The second part of the association is stored in the registry under:
    Code:
    HKEY_CLASSES_ROOT\<2nd>\shell\Open\command
    The (Default) value under this key is what contains the path to the executable used to open the file.

    So given this information you simple look into the registry for the first part of the file association, grab the default value and then look for the 2nd part of the file association. If the file extension isn't present during the first registry lookup, then Windows is going to prompt the user. Likewise, if the 2nd part of the association isn't found in the registry or the executable listed in the default value doesn't exist, then Windows will again prompt the user.

    Let's look at a couple of examples:

    Example 1
    Consider a Word document with a .doc extension. On my machine, it's opened in Winword.exe. To find this, we look for the 1st part of the association:
    Code:
    HKEY_CLASSES_ROOT\.doc
    The (Default) value for this key is:
    Code:
    Word.Document.8
    To find the second part of the association, we use this value and do another registry lookup:
    Code:
    HKEY_CLASSES_ROOT\Word.Document.8\shell\Open\command
    Finally the (Default) Value gives us:
    Code:
    "D:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde
    Example 2
    Let's look for a .txt file. On my machine, this is opened by notepad.

    Again, to find this, we look for the 1st part of the association:
    Code:
    HKEY_CLASSES_ROOT\.txt
    The (Default) value for this key is:
    Code:
    txtfile
    To find the second part of the association, we use this value and do another registry lookup:
    Code:
    HKEY_CLASSES_ROOT\txtfile\shell\Open\command
    Finally the (Default) Value gives us:
    Code:
    &#37;SystemRoot%\system32\NOTEPAD.EXE %1
    A few comments:
    1) With regard to retrieving the default value. To do this, you'll want to open the registry key and read the value by passing in an empty string "". At first this is confusing because the natural tendency is to try to specify the value to read by passing in "Default" or "(Default)" or NULL. This won't work, so to read the default value, pass in "" (or the tchar equivalent of _T("")).
    2) There are two types of string values used in the value of the 2nd part. REG_SZ and REG_EXPAND_SZ. The latter value is expanded by the system with environment variables.
    3) Check out the CRegKey class from ATL. This class makes reading and writing the registry a snap. To use it, just include 'atlbase.h'. Some folks think that in order to use an ATL class, you need to register your app as a COM app. This is incorrect, as many of the ATL support classes can be used without registration - CRegKey is one of them. It's a small, lightweight class wrapper for the registry operations - check it out.
    Last edited by Arjay; May 14th, 2009 at 11:17 AM.

  10. #10
    Join Date
    Nov 2006
    Posts
    221

    Re: Getting file name and extenssion

    Thanks Arjay Sir, for your reply and ur valuable time.

    I am aware with the registry functionality But the problem is different. I dont want to look at registry, I need to trace file open commands(eg double click, right click and open, enter key press.. all these used to open files) for all files like .txt .jpg, wmv etc in my application. My application should know when a user is opening a file and what is the file name and path.

    I cant read this things from registry as I think.
    Is there any problem to getting my question please let me know.

    Looking for your valuable cooperation.

    Thanks to all of u for giving your time to this post.

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

Featured