На главную

On-line справка по Win32 API

Написать письмо
БЕСПЛАТНАЯ ежедневная online лотерея! Выигрывай каждый день БЕСПЛАТНО!
Список всех статей A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z | Скачать Вниз

Resolving A Shortcut



An application may need to access and manipulate a shortcut that was created previously. This operation is referred to as "resolving" the shortcut.

The application-defined ResolveIt function in the following example resolves a shortcut. Its parameters include a window handle, a pointer to the path of the shortcut, and the address of a buffer that receives the new path to the object. The window handle identifies the parent window for any message boxes that the shell may need to display. For example, the shell can display a message box if the link is on unshared media, if network problems occur, if the user needs to insert a floppy disk, and so on.

The ResolveIt function calls the CoCreateInstance function and assumes that the CoInitialize function has already been called. Note that ResolveIt needs to use the IPersistFile interface to store the link information. IPersistFile is implemented by the IShellLink object. The link information must be loaded before the path information is retrieved, which happens later in the example. Failing to load the link information causes the calls to the IShellLink::GetPath and IShellLink::GetDescription member functions to fail.

HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
HRESULT hres;
IShellLink* psl;
char szGotPath[MAX_PATH];
char szDescription[MAX_PATH];
WIN32_FIND_DATA wfd;

*lpszPath = 0; // assume failure

// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;


// Get a pointer to the IPersistFile interface.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
&ppf);
if (SUCCEEDED(hres)) {
WORD wsz[MAX_PATH];

// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz,
MAX_PATH);

// Load the shortcut.
hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
if (SUCCEEDED(hres)) {


// Resolve the link.
hres = psl->lpVtbl->Resolve(psl, hwnd, SLR_ANY_MATCH);
if (SUCCEEDED(hres)) {

// Get the path to the link target.
hres = psl->lpVtbl->GetPath(psl, szGotPath,
MAX_PATH, (WIN32_FIND_DATA *)&wfd,
SLGP_SHORTPATH );
if (!SUCCEEDED(hres)
HandleErr(hres); // application-defined function


// Get the description of the target.
hres = psl->lpVtbl->GetDescription(psl,
szDescription, MAX_PATH);
if (!SUCCEEDED(hres))
HandleErr(hres);
lstrcpy(lpszPath, szGotPath);
}
}
// Release the pointer to the IPersistFile interface.
ppf->lpVtbl->Release(ppf);
}
// Release the pointer to the IShellLink interface.

psl->lpVtbl->Release(psl);
}
return hres;
}



Пригласи друзей и счет твоего мобильника всегда будет положительным!
Предыдущая статья
 
Сайт Народ.Ру Интернет
Следующая статья
Пригласи друзей и счет твоего мобильника всегда будет положительным!

Разрешение Сокращенного



Приложение возможно нужно иметь доступ к и манипулировать сокращенным, что создавался прежде. Это действие называется "разрешение" сокращенный.

Определенная прикладная функция ResolveIt в следующем примере решает сокращенный. Параметры включают ручку окна, указатель в путь сокращенного, и адреса буфера, которые получают новый путь на объект. Ручка окна идентифицирует родительское окно для любых ящиков сообщения, что оболочка возможно нужно отображаться. Например, оболочка может отобразить ящик сообщения если связь находится на unshared носителе, если сетевые проблемы происходят, если потребителю нужно включать флоппи-диск, и так далее.

Функция ResolveIt вызывает CoCreateInstance функционирует и допускает что функция CoInitialize уже вызвана. Отметьте, что ResolveIt нужно использовать интерфейс IPersistFile, чтобы загружать информацию связи. IPersistFile ОСУЩЕСТВЛЕН объектом IShellLink. Информация связи должна быть загружена прежде, чем информация пути будет извлечена, который случается позже в примере. Терпя неудачу, чтобы загружать информацию связи вызывает вызовы на IShellLink::GetPath и IShellLink::функции элемента GetDescription, чтобы терпеть неудачу.

HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
hres HRESULT;
IShellLink* psl;
символ szGotPath[MAX_PATH];
символ szDescription[MAX_PATH];
wfd WIN32_FIND_DATA;

*lpszPath = 0; // примите неудачу

// Получите указатель на интерфейс IShellLink.
hres = CoCreateInstance(&CLSID_ShellLink, НЕДЕЙСТВИТЕЛЬНЫЙ, CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
если (ПОЛУЧЕННОЕ(hres)) { IPersistFile* ppf;


// Получите указатель на интерфейс IPersistFile.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf);
если (ПОЛУЧЕННОЕ(hres)) { СЛОВО wsz[MAX_PATH];

// Проверьте, что строка является Уникодом.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);

// Загрузка сокращенный.
hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
если (ПОЛУЧЕННОЕ(hres)) {


// Решите связь.
hres = psl->lpVtbl->Resolve(psl, hwnd, SLR_ANY_MATCH);
если (ПОЛУЧЕННОЕ(hres)) {

// Получите путь в цель связи.
hres = psl->lpVtbl->GetPath(psl, szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH );
если (!ПОЛУЧЕННОЕ(hres) HandleErr(hres); // определенная прикладная функция


// Получите описание цели.
hres = psl->lpVtbl->GetDescription(psl, szDescription, MAX_PATH);
если (!ПОЛУЧЕННОЕ(hres)) HandleErr(hres);
lstrcpy(lpszPath, szGotPath);
}
}
// Версия указатель на интерфейс IPersistFile.
ppf->lpVtbl->Release(ppf);
}
// Версия указатель на интерфейс IShellLink.

psl->lpVtbl->Release(psl);
}
возврат hres;
}



Вверх Version 1.3, Oct 26 2010 © 2007, 2010, mrhx Вверх
 mrhx software  Русский перевод OpenGL  Русский перевод Win32 API
 
Используются технологии uCoz