Helpful Information
 
 
Category: Computer Programming
VB /C++ tutorials

does anyone know of any VB/C++ tutorials which will teach me how i can link a button to a program. So when the button labeled notepad is clicked it opens C:\blah\notepad.exe
i`m interessed in using either one of the two languages for it.
do you understand?

thanks in advance

scroots

I assume you're programming for windows:
Try this:


switch(LOWORD(wParam))
{
case BUTTON:
ShellExecute(hwnd,"open","c:\\winnt\\system32\\notepad.exe",NULL,NULL,SW_MAXIMIZE);
return 0;
}



if you're programming for the console (I think this also works in linux)
you can also use


#include <process.h>
...
spawnl(_P_WAIT,"c:\\winnt\\system32\\notepad.exe","c:\\winnt\\system32\\notepad.exe",NULL);



- Maes

maes could you expalin a little deeper.

scroots

Well, when you're makeing a win32 (C) aplication, I advice you to use ShellExecute (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/reference/functions/shellexecute.asp) .

With ShellExecute, you can start an other program or an other document, print it, etc.
the first parameter is the Handle to your window (HWND)

the second: this is what you want to do with the program/document. we want to "open" it. this will execute the .exe-file.

the third: this is the file (+path) we want to execute.
you have to youse "\\" instead of '\' beacause the slash (or backslash whatever) is an escape character

fourth: these are the parameters you want to give to your exe program. I've used NULL here this means I don't want to pass any arguments. but you can type here a path to a .txt-file that you want notepad to open

fifth: this is the default directory. when you add an .txt-file as the fourth parameter, you can specifie here where notepad has to look for it.

sixth: this specifies how the program will be shown to you.
I used SW_MAXIMIZE: this will maximize notedpad.
SW_MINIMIZE will minimize notepad. there are some more styles, but these are the most important ones (IMHO)


Am I makeing any sense here?

are there any tutorials on this, as i am not the worlds best c++/VB programmer, infact i don`t know much at all.
or what should my code look like?
cheers
scroots

<?
#include <shlobj.h>
#include <shlwapi.h>

#define YAKS "C:\\WINNT\\NOTEPAD.EXE"

main()
{
HWND handle;
ShellExecute(handle,"open",YAKS,NULL,NULL,SW_SHOWNORMAL);

return 0;
}
?>


lol - just wanted to see what the PHP syntax highlighting did to C

:confused:

Is there a way to use a relative path, instead of writing the complete path?

For example, if I have a executable.exe file in a folder

Can I use:

"folder\\executable.exe"

instead of

"d:\\folder\\executable.exe"

?

Because I´m gonna save the program that calls the file "executable.exe" in a CD, and the drive could have another letter assigned instead of "d:"

Thanks










privacy (GDPR)