|
Am making a menu and so i need some way to launch a other program.
does ShellExecute do that?? If so how do i make it work, i tryed lots off things (didnt work)
Please give some examples.
Thank you
|
|
|
|
|
Yes, this is what you want. Here is the MSDN on ShellExecute.
ShellExecute
Performs an operation on a specified file.
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpVerb,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
Parameters
hwnd
Handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
lpVerb
A string, referred to as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's context menu are available verbs. For more information about verbs and their availability, see Object Verbs. See Extending Context Menus for further discussion of context menus. The following verbs are commonly used: Verb Description
edit Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
explore Explores the folder specified by lpFile.
find Initiates a search starting from the specified directory.
open Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder.
print Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
properties Displays the file or folder's properties.
If you set this paramater to NULL:
For systems prior to Microsoft® Windows® 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.
For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.
lpFile
Address of a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a shell namespace object, pass the fully-qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb.
lpParameters
If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application.The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
Address of a null-terminated string that specifies the default directory.
nShowCmd
Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the z-order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
Return Values
Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Microsoft® Windows® applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an integer and compare it with the value 32 or one of the error codes below.
0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .exe file is invalid (non-Win32® .exe or error in .exe image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.
Remarks
This method allows you to execute any commands in a folder's context menu or stored in the registry.
To open a folder, use either of the following calls:
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);
or
ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
To explore a folder, use:
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
To launch the shell's Find utility for a directory, use:
ShellExecute(handle, "find", path_to_folder, NULL, NULL, 0);
If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will attempt to open or explore the folder.
With multiple monitors, if you specify the window handle and set lpOperation to "Properties", any windows created by ShellExecute may not appear in the correct position.
To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx.
See Also
IShellExecuteHook
Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in shellapi.h.
Import Library: shell32.lib.
From my own code, it looks like this:
ShellExecute(this->m_hWnd,NULL,"IE.EXE",NULL,"IE5",SW_SHOWDEFAULT );
Note this was from an install CD, so I did not need to provide a path.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
First af all, please my ingles because i´m spanish girl. If you don´t understand me i can say someone to translate it and send to you again. I created a program which execute an unix script, i made this: system ("rsh dir_ip -l root -n path/namefile [parameter] -l") but before i had to modify rhost and another file in my unix machine. The system command give you the posibility to handle the DOS or windows commands as remote shell, now you have to research this commands.
|
|
|
|
|
i'd like to display the ip address of the localhost as a CString. if anyone knows a way to convert an ip to a char array, your help would be appreciated. gethostbyname() doesn't seem to do the trick for me. thanks in advance.
~loki
|
|
|
|
|
|
thanks a ton, it worked perfectly.
~loki
|
|
|
|
|
Hello, am trying to make a dice program, and i was wondoring how i could make a Random number from 1-6 when i press a butten???
Oh one more thing, when i start a new project "MFC app wizard", i can chose: "As shared Dll" or "as staticaly linked library" i tryed them both, but didnt see any change at all, what are the defrents????
Thank's
|
|
|
|
|
Hi,
The code for generating random numbers is posted below.
The second question involved static versus shared libraries.
You only get the shared dll option for the professional
version. The difference between the two is noticable when
you want to distribute your software.
When you compile the program with shared dll, you incorporate
all the dll files that you were using for that program
into your executable. You can put that executable on other
computers and everything will work fine.
When you compile the program with static dll's, you get
a rather small exectuable. If you put that executable on
another computer, it won't work unless you find and send
the dll files as well and put them next to the executable.
Finding which dll files your using can be a pain, but if you
don't have the professional version (which I don't), then
you have to hunt them down and include them. In fact, that's
the only real difference between the professional and
standard version.
main()
{
double a_number;
/*
* The simplest way to get a random number is just to call the
* function 'random()'. It returns a random number between
* 1 and 2**31 - 1. For example:
*/
a_number = (float) random();
printf("A big random number is %lf.\n", a_number);
/*
* To get a random number between 0 and 1, you would use this:
*
* double number;
* number = (float) random() / (float) 0x7fffffff;
*
* Note that the constant 0x7fffffff is equal to (2**31)-1, which is
the
* maximum value of the random number generator.
*/
a_number = (float) random() / (float) 0x7fffffff;
printf("A random number between 0 and 1 is %lf,\n", a_number);
/*
* However, when used as above, the program will get
* the same random numbers every time it is run. Sometimes
* this is good, sometimes not. For example, in Monte Carlo
* simulations a set of identical "random" numbers is useful
* for debugging, but bad for getting real data.
*
* To change the set of numbers generated, use 'srandom' to
* set an initial state. The number that you use to set this
* state is called a "seed". Note that identical seeds will
* generate identical sequences of random numbers. A possible
* seed is the number of seconds since Jan 1, 1970, GMT, the
* value given by time or the process id (from 'getpid').
* Both are used here. This 'srandom' call only needs
* to be done once per program.
*/
srandom(time(0) * getpid());
/*
* Now get and print a "real" random number.
*/
a_number = (float) random() / (float) 0x7fffffff;
printf("But a more random number between 0 and 1 is %lf\n", a_number);
/*
* So, if you wanted a random number between 0 and 10, you would take
the
* number you got above and multiply it by 10, and round to the
nearest
* integer (or whatever).
*/
a_number = 10.0 * (float) random() / (float) 0x7fffffff;
printf("But a more random number between 0 and 10 is %lf\n",
a_number);
}
|
|
|
|
|
How do i implant those codes in C++ MFC????
Thanks
|
|
|
|
|
How do i implant those codes in C++ MFC????
Thanks
|
|
|
|
|
Thanks for the help but i just figured it out my self
lNumLines = rand() % 100;
thats how i did it, a random number between 0 and 99 (I think)..
|
|
|
|
|
Hi Michael,
You might try the code :
#include <stdlib.h>
{
int iRandomNumber;
iRandomNumber = 1 + (rand() % 6); /* 1 + a random number between 0 and 5 inclusive */
...
}
|
|
|
|
|
Hi,
I have a application that minimizes to the tray (the main window is hidden while the program is minimized to the tray)
The problem is that the apilication will not receive the WM_QUERYENDSESSION/WM_DESTROY messages when I'm shutting down.
That means that data and settings will not be saved before the program exits if someone logs off or closes Windows
Does anybody know what to do
Thanks,
Christian Skovdal Andersen
|
|
|
|
|
Try looking at onexit() and/or atexit()
You can register functions that get called at C/C++ (not windows) application
shutdown. So if someone or windows closes you program and you don't get the
WM_CLOSE, your program still calls all the functions registered with onexit()
and/or atexit()
Stephen Kellett
|
|
|
|
|
I have several simple questions on linear programming.
I am using the package CPLEX. Does anyone know of anyone
who can answer questions on linear programming or CPLEX?
I would really like to find someone, anyone who could
answer some of my questions?
My email address is : brinasas@yahoo.com
Any response any one can give me will be greatly
appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
I wonder how to hide the main dialog in a dialog based app, and display it again later ? please gimme any example !
|
|
|
|
|
Call ShowWindow() and pass SW_HIDE or SW_SHOW to hide or show it, respectively.
--Mike--
http://home.inreach.com/mdunn/
Time is an illusion; lunchtime doubly so.
|
|
|
|
|
Yeah, it works fine , but i want to hide it after creation (for tray use)
the programs initial state should be residing in tray, and after double clicking i want to show the main dialog
inserting ShowWindow(SW_HIDE); in OnInitDialog doesnt work !
Any ideas ?
|
|
|
|
|
Yeah, it works fine , but i want to hide it after creation (for tray use)
the programs initial state should be residing in tray, and after double clicking i want to show the main dialog
inserting ShowWindow(SW_HIDE); in OnInitDialog doesnt work !
Any ideas ?
|
|
|
|
|
Either of two straight forward methods,
1. Run your App from a Child of your hidden Dialog.
2. Remove || Replace the AppWindow style if you are using MFC from your .rc file,
Regardz
Colin Davies
|
|
|
|
|
Hmm, i must say i have no idea what you mean
My only Goal is to code an Application, that sits in Tray on Startup (no window displayed) and when you doubleclick the tray icon the main window should be shown. And it has to be dialog based !.
Hoping for further explanations. (I'm a quite newbie)
|
|
|
|
|
Hi!
Knowing that even a dialog based app is an app already! So you'd have an application class in MFC that is named: CwhateverApp Right?
OK, then do this in the InitInstance() function:
BOOL CwhateverApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
return FALSE;
}
And then if you have a menu item that's used to load the dialog again, then that's where you gotta call the DoModal() funtion to show the window.
Hope this helped!
|
|
|
|
|
It worx, big thanks !!!!!!
I already hat this idea before "BUT" i did return TRUE; and got presented a nice debug assertion error
It works ! It works ! YAHOOOOOOOOOOOOOOOOOOOOOO !
|
|
|
|
|
Argh, damn i was wrong, it doesnt work, if i dont call DoModal, the whole application doesnt start (->Task list). Any other ideas ?
|
|
|
|
|
Have you tried setting the dialog box to not be visible (using the resource editor)?
|
|
|
|
|