Making a Win32

Hey I'm making a trivia game following the Win32 code from here: http://msdn.microsoft.com/en-us/library/bb384843.aspx

I took that code and added what I think I needed to do for my program (took a class on this years ago, I looked at some of my programs from that), but the only thing that registers in the output is the first line that I replaced "Hello world" with. Here is what I have:

// GT_HelloWorldWin32.cpp
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <iostream>
#define CLS std::cin.ignore (std::cin.rdbuf()->in_avail())


// Global variables

// The main window class name.
static TCHAR szWindowClass[] = _T("win32app");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = _T("Win32 Guided Tour Application");

HINSTANCE hInst;

// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);

return 1;
}

hInst = hInstance; // Store instance handle in our global variable

// The parameters to CreateWindow explained:
// szWindowClass: the name of the application
// szTitle: the text that appears in the title bar
// WS_OVERLAPPEDWINDOW: the type of window to create
// CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
// 500, 100: initial size (width, length)
// NULL: the parent of this window
// NULL: this application does not have a menu bar
// hInstance: the first parameter from WinMain
// NULL: not used in this application
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 100,
NULL,
NULL,
hInstance,
NULL
);

if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Win32 Guided Tour"),
NULL);

return 1;
}

// The parameters to ShowWindow explained:
// hWnd: the value returned from CreateWindow
// nCmdShow: the fourth parameter from WinMain
ShowWindow(hWnd,
nCmdShow);
UpdateWindow(hWnd);

// Main message loop:
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int) msg.wParam;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T(" Kathryn Erbe Triva Game");

switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);

// Here your application is laid out.
// For this introduction, we just print out "Hello, World!"
// in the top left corner.
TextOut(hdc,
5, 5,
greeting, _tcslen(greeting));
int score;
score=0;
char c1, c2, c3, c4, c5, c6, c7, c8, c9, c10;
CLS;
CLS;
std::cout<<"To answer, type the letter in lower case and press enter.";
CLS;
CLS;
std::cout<<"1. How many Criminal Intent openings did Kathryn do?";
std::cout<<"a 4";
std::cout<<"b 5";
std::cout<<"c 6";
std::cout<<"d 7";
std::cout<<"e 8";
CLS;
std::cin>>c1;
if (c1=='d') {
score=score+10;
}
CLS;
CLS;
std::cout<<"2. What is the first name of her father?";
std::cout<<"a Henry";
std::cout<<"b John";
std::cout<<"c Richard";
std::cout<<"d Anthony";
std::cout<<"e Peter";
CLS;
std::cin>>c2;
if (c2=='c') {
score=score+10;
}
CLS;
CLS;
std::cout<<"3. Which of these directors has Kathryn not worked with?";
std::cout<<"a John Frankenheimer";
std::cout<<"b Frank Oz";
std::cout<<"c Barbet Schroeder";
std::cout<<"d William Friedkin";
std::cout<<"e Bruce Beresford";
CLS;
std::cin>>c3;
if (c3=='d') {
score=score+10;
}
CLS;
CLS;
std::cout<<"4. What was her final score on Celebrity Jeopardy?";
std::cout<<"a $4000";
std::cout<<"b $6000";
std::cout<<"c $8000";
std::cout<<"d $12,000";
std::cout<<"e $16,000";
CLS;
std::cin>>c4;
if (c4=='a') {
score=score+10;
}
CLS;
CLS;
std::cout<<"5. Which of these Criminal Intent actors was not a previous film costar of hers?";
std::cout<<"a Annabella Sciora";
std::cout<<"b Courtney B. Vance";
std::cout<<"c Illeana Douglas";
std::cout<<"d Reg E. Cathey";
std::cout<<"e Bobby Cannavale";
CLS;
std::cin>>c5;
if (c5=='e') {
score=score+10;
}
CLS;
CLS;
std::cout<<"6. Which Oz character did she not interact with?";
std::cout<<"a Leo Glynn";
std::cout<<"b Timmy Kirk";
std::cout<<"c Simon Adebesi";
std::cout<<"d Vern Schillinger";
std::cout<<"e Tobias Beecher";
CLS;
std::cin>>c6;
if (c6=='e') {
score=score+10;
}
CLS;
CLS;
std::cout<<"7. What does the tatoo on her back say?";
std::cout<<"a M + T";
std::cout<<"b M + C";
std::cout<<"c K + T";
std::cout<<"d T + M";
std::cout<<"e T + K";
CLS;
std::cin>>c7;
if (c7=='d') {
score=score+10;
}
CLS;
CLS;
std::cout<<"8. What is the name of her dog?";
std::cout<<"a Liz";
std::cout<<"b Lily";
std::cout<<"c Lilah";
std::cout<<"d Linda";
std::cout<<"e Libby";
CLS;
std::cin>>c8;
if (c8=='c') {
score=score+10;
}
CLS;
CLS;
std::cout<<"9. What was the topic of her The More You Know PSA?";
std::cout<<"a Poverty";
std::cout<<"b Drunk driving";
std::cout<<"c STDs";
std::cout<<"d The enironment";
std::cout<<"e Mental illness";
CLS;
std::cin>>c9;
if (c9=='d') {
score=score+10;
}
CLS;
CLS;
std::cout<<"10.Fill in the blank: Alex Eames says he's a big _______";
std::cout<<"a jerk";
std::cout<<"b phony";
std::cout<<"c loser";
std::cout<<"d creep";
std::cout<<"e pig";
CLS;
std::cin>>c10;
if (c10=='b') {
score=score+10;
}
CLS;
CLS;
CLS;
std::cout<<"Your score is";
std::cout<<score;

// End application-specific layout section.

EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}

return 0;
}




Any help would be greatly appreciated.
Code tags would have been nice... It is the <> button in Format when you are making a post.

As far as the code goes... I'll take a look at it... though it looks like it has many problems on first glance.

Edit: Is this a GUI app or a console app? or both?
Last edited on
You seem to be mixing the standard console I/O with the Windows I/O functions? Try TextOut instead of cout
It's confusing me... sorry.
Yeah GUI, the linker is set to Windows not console.

Not getting what to do with TextOut. How would I write:

std::cout<<"To answer, type the letter in lower case and press enter.";


in TextOut?
There's a TextOut code in your source above which displays the text pointed to by the greeting variable. Look up for the function TextOut on MSDN. Play with its 2nd up to the last parameters. They control the location (x,y coordinates) of the text, and the text to display.
OK I think I'm starting to get the hang of this. Now, does every line of text need to be a TCHAR variable? Is the method of input TextIn? And will the if statements work as they are?
With regard to TCHAR, please see
http://msdn.microsoft.com/en-us/library/ff381407(VS.85).aspx


The if statement will work as is.

For further Windows I/O functions/programming, please check out the MSDN documentation.
I'm seeing different things for input. Is it fget? Which will work best here?
Please see if the following topic can help:
http://msdn.microsoft.com/en-us/library/ms632585(VS.85).aspx
Topic archived. No new replies allowed.