View Single Post
Old Oct 14th, 2005, 2:03 PM   #10
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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
badbasser98 is offline   Reply With Quote