|
Hello,
I am creating a short-cut to an installed application in the "C:\Program Files (x86)" folder, but the target always seems to point to the "C:\Program Files" folder, the only problem with this is the short-cut icon shown is the default one. But if i double-click the short-cut, the app is invoked fine. Is this a problem with the 64-bit Vista shell or am i doing something wrong in the below mentioned program. My appname is test.exe and is installed in the "C:\\Program Files (x86)\\Sample" folder.
All the folders usedin the below program were valid one's on my system.
This same program works fine on XP-64 bit.
Regards,
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkDir) ;
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
HRESULT ret = CreateLink("C:\\Program Files (x86)\\Sample\\test.exe","c:\\users\\public\\desktop\\test.lnk","Test","C:\\Program Files (x86)\\Sample");
if(SUCCEEDED(ret))
printf("\nCreate link succeeded");
else
printf("\nCreate link failed");
CoUninitialize();
return 0;
}
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkDir)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
printf("\nSucceded in creating an instance");
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
psl->SetWorkingDirectory(lpszWorkDir);
//psl->SetIconLocation(lpszWorkDir, 0);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
printf("\nSucceded in querying interface");
// Ensure that the string is Unicode.
if(MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH))
{
// TODO: Check return value from MultiByteWideChar to ensure success.
printf("\nSucceded in conversion");
char pszGetPath[MAX_PATH];
if(SUCCEEDED(psl->GetPath(pszGetPath,MAX_PATH,NULL,SLGP_RAWPATH)))
printf("\nGet Path: %s",pszGetPath);
else
printf("\nGet Path failed");
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
}
ppf->Release();
}
psl->Release();
}
return hres;
}
Regards,
Pavan
|
|
|
|
|
kpkrind wrote: HRESULT ret = CreateLink("C:\\Program Files (x86)\\Sample\\test.exe","c:\\users\\public\\desktop\\test.lnk","Test","C:\\Program Files (x86)\\Sample");
I might be wrong, but isn't this the old problem with path names containing spaces in a command line?
Try to surround (at least) the paths containing spaces with quotes.
Like this:
CreateLink("\"C:\\Program Files (x86)\\Sample\\test.exe\"","c:\\users\\public\\desktop\\test.lnk","Test","\"C:\\Program Files (x86)\\Sample\"");
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
No, its not a problem with the spaces, CreateLink expects a string pointer and is passed correctly
|
|
|
|
|
OK, It was worth a try anyway.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Hi
Iam developing a Dialog based application.
In that application user has to add some files to perfrom the next operation,
so i need to validate the file path,file name,for further operation.
how can i check that user has entered the correct path,file name
|
|
|
|
|
reddy harish wrote: how can i check that user has entered the correct path,file name
It depends of what you mean by that exactly. If you simply want to check if the file exist, you can simply try to open is (with fopen for example) and if the function succeed, then the file exists. Supply the absolute path so that you can check the path and the file name.
|
|
|
|
|
Thnks for ur reply.
but If the user is entering the wrong file path or file name and he is trying to perform the next operation,how can we prevent him from that.so that we have to write the code to give him messeage or to stop him.
Ex:when we are entering the wrong file name or path in the "RUN" command,it shows us a warning or message saying that is not exist.
Like that can we perform the operation
|
|
|
|
|
Uuuhh ??
Did you read my post ?
If you try to open a file that doesn't exist in read mode, fopen will return an error. So in that case you know that the file is wrong and you can display a message and not continue to the next step.
Anyway, the solution of Christian is better (and you provide also an elegant way to choose the file for the user).
|
|
|
|
|
Easiest way - get them to select files with the file dialog and set the style so the filename entered must exist.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
See Cedric Moonen answer.... and see SetCurrentDirectory(...) and see return value.Is your purpose
|
|
|
|
|
|
Christian's solution will work for the most part. I'd just add that after you select a file, use CFile::GetStatus to determine if it exists or not. The method will return TRUE if it succeeds, and FALSE if the file/directory doesn't exist.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello,
I am writing a function that control the staus from key pressed.
It works but how can check in one function at the same time if VK_CONTROL && VK_SHIFT are pressed !
Thank you !
AutreChien
|
|
|
|
|
NorGUI wrote: VK_CONTROL && VK_SHIFT are pressed
SHORT GetKeyState(int nVirtKey);
Return Value:
If the high-order bit is 1, the key is down; otherwise, it is up.
nVirtKey:
VK_LSHIFT
VK_RSHIFT
VK_LCONTROL // Check this parameter
VK_RCONTROL // or Check this parameter with GetKeyState in Key press event
VK_LMENU
VK_RMENU
Example:
if(GetKeyState (VK_LSHIFT) && GetKeyState (VK_LCONTROL))
{
// Do something the left shift and control key are pressed.
}
-- modified at 6:52 Tuesday 22nd August, 2006
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi,
In my application I am processing timer events. User has minimized my application by clicking on Minimize button. At some specific timer event I want to show the window of my application to maximized state and set the application to active state. How can I achive this?
Regards,
Hemant
|
|
|
|
|
Hemant kulkarni wrote: At some specific timer event I want to show the window of my application to maximized state and set the application to active state. How can I achive this?
At timer event use ShowWindow(SW_SHOWMAXIMIZED) for that window.
|
|
|
|
|
Hi,
I tried this, but this doesn't work as my application is minimised to taskbar and other application is active.
Regards and Thanks,
Hemant
|
|
|
|
|
WM_SYSCOMMAND and SC_MAXIMIZE should help.
|
|
|
|
|
Hi,
I tried this also , but this doesn't work as my application is minimised to taskbar and other application is active.
Regards and Thanks,
Hemant
|
|
|
|
|
Can you show your code why your code doesnt work with these.
|
|
|
|
|
here is code snapshot
void CAutoActivateAppView::OnTimer(UINT nIDEvent)
{
SetForegroundWindow();
SetFocus(); //Just playing safe
SetActiveWindow();
ShowWindow(SW_MAXIMIZE);
CView::OnTimer(nIDEvent);
return;
}
Regards,
Hemant.
|
|
|
|
|
You need to call ShowWindow on main frame window.use this code,
void CAutoActivateAppView::OnTimer(UINT nIDEvent)
{
GetParent()->ShowWindow(SW_SHOWMAXIMIZED);
CView::OnTimer(nIDEvent);
}
|
|
|
|
|
Thanks god ! ! !
It worked !
I was missing this activating parent window!
Thanks again for suggestion.
Thanks and Reagrd
Hemant
|
|
|
|
|
Do you really want to do this?
What happens if you press space, or enter on your window? If enter sets some process running, then imagine what could happen if a user is in the middle of typing an email, and just as your app pops up they press enter, only to find your app starts running away doing stuff they really didn't want to happen just yet?
It might be better to have a notification balloon pop up and tell them that they need to do something
|
|
|
|
|
Yes. But not exactly this.
The requirement is when user presses "F12" the application should start and display the window to user. If the application is already started but if it is in minimized state at taskbar it should become active, focused and show the window to user. If the application is not started it should start the.
I am checking the user keys in a hook procedure
Hope this will make the things clear
Regards,
Hemant.
|
|
|
|