임프랍니다.. 오늘은.. 좀 늦었습니다..
오늘의 팁은.. 자신의 프로그램 데이터파일 확장자를 레지스트리에 등록하기입니다.
많이들 보셨을겁니다. 물론 방법은 레지스트리에 등록하는 것입니다.
HKEY_CLASSES_ROOT에는 각 확장자의 연결 프로그램이 등록되어있는데, 여기다가
자신의 확장자명을 써넣고,
그 아래 shell\open\command 에다 실행할 프로그램을 써넣으면 되죠.
소스를 보실까요?
// C++ 코드
#include
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegistry *reg = new TRegistry;
reg->RootKey = HKEY_CLASSES_ROOT;
reg->LazyWrite = false;
// Add Program Support
reg->OpenKey(".imp\\shell\\open\\command", true);
// Invoke the program passing the file name as the first parameter
reg->WriteString("", "C:\\Windows\\notepad.exe %1");
// Add Icon Display
reg->CloseKey();
reg->OpenKey(".bor\\DefaultIcon", true);
// Use the first icon in the executable to display
reg->WriteString("", "C:\\Windows\\notepad.exe, 0");
reg->CloseKey();
delete reg;
}
// 델파이 코드
uses Registry;
procedure TForm1.Button1Click(Sender: TObject);
begin
with TRegistry.Create do
begin
RootKey := HKEY_CLASSES_ROOT;
LazyWrite := false;
// Add Program Support
OpenKey('.imp\shell\open\command', true);
// Invoke the program passing the file name as the first parameter
WriteString('', 'C:\Windows\notepad.exe %1');
// Add Icon Display
CloseKey;
OpenKey('.bor\DefaultIcon', true);
// Use the first icon in the executable to display
WriteString('', 'C:\Windows\notepad.exe, 0');
CloseKey;
Free;
end;
end;
간단하지요?
이렇게 하면 확장자 .imp를 가진 화일을 더블클릭하면 메모장이 실행됩니다.
먼저 해당확장자를 가진 화일을 오픈하려고 시도했을때 실행될 연결된 어플을
등록하고, 그 확장자를 가진 화일에 나타낼 아이콘을 등록한거죠.
근데.. 보자...
이런건 아무데나 다 나오는 흔한 팁이잖아요? 그래서...
약간 플러스 알파를... ^^
일부 프로그램을 보면, 특정 확장자가 아니라 확장자에 관계없이 무조건 탐색기의
컨텍스트메뉴에 등록시켜놓은게 있지요? 대표적으로 WinZip 같은게 있구요, 그
외에도 많은 프로그램이 자기 프로그램을 컨텍스트메뉴에 항상 등록해놓고 있죠.
이걸 어떻게 했을까.. 하고 찾아봤는데, 한가지 방법은 알아냈습니다.
위와같은 HKEY_CLASSES_ROOT 아래에 확장자 이름이 아닌 "*" 이란 키를 만들어
그 아래에 위와 동일한 방법으로 연결 프로그램을 써넣는겁니다.
다시 말해, 컨텍스트메뉴에 제가 만든 "c:\\임프만세.exe"를 항상 등록해놓고
싶다면, C++에서는,
reg->OpenKey("*\\shell\\open\\command", true);
하고,
reg->WriteString("", "C:\\임프만세.exe %1");
라고 하면 된다는거죠. 잘 되더군요.
델파이에서는,
reg.OpenKey(.*\shell\open\command', true);
한 후,
reg.WriteString('', 'C:\임프만세.exe %1');
근데.. WinZip은 꼴에 다른 방법을 쓰더군요.. *항목에 WinZip은 등록하지
않습니다. 쩝..
좀더 찾아보고 알게되면 알려드리도록 하지요.
그럼.. 오늘도, 모두들 도움되시길 바라면서, 이만...
독립문에서 임펠리테리였습니다.