Creating a Simple Survey Progrmam

May 6, 2011 at 18:55:17
Specs: Windows 7
I'm trying to make a simple 5 page survey for my Psychology class in order to make it easier to collect data. I'm really new to coding and can't do much. I've been working for HOURS on trying to code this, and it definitely isn't very fun when I have no idea what I'm doing. I have gotten it to create a child window with text, but need to be able to make 3 more of those, but I don't know what part of the code to copy or where to put it in order to add it. Also, I need to create a drop down box/text edit box function to put answers to my questions. At the end, I want it to be able to send to my email address. I know that it's all possible to do, but I am having a ton of trouble with it. I'm using Dev C++ as my compiler. I've gotten a little bit of help from a programming friend, but he just doesn't have the time to code it for me or help me with it.

Can anyone tell me how to make it do what I want, and in what sections to place it? Or even, just what the code is! I'm pretty lost, I need help soon!

The code I have so far:
#include <windows.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>


LRESULT CALLBACK
ChildWnd1Proc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Click Me" 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 */
"Click Near Here",
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 "Hello, World" in the middle of the upper
* half of the window. */
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, New World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);

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)
{
/* Our button was clicked. Close the 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
/*WinChild (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)*/
WinChild ()
{
HWND hwndMain; /* Handle for the main window. */
MSG msg; /* A Win32 message structure. */
WNDCLASSEX wndclass2; /* A window class structure. */
char*szMainWndClass2 = "WinTestWin2"; /* must give your window a new name!*/
HINSTANCE hInst= GetModuleHandle (0);
int nShow=1;
static int counter=0;
counter++;
char number[233];
char myText[500];
itoa( counter,number,10);
sprintf (myText,"My Child window number %d\n",counter);


memset (&wndclass2, 0, sizeof(WNDCLASSEX));
wndclass2.lpszClassName = szMainWndClass2;
wndclass2.cbSize = sizeof(WNDCLASSEX);
wndclass2.style = CS_HREDRAW | CS_VREDRAW;
wndclass2.lpfnWndProc = ChildWnd1Proc;
wndclass2.hInstance = hInst;
wndclass2.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass2.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass2.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass2.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

RegisterClassEx (&wndclass2);

hwndMain = CreateWindow (
szMainWndClass2, /* Class name */
myText, /* 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 */
);

ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}


/*
* 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 "Click Me" 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 */
"Click Here",
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 "Hello, World" in the middle of the upper
* half of the window. */
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);

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)
{
/* Our button was clicked. Close the window. */
WinChild ();
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 = "WinTestWin";
/* 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 white */
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

/*
* Now register the window class for use.
*/
RegisterClassEx (&wndclass);

/*
* Create our main window using that window class.
*/
hwndMain = CreateWindow (
szMainWndClass, /* Class name */
"Hello", /* 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;
}


See More: Creating a Simple Survey Progrmam

Report •

#1
May 6, 2011 at 20:33:26
Serious mode time: C++ is good. It lets you have total control over your application, with little to no overhead. It is the basis of more modern languages; it has objects, try/catch, and the basics of generics.

What it is not good at is GUI programming on any platform, and being beginner friendly.

If you're making a Windows application, I suggest you pick a language easier to work with. If I'm making a Windows application, I use Microsoft's C#. Its free IDE, Visual Studio Express, will let you design your application graphically, and typically the amount of code required to stitch everything together is minimal (when compared to C or C++). It's also popular enough that you should be able to find any code you need with a quick Google search.

How To Ask Questions The Smart Way


Report •

#2
May 8, 2011 at 09:03:17
Are you inputting the data or are people who are being surveyed doing it?

If it is going to be on a web page then html might be the answer.

Below is some unfinished code....needs some editing and a mailto entry
so the input can be sent.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Information</title>
</head>
<body style="background-color: rgb(102, 51, 0); color: rgb(0, 0, 0);"
alink="#000099" link="#000099" vlink="#990099">
<form>
</form>
<div style="text-align: center;">  style="color: rgb(255, 255, 255);" size="+3">Talk to me

</div>
<center>
<table style="width: 600px;" border="12" cellspacing="12">
<tbody>
<tr>
<td style="width: 199px; background-color: rgb(204, 102, 0);">What
brand is your computer?

<input name="Brand?..HP" value="YES" type="checkbox"> HP

<input name="Brand?..Dell" value="YES" type="checkbox"> Dell

<input name="Brand?..IBM" value="YES" type="checkbox"> IBM

<input name="Brand?..Acer" value="YES" type="checkbox"> Acer

<input name="Brand?..LAPTOP" value="YES" type="checkbox"> Laptop

<input name="Brand?..DeSKTOP" value="YES" type="checkbox">Desktop


<input name="Brand?..Other" value="YES" type="checkbox"> Other</p>
</td>
<td style="background-color: rgb(204, 102, 0);" width="200">What
OS are you using?

<input name="os?...DOS" value="YES" type="checkbox"> DOS

<input name="os?...WIN3.1" value="YES" type="checkbox">WIN3.1

<input name="os?...WIN95" value="YES" type="checkbox"> WIN95

<input name="os?...WIN98" value="YES" type="checkbox">WIN98

<input name="os?...WINME" value="YES" type="checkbox"> WINME

<input name="os?...wINNEPTUNE" value="YES" type="checkbox"> WIN
NEPTUNE

<input name="os?...WIN2000" value="YES" type="checkbox"> WIN2000

<input name="os?...WINXPHOME" value="YES" type="checkbox"> XP HOME

<input name="os?...WINXPPRO" value="YES" type="checkbox"> XP PRO

<input name="os?...WIN7" value="YES" type="checkbox"> WIN7

<input name="os?...VISTA" value="YES" type="checkbox"> VISTA

</td>
<td style="background-color: rgb(204, 102, 0);" width="199">What
level of
experiance do you have?



<input name="exper?...New" value="YES" type="checkbox"> New

<input name="exper?...Less than one year" value="YES"
type="checkbox">Less than 1 year

<input name="exper?...Two years" value="YES" type="checkbox">Two
years

<input name="exper?...Five years" value="YES" type="checkbox">Five
years

<input name="exper?...Ten Plus years" value="YES" type="checkbox">Ten
Plus years

<input name="exper?...Guru" value="YES" type="checkbox">Guru </td>
</tr>
</tbody>
</table>
<form>
</form>
<div style="text-align: center;">  style="color: rgb(255, 255, 255);" size="+3">What is the problem?

</div>
<center>
<table style="width: 600px;" border="12" cellspacing="12">
<tbody>
<tr>
<td style="width: 199px; background-color: rgb(204, 102, 0);"><input
name="Brand?..HP" value="YES" type="checkbox"> Hard Drive

<input name="Brand?..Dell" value="YES" type="checkbox"> Monitorl

<input name="Brand?..IBM" value="YES" type="checkbox"> CD Rom

<input name="Brand?..Acer" value="YES" type="checkbox"> Modem

<input name="Brand?..LAPTOP" value="YES" type="checkbox">Connector

<input name="Brand?..DeSKTOP" value="YES" type="checkbox">Keyboard


<input name="Brand?..Other" value="YES" type="checkbox"> Other</p>
</td>
<td style="width: 200px; background-color: rgb(204, 102, 0);">

<input name="os?...DOS" value="YES" type="checkbox"> Virus or
Trojan

<input name="os?...WIN3.1" value="YES" type="checkbox">WIN3.1

<input name="os?...WIN95" value="YES" type="checkbox"> WIN95

<input name="os?...WIN98" value="YES" type="checkbox">WIN98

<input name="os?...WINME" value="YES" type="checkbox"> WINME

<input name="os?...wINNEPTUNE" value="YES" type="checkbox"> WIN
NEPTUNE

<input name="os?...WIN2000" value="YES" type="checkbox"> WIN2000

<input name="os?...WINXPHOME" value="YES" type="checkbox"> XP HOME

<input name="os?...WINXPPRO" value="YES" type="checkbox"> XP PRO

<input name="os?...WIN7" value="YES" type="checkbox"> WIN7

<input name="os?...VISTA" value="YES" type="checkbox"> VISTA

</td>
<td style="background-color: rgb(204, 102, 0);" width="199">What
level of
experiance do you have?





<input name="exper?...New" value="YES" type="checkbox"> New

<input name="exper?...Less than one year" value="YES"
type="checkbox">Less than 1 year

<input name="exper?...Two years" value="YES" type="checkbox">Two
years

<input name="exper?...Five years" value="YES" type="checkbox">Five
years

<input name="exper?...Ten Plus years" value="YES" type="checkbox">Ten
Plus years

<input name="exper?...Guru" value="YES" type="checkbox">Guru </td>
</tr>
</tbody>
</table>
<textarea name="COMMENTS" rows="15" cols="65"> \\|// (@ @)
----------------------oOO---(_)---OOo------------------------- : : :
This is to illustrate that if you type something between : : the
<TEXTAREA> tags, it will show up in the window as the : : default
"COMMENT". The cool part is... it shows up : : EXACTLY the type : : way
you it! :
-------------------------------------------------------------- |__|__|
|| || ooO Ooo
</textarea></center>
</center>
</body>
</html>


Report •
Related Solutions


Ask Question