Win32 , C++

Registering an Application to a URL Protocol

김모작자 2006. 8. 4. 18:53
간혹 인터넷을 하다 보면
http, ftp 등 익숙한 프로토콜 이름이 아닌 mms, rtp, rts, edonkey 등 못 보던 프로토콜 이름을 봤을 것이다. 해당 링크를 클릭하면 특정 프로그램이 반응하도록 되어 있는데, 이 기능을 구현하는 방법을 설명해보겠다 -0-/

아래 내용, 제목은 MSDN 이 출처이니 아쉬운 사람은 더 찾아 보도록!

protocol
://URL/sub/sub/file
웹페이지에 해당 protocol 이 포함된 링크가 포함되었을 때 반응하는 어플리케이션 정의

응응프로그램이 특정 URL 프로토콜을 취급하도록 하려면, HKEY_CLASSES_ROOT 레지스트리에 적정 키와 값을 추가해야한다

새로운 레지스트리 키는 추가될 특정 protocol scheme(http 같은)와 일치해야 한다. 예를 들어, note: 라는 프로토콜을 추가하려면, HKEY_CLASSES_ROOT 에 추가될 키 이름은 note 여야한다.
이 레지스트리 키에 (기본값) 에는 새로운 프로토콜의 이름이 들어가야 하고, URLProtocol 문자열 값에는 프로토콜의 정보나 빈 문자열이 들어가야 한다. 그리고 하위에 DefaultIcon 이 꼭
추가되어야 한다. DefaultIcon 의 (기본값)에는 이 프로토콜에 사용할 아이콘으로 사용될 파일 이름이 들어가야 한다. Shell 키도 반드시 들어가야 한다. 그리고 하위에 open 등의 DDEEXEC 명령이
들어가야 한다.
------------ MSDN 원문 -------------------------------------------------
To enable an application to handle a particular URL protocol, you must add a new key, with the appropriate keys and values, to the registry in HKEY_CLASSES_ROOT.

The new registry key must match the protocol scheme that is being added. For instance, to add the protocol note:, the key added to HKEY_CLASSES_ROOT should be note. Under this new key, the Default string value should be the name of the new protocol, and the URLProtocol string value should contain either protocol-specific information or an empty string. Also under the new key, a DefaultIcon key and a shell key should be added. The Default string value under the DefaultIcon key must be the file name to use as an icon for this new URL protocol. Under the shell key, a key using a verb (such as open) should be added. A command key and a DDEEXEC key can be added under the key using a verb. The values under the command and DDEEXEC keys are used to call the application.

The following example shows which registry values must be added to register a new application (notepad.exe in this example) to handle a new URL protocol (note:).

[HKEY_CLASSES_ROOT]
  [note]
    (Default) = "URL:Note Protocol"
    URL Protocol = ""
    [DefaultIcon]
       (Default) = "notepad.exe"
    [shell]
       [open]
          [command]
            (Default) = "c:windowsnotepad.exe %1"

By adding these settings to the registry, attempts to navigate to URLs such as note:c:myfile.txt would launch Notepad to edit the file c:myfile.txt. Of course, all the commands supported under ShellOpen are supported, including DDEEXEC (in other words, "command" is not the only key you can put under the verb).