Sign in to follow this  

C++ - windows.h Problems

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, Just bought the book OpenGL Game Programming. It gives some example code at the beginning for the "Hello World" windows application (using windows.h). I get some warnings and errors in my compiler (Dev C++) when I try to run the example code in the book. I'm thinking that I might not have the right windows.h or something. What am I doing wrong? Thanks.

Share this post


Link to post
Share on other sites

#define WIN32_LEAN_AND_MEAN // trim the excess fat from Windows

#include <windows.h> // standard Windows app include

// the Windows Procedure event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paintStruct;
HDC hDC; // device context
char string[] = "Hello, world!"; // text to be displayed

switch(message)
{
case WM_CREATE: // window is being created
return 0;
break;

case WM_CLOSE: // windows is closing
PostQuitMessage(0);
return 0;
break;

case WM_PAINT: // window needs updating
hDC = BeginPaint(hwnd, &paintStruct);
SetTextColor(hDC, COLORREF(0x00FF0000)); // set text color to blue
TextOut(hDC, 150, 150, string, sizeof(string)-1); // display text in middle of window
EndPaint(hwnd, &paintStruct);
return 0;
break;

default:
break;
}

return (DefWindowProc(hwnd, message, wParam, lParam));
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass; // window class
HWND hwnd; // window handle
MSG msg; // message
bool done; // flag saying when our app is complete

// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // white background
windowClass.lpszMenuName = NULL; // no menu
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon

// register the windows class
if (!RegisterClassEx(&windowClass))
return 0;

// class registered, so now create our window
hwnd = CreateWindowEx(NULL, // extended style
"MyClass", // class name
"A REAL Windows Application!", // app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU, // style
100, 100, // x,y coordinate
400, 400, // width, height
NULL, // handle to parent
NULL, // handle to menu
hInstance, // application instance
NULL); // no extra params

// check if window creation failed (hwnd would equal NULL)
if (!hwnd)
return 0;

done = false; // intialize the loop condition variable

// main message loop
while (!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);

if (msg.message == WM_QUIT) // do we receive a WM_QUIT message?
{
done = true; // if so, time to quit the application
}
else
{
TranslateMessage(&msg); // translate and dispatch to event queue
DispatchMessage(&msg);
}
}

return msg.wParam;
}


Quote:

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Program Files\Abyss Web Server\htdocs\fft_online\compwinapp\main.cpp" -o "C:\Program Files\Abyss Web Server\htdocs\fft_online\compwinapp\main.exe" -I"C:\Dev-Cpp\include\c++\3.3.1" -I"C:\Dev-Cpp\include\c++\3.3.1\mingw32" -I"C:\Dev-Cpp\include\c++\3.3.1\backward" -I"C:\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp: In
function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:73: warning: passing

NULL used for non-pointer argument passing 1 of `HWND__*
CreateWindowExA(long unsigned int, const CHAR*, const CHAR*, long unsigned
int, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:73: warning: argument
to non-pointer type `long unsigned int' from NULL
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:84: warning: passing
NULL used for non-pointer argument passing 3 of `BOOL PeekMessageA(tagMSG*,
HWND__*, unsigned int, unsigned int, unsigned int)'
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:84: warning: argument

to non-pointer type `unsigned int' from NULL
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:84: warning: passing

NULL used for non-pointer argument passing 4 of `BOOL PeekMessageA(tagMSG*,
HWND__*, unsigned int, unsigned int, unsigned int)'
C:/Program Files/Abyss Web Server/htdocs/fft_online/compwinapp/main.cpp:84: warning: argument
to non-pointer type `unsigned int' from NULL

C:\DOCUME~1\Andrew\LOCALS~1\Temp/ccEDbaaa.o(.text+0xb4):main.cpp: undefined reference to `SetTextColor@8'
C:\DOCUME~1\Andrew\LOCALS~1\Temp/ccEDbaaa.o(.text+0xe1):main.cpp: undefined reference to `TextOutA@20'
C:\DOCUME~1\Andrew\LOCALS~1\Temp/ccEDbaaa.o(.text+0x1ce):main.cpp: undefined reference to `GetStockObject@4'

Execution terminated


Sorry for the large amount of code and stuff. I didn't want to post it right away unless I needed to. Thanks for any help.

Share this post


Link to post
Share on other sites
Well, I know how to fix the linker errors: Project -> Project Options -> General -> Type and select 'Windows GUI'. That tells the compiler that it will use the Windows GUI functions (with all of the libraries and such).

EDIT: Don't worry, we all have those moments. (Took me a little while to figure out too)

[Edited by - deadimp on January 16, 2005 8:53:16 PM]

Share this post


Link to post
Share on other sites

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this