![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I wrote a C++ program to auto install 2 programs from a CD when it is inserted via an autorun file. I had to make the program pause after initializing the first setup program so that it did not try and run both setups at the same time. When the first program setup starts, the pause command is run in my program bringing it back to an active window and making the setup program inactive. This can be solved simply by clicking on the minimize button, which is fine if I am using the program. I am worried that if someone else uses it they won't know to install both setups. Is there a way to make the console window drop behind the setup window after the pause command is executed?
Any help would be appreciated. Thanks, -BB98 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
how about a batch script, run setup1, then delay, then run setup2?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Sorry, I am not sure how to create a batch script. Would you be able to give me some more info, or maybe a link to a tutorial.
This is the code, spaces are just to align the text in the console window to the center. # include <stdio.h>
# include <stdlib.h>
main()
{
printf("\n ==> ATTENTION <==\n\n");
printf(" Do NOT close this window.\n");
printf(" Unless you wish to exit installation\n");
printf(" It will close automatically when done.\n\n");
printf(" AdWin Installation.\n\n");
printf(" ");
system("pause");
system("setup.exe");
printf("\n Please ");
system("pause");
printf("\n\n Adobe Acrobat Reader Installation.\n");
printf(" ");
system("pause");
system("AdbeRdr70_enu_full.exe");
printf("\n\n Exiting...\n\n");
}thanks, -BB98 |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
check out the parameters for the 'cmd' command. Particularly, the /C and /K
system("cmd /C setup.exe"); or system("cmd /K setup.exe"); (btw, a batch script in the simplest form is just a sequence of things you may type at a command shell, the script has a *.bat extension)
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Alright, I'll play with it.
Thanks for the help, -BB98 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
alright, let us know if you still have problems.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I still can't get the console window to stop coming to the front on top of the setup program. I would like to learn to create GUI's, maybe this would be a good starting project, any good places to look for tutorials? Or maybe some books?
Thanks in advance, -BB98 |
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
what have you tried so far?
check here for a relatively decent win32 api tut for gui dev. http://www.functionx.com/win32/index.htm
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I tried playing with the "cmd /C" or "cmd /K" and it worked, except that it would still bring the console window back infront of the first setup program. I think I am going to need to learn a lot more before I can attempt a GUI after browsing through that tut.
Thanks for all the info IR. -BB98 |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Sorry for being impatient... I was looking through my Dev-C++ installed files and came across the Examples folder. After looking through it I found a simple GUI that is along the lines of what I wanted to create to run the series of setup files that way I wanted. The original program had some text in the center and a button towards the bottom that would close the window when clicked. It is supposed to be a simple window that I would like to have several buttons down the center. Each button will correspond to a certain setup.exe file. I have adjusted the code from the example so that it has one button that will execute a setup.exe from the CD-ROM drive. I cannot figure out how to add more buttons for the other setups and one to quit and close the window. If someone could guide me in the right direction on how to add more buttons and where to add it in the code it would help me out a lot. I have looked through a few tutorials, but none so far have mentioned creating or adding buttons to the parent window. Looks like I am going to have to take a trip to Borders and get myself a book...
Here's the code so far. /*
* A simple Win32 application that will take setup files
*
* from a CD and run them when the button for that setup
*
* is clicked in the application window.
*/
#include <windows.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
/*
* This is the window function for the main window. Whenever a message is
* dispatched using DispatchMessage (or sent with SendMessage) this function
* gets called with the contents of the message.
*/
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Install AdWin" button. */
static HWND hwndButton = 0;
static int cx, cy;/* Height and width of our button. */
HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
/*
* Perform processing based on what kind of message we got.
*/
switch (nMsg)
{
case WM_CREATE:
{
/* The window is being created. Create our button
* window now. */
TEXTMETRIC tm;
/* First we use the system fixed font size to choose
* a nice button size. */
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);
/* Now create the button */
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Install Adwin",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY:
/* The window is being destroyed, close the application
* (the child button gets destroyed automatically). */
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
/* The window needs to be painted (redrawn). */
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
/* Draw text in the middle top
* of the window. */
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Click a button to install that program.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
/* The window size is changing. If the button exists
* then place it in the center of the bottom half of
* the window. */
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 2;
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
/* Check the control ID, notification code and
* control handle to see if this is a button click
* message from our child button. */
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
/* AdWin button was clicked. Execute the setup.*/
system("D:\\adwin\\setup.exe");
}
/* Quit button was clicked. Close Window.
DestroyWindow (hwnd);*/
return 0;
break;
}
/* If we don't handle a message completely we hand it to the system
* provided default window function. */
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "InstallationWin";
/* The name of the main window class */
/*
* First we create a window class for our main window.
*/
/* Initialize the entire structure to zero. */
memset (&wndclass, 0, sizeof(WNDCLASSEX));
/* This class is called WinTestWin */
wndclass.lpszClassName = szMainWndClass;
/* cbSize gives the size of the structure for extensibility. */
wndclass.cbSize = sizeof(WNDCLASSEX);
/* All windows of this class redraw when resized. */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
/* All windows of this class use the MainWndProc window function. */
wndclass.lpfnWndProc = MainWndProc;
/* This class is used with the current program instance. */
wndclass.hInstance = hInst;
/* Use standard application icon and arrow cursor provided by the OS */
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
/* Color the background black */
wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
/*
* Now register the window class for use.
*/
RegisterClassEx (&wndclass);
/*
* Create our main window using that window class.
*/
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Setups and Patches",/* Caption */
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);
/*
* Display the window which we just created (using the nShow
* passed by the OS, which allows for start minimized and that
* sort of thing).
*/
ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);
/*
* The main message loop. All messages being sent to the windows
* of the application (or at least the primary thread) are retrieved
* by the GetMessage call, then translated (mainly for keyboard
* messages) and dispatched to the appropriate window procedure.
* This is the simplest kind of message loop. More complex loops
* are required for idle processing or handling modeless dialog
* boxes. When one of the windows calls PostQuitMessage GetMessage
* will return zero and the wParam of the message will be filled
* with the argument to PostQuitMessage. The loop will end and
* the application will close.
*/
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}I am assuming it has something to do with defining more buttons?? Thanks, -BB98 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|