|
From: christiaan s. <ck...@ia...> - 2002-03-17 10:28:54
|
how do i start an external program from my program? I tried wineexec and =
its error code returns success but i dont see the program! here is my =
code
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] =3D "WindowsApp";
HINSTANCE hInstance; // Holds The Instance Of The Application
HWND hWnd; /* This is the handle for our window */
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, =
LPSTR lpszArgument, int nFunsterStil)
{
MSG messages; /* Here messages to the application are =
saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
hInstance =3D hThisInstance; // Holds The Instance Of The =
Application
/* The Window structure */
wincl.hInstance =3D hThisInstance;
wincl.lpszClassName =3D szClassName;
wincl.lpfnWndProc =3D WindowProcedure; /* This function is =
called by windows */
wincl.style =3D CS_DBLCLKS; /* Catch double-clicks =
*/
wincl.cbSize =3D sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon =3D LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm =3D LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor =3D LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName =3D NULL; /* No menu */
wincl.cbClsExtra =3D 0; /* No extra bytes after =
the window class */
wincl.cbWndExtra =3D 0; /* structure or the =
window instance */
/* Use light-gray as the background of the window */
wincl.hbrBackground =3D (HBRUSH) GetStockObject(LTGRAY_BRUSH);
/* Register the window class, if fail quit the program */
if(!RegisterClassEx(&wincl)) return 0;
/* The class is registered, let's create the program*/
hWnd =3D CreateWindowEx(
0, /* Extended possibilites for variation =
*/
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_POPUP, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the =
screen */
800, /* The programs width */
600, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to =
desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow(hWnd, nFunsterStil);
=20
//SystemParametersInfo(SPI_SCREENSAVERRUNNING,true,0,0);
/* Run the message loop. It will run until GetMessage( ) returns 0 =
*/
while(GetMessage(&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage( ) =
gave */
return messages.wParam;
}
void quit()
{
SystemParametersInfo(SPI_SCREENSAVERRUNNING,false,0,0);
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To =
Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN =
ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=3DNULL; // Set hWnd To NULL
}
if (!UnregisterClass("WindowsApp",hInstance)) // Are We =
Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN =
ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=3DNULL; // Set hInstance To NULL
}
}
/* This function is called by the Windows function DispatchMessage( ) */
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT message, WPARAM wParam, =
LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
return 0; /* send a WM_QUIT to the message queue */
break;
case WM_KEYDOWN: // Is A Key Being Held Down?
{
if (wParam =3D=3D 13)
{
int blah;
blah =3D =
WinExec("C:\\WINDOWS\\COMMAND\\edit.com",WS_OVERLAPPEDWINDOW);
switch( blah )
{
case 0:
MessageBox(NULL,"out of =
mem","CLOSING",MB_OK|MB_ICONSTOP);
break;
case ERROR_BAD_FORMAT:
MessageBox(NULL,"bad =
format","CLOSING",MB_OK|MB_ICONSTOP);
break;
case ERROR_FILE_NOT_FOUND:
MessageBox(NULL,"file not =
found","CLOSING",MB_OK|MB_ICONSTOP);
break;
case ERROR_PATH_NOT_FOUND:
MessageBox(NULL,"path not =
found","CLOSING",MB_OK|MB_ICONSTOP);
break;
}
if (blah>31)
MessageBox(NULL,"success ","CLOSING",MB_OK|MB_ICONSTOP);
=20
}
if (wParam =3D=3D 57)
{
MessageBox(NULL,"Program Will Now =
Close.","CLOSING",MB_OK|MB_ICONSTOP);
quit();
PostQuitMessage(0);
return 0; // Jump Back
}
}
break;
default: /* for messages that we don't deal =
with */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
|
|
From: christiaan s. <ck...@ia...> - 2002-03-19 12:58:06
|
But if i launch a windows program with winexec it works, its just when i = tried to run a dos one like edit.com that it didnt show up! why is that? |
|
From: Kevin W. <ke...@me...> - 2002-03-17 20:26:51
|
Try the CreateProcess function instead. The following is from the Win32 SDK: ............... WinExec Remarks Win32-based applications should use the CreateProcess function rather than this function. The WinExec function exists in Win32 to provide compatibility with earlier versions of Windows. For more information about how the WinExec function is implemented, see the Remarks section of the LoadModule function. In Win32, the WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec. ..................... Kev. ----- Original Message ----- From: christiaan scholtz <ck...@ia...> To: <dev...@li...> Sent: Sunday, March 17, 2002 10:28 AM Subject: [Dev-C++] winexec how do i start an external program from my program? I tried wineexec and its error code returns success but i dont see the program! --- cut --- |