>> i also changed both of the NULL's to (0) which fixed the error in line 186
There were four NULL's in the call, and only one of then was wrong! That said, zero is always valid as a NULL pointer or an integer so you should probably use it exclusively in preference to the NULL macro.
>> but i still do not understand how to fix or 'define' the 'undefined references' for CGfxOpenGL terms.
Do EXACTLY what I said! You have not created a PROJECT (winmain.cpp is not a project it is merely a source file), and you have not added CGfxOpenGL.cpp to your project. Every time you change something and it still does not work, post the log so we can see what you have done.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yeah, i created a project and added CGfxOpenGL.cpp to the project and it worked i received no errors. but theres no wnd. nothing was displayed after my compilation.
heres my compile log which states that theres nothing to be done for 'all'
Compiler: Default compiler
Building Makefile: "C:\ATimetoKill\Makefile.win"
Executing make...
make.exe -f "C:\ATimetoKill\Makefile.win" all
make.exe: Nothing to be done for `all'.
Execution terminated
Compilation successful
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> yeah, i created a project and added CGfxOpenGL.cpp to the project and it worked i received no errors.
I wonder why you did not do that the first time I suggested it or even felt the need to apologise for wasting my time?
>> heres my compile log which states that theres nothing to be done for 'all'
That will be because it has already build. To show a complete log use "Rebuild All" to force a complete re-build.
>> nothing was displayed after my compilation.
You did run the code right? It does not run automatically after compilation (unless you select that meny option that is).
You have not posted the complete code but after CreateWindowEx() your WinMain() should enter the message loop. If it does not and the program terminates, then you will never see the the window. I hesitate to suggest using the debugger because it sucks in Dev-C++, but that is the best way of tracing what your code is doing.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is the code from where WINAPI WinMain() has become intialized, to the creation of the window, CreateWindowEx()
i changed the NULL macro from CreateWindowEx(NULL, to CreateWindowEx(0, ..could that be the problem?
And yes your correct, and i do apologise, i did miss that the first time and i apreciate you telling me a second.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
DWORD dwExStyle;
DWORD dwStyle;
RECT windowRect;
g_glRender = new CGfxOpenGL;
windowRect.left=(long)0; // left value
windowRect.right=(long)windowWidth;
windowRect.top=(long)0;
windowRect.bottom=(long)windowHeight;
// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = MainWindowProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = NULL;
windowClass.lpszClassName = "GLCLass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
// register the windows class
if (!RegisterClassEx(&windowClass))
return 0;
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = windowWidth;
dmScreenSettings.dmPelsHeight = windowHeight;
dmScreenSettings.dmBitsPerPel = windowBits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) !=DISP_CHANGE_SUCCESSFUL)
{
// setting display mode failed switch to windowed
MessageBox(NULL, "Display Mode failed....LOL!", NULL, MB_OK);
fullscreen = FALSE;
}
}
if (fullscreen) // are we still FSM?
{
dwExStyle=WS_EX_APPWINDOW; // WINDOW_EXTENDED_style
dwStyle=WS_OVERLAPPEDWINDOW;
}
// adjust window to True Reqeuested size
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
// class register so now create our window
hwnd = CreateWindowEx(0, // extended style
"GLClass", // class name
"BOGLGP - An OpenGL Application",
dwStyle | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
0, 0, // "X" AND "Y" COORDINATES
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top, // width, height
NULL, // handel to parent
NULL, // handle to menu
hInstance,
NULL); // pointer to window creation data
hDC = GetDC(hwnd);
// check if window creation failed (hwnd would =0
if (!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
g_glRender->Init();
while (!exiting)
{
g_glRender->Prepare(0.0f);
g_glRender->Render();
SwapBuffers(hDC);
while(PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage (&msg, NULL, 0, 0))
{
exiting = true;
break;
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
delete g_glRender;
if (fullscreen)
{
ChangeDisplaySettings(NULL,0); // if so switch back to the destop
ShowCursor(TRUE);
}
return (int)msg.wParam;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You registerd your window Class with the name "GLCLass" but used "GLClass" for the call to CreateWindowEx() - they differ in case of the second 'L'.
You would have protected yourself from that error by using windowClass.lpszClassName for CreateWindowEx() class name parameter; then it would not matter what the class name was, even with the typo it would have worked.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i fixed the typo error, but im wondering if the WinMain() function is setup properly so that it enters the message loop, because nothing is displayed. what would i need to add anything to the project so that it might display what i need?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On the 14th January I suggested that you attempt to build the basic Win32 template code before attempting any additional code. Did you do that? Did it work? The basic Windows framework should be much the same. Compare them.
Another suggestion was to step the code in the debugger. Did you try that?
Look at the code, the window is displayed when ShowWindow() is called, but the code exits before that if hwnd is zero, which it will be if CreateWindowEx() fails. So I suggest that you check the parameters against the documentation - I did not check them all. And put a breakpoint on the exit(0) to see if that is where it is failing.
I have done very little GUI development (I work on embedded systems), and certainly none of this 'Petzold' style code for over 10 years - yet I am answering your questions. I'll tell you how - I am studying your code, your build logs, and checking the API documentation. You could do all that for yourself, and would learn much more from it. Its time to learn how to become a little more self reliant.
I have in my installation an OpenGL DevPak. I don't know where it came from or which one it is (DevPaks.org has several via teh WebUpdate tool in Dev-C++) I must have installed it to assist with someone else's problem. However the template code is as below, it runs out of the box:
CUT-----------------------------------------------
/****
* Includes
/* get the device context (DC) */*hDC=GetDC(hWnd);/* set the pixel format for the DC */
ZeroMemory(&pfd,sizeof(pfd));
pfd.nSize=sizeof(pfd);
pfd.nVersion=1;
pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=24;
pfd.cDepthBits=16;
pfd.iLayerType=PFD_MAIN_PLANE;
iFormat=ChoosePixelFormat(*hDC,&pfd);
SetPixelFormat(*hDC,iFormat,&pfd);/* create and enable the render context (RC) */*hRC=wglCreateContext(*hDC);
wglMakeCurrent(*hDC,*hRC);
i've tried a lot of things that were relevent in what is to be displayed. but something is just not telling it to give a display. also i did try and compare the code to the opengl template. i added a few things but no luck. and yes the opengl template does work on my os.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So how did you get on with the debugger? Is hwnd a valid value when ShowWindow() is called? Is ShowWindow even being called? There is a possible exit point before that.
We cannot debug it for you, but only tell you how to debug it yourself. If you want assistance, you have to tell us your actions and observations other wise we are blind.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is my compile log when i used the 'if' statement. But the (intentional?) errors are occuring when i let the program know that the window creation fails.
winmain.cpp: In function int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
winmain.cpp:162: warning: converting to non-pointer typeUINT' from NULL
C:/Dev-Cpp/include/winuser.h:3675: error: too many arguments to function `int MessageBoxA(HWND__, const CHAR, const CHAR*, UINT)'
winmain.cpp:162: error: at this point in file
winmain.cpp:163: warning: converting to non-pointer type `int' from NULL
make.exe: *** [winmain.o] Error 1
Execution terminated
Here is the code:
define WIN32_LEAN_AND_MEAN
define WIN32_EXTRA_LEAN
include <windows.h>
include <gl/gl.h>
include <gl/glu.h>
include "CGfxOpenGL.h"
bool exiting = false;
long windowWidth = 800;
long windowHeight = 600;
long windowBits = 32;
bool fullscreen = false;
HDC hDC;
// global poointer to the CGfxOpenGL fendering class
CGfxOpenGL *g_glRender = NULL;
void SetupPixelFormat(HDC hDC)
{
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // SIZE
1, // version
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0, // COLOR BITS, IGNORED
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0, // reserved
0, 0, 0, // NO LAYER, VISIBLE, DAMAGE MASK
};
pixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, pixelFormat, &pfd);
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDC;
static HGLRC hRC;
int height, width;
// Dispatch Messages
switch (uMsg)
{
case WM_CREATE:
hDC = GetDC(hWnd);
SetupPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
break;
case WM_DESTROY
:case WM_QUIT:
case WM_CLOSE:
// deselect rednering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
// send WM_QUIT message queue
PostQuitMessage(0);
break;
case WM_SIZE:
height = HIWORD(lParam); // retrireving window sizes
width = LOWORD(lParam);
g_glRender->SetupProjection(width, height);
break;
case WM_KEYDOWN: // enables users key function
int fwKeys;
LPARAM keyData;
fwKeys = (int)wParam; // virtual key code
keyData = lParam; // the key data
switch(fwKeys)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
default:
break;
}
break;
default:
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
DWORD dwExStyle;
DWORD dwStyle;
RECT windowRect;
g_glRender = new CGfxOpenGL;
windowRect.left=(long)0; // left value
windowRect.right=(long)windowWidth;
windowRect.top=(long)0;
windowRect.bottom=(long)windowHeight;
// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = MainWindowProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = NULL;
windowClass.lpszClassName = "GLClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
// register the windows class
if (!RegisterClassEx(&windowClass))
return 0;
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = windowWidth;
dmScreenSettings.dmPelsHeight = windowHeight;
dmScreenSettings.dmBitsPerPel = windowBits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) !=DISP_CHANGE_SUCCESSFUL)
{
if (!hwnd){
MessageBox(NULL, "Sigh! My window creation failed", "Error", NULL, MB_OK);
return 0;
}
fullscreen = FALSE;
}
}
if (fullscreen) // are we still FSM?
{
dwExStyle=WS_EX_APPWINDOW; // WINDOW_EXTENDED_style
dwStyle=WS_POPUP;
ShowCursor(FALSE); // hide mouse pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
// adjust window to True Reqeuested size
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
// class register so now create our window
hwnd = CreateWindowEx(0, // extended style
"GLClass", // class name
"BOGLGP - An OpenGL Application",
dwStyle | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
0, 0, // "X" AND "Y" COORDINATES
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top, // width, height
NULL, // handel to parent
NULL, // handle to menu
hInstance,
0); // pointer to window creation data
hDC = GetDC(hwnd);
// check if window creation failed (hwnd would =0
if (!hwnd) {
return 0;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
g_glRender->Init();
while (!exiting)
{
g_glRender->Prepare(0.0f);
g_glRender->Render();
SwapBuffers(hDC);
while(PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage (&msg, NULL, 0, 0))
{
exiting = true;
break;
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
delete g_glRender;
if (fullscreen)
{
ChangeDisplaySettings(NULL,0); // if so switch back to the destop
ShowCursor(TRUE);
}
return (int)msg.wParam;
}
and yeah i have tried using the debugger but i have a hard time understanding it, even after reading over the FAQ. i did use my first breakpoint on the int WINAPI winmain() and from there to the showwindow 'hwnd sw_show'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
its obvious at this point you are in way over your head.
NOW for what is the problem.
again I will state that you are not following directions.
Had you listened to me the first time about telling yourself when something fails you would have found that it has nothing to do with the ShowWindow function.
Your window class never gets registered and produces an error. This again is where you need to stop and go look at the resources provided so that you are not so clueless.
you have
// register the windows class
if (!RegisterClassEx(&windowClass)){
return 0;
}
So if this fails how do you know? you can use the debugger but at your skill level this is probably beyond you.
you should have had
// register the windows class
if (!RegisterClassEx(&windowClass)){
MessageBox(NULL, "Sigh! Registering Window failed", "Error", MB_OK);
return 0;
}
so when you run the program it would tell you that the registration of the windowclass failed.
which would then point you in the right direction.
You cannot even copy a piece of code directly from the forum! Then you cannot read and understand very clear error messages. MessageBox() takes FOUR parameters not FIVE! Where did the extra NULL come from! Its like swimming through treacle.
Then you cheerfully ignored my advice/question about the debugger. Unlike BiT, I do not believe that using a debugger is in any way "advanced". It should be learned after learning "hello, world" and before learning anything else about programming. The MessageBox (or printf) approach to debugging is fine if you know where and when to instrument your code, but it is not very flexible or practical in the longer term, or for more complex problems.
As BiT says read the documentation. It seems that wherever you are copying this stuff from is not a particularly reliable resource. There really is no substitute for knowing what you are doing!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>> i also changed both of the NULL's to (0) which fixed the error in line 186
There were four NULL's in the call, and only one of then was wrong! That said, zero is always valid as a NULL pointer or an integer so you should probably use it exclusively in preference to the NULL macro.
>> but i still do not understand how to fix or 'define' the 'undefined references' for CGfxOpenGL terms.
Do EXACTLY what I said! You have not created a PROJECT (winmain.cpp is not a project it is merely a source file), and you have not added CGfxOpenGL.cpp to your project. Every time you change something and it still does not work, post the log so we can see what you have done.
Clifford
yeah, i created a project and added CGfxOpenGL.cpp to the project and it worked i received no errors. but theres no wnd. nothing was displayed after my compilation.
heres my compile log which states that theres nothing to be done for 'all'
Compiler: Default compiler
Building Makefile: "C:\ATimetoKill\Makefile.win"
Executing make...
make.exe -f "C:\ATimetoKill\Makefile.win" all
make.exe: Nothing to be done for `all'.
Execution terminated
Compilation successful
>> yeah, i created a project and added CGfxOpenGL.cpp to the project and it worked i received no errors.
I wonder why you did not do that the first time I suggested it or even felt the need to apologise for wasting my time?
>> heres my compile log which states that theres nothing to be done for 'all'
That will be because it has already build. To show a complete log use "Rebuild All" to force a complete re-build.
>> nothing was displayed after my compilation.
You did run the code right? It does not run automatically after compilation (unless you select that meny option that is).
You have not posted the complete code but after CreateWindowEx() your WinMain() should enter the message loop. If it does not and the program terminates, then you will never see the the window. I hesitate to suggest using the debugger because it sucks in Dev-C++, but that is the best way of tracing what your code is doing.
Clifford
Heres the full compile log after i selected 'rebuild all'
Compiler: Default compiler
Building Makefile: "C:\ATimetoKill\Makefile.win"
Executing make clean
rm -f CGfxOpenGL.o winmain.o winmain.exe
g++.exe -c CGfxOpenGL.cpp -o CGfxOpenGL.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
g++.exe -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
g++.exe CGfxOpenGL.o winmain.o -o "winmain.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib/GL" -lopengl32 -lglu32 -lglut32 -lwinmm -mwindows
Execution terminated
Compilation successful
here is the code from where WINAPI WinMain() has become intialized, to the creation of the window, CreateWindowEx()
i changed the NULL macro from CreateWindowEx(NULL, to CreateWindowEx(0, ..could that be the problem?
And yes your correct, and i do apologise, i did miss that the first time and i apreciate you telling me a second.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
DWORD dwExStyle;
DWORD dwStyle;
RECT windowRect;
hDC = GetDC(hwnd);
You registerd your window Class with the name "GLCLass" but used "GLClass" for the call to CreateWindowEx() - they differ in case of the second 'L'.
You would have protected yourself from that error by using windowClass.lpszClassName for CreateWindowEx() class name parameter; then it would not matter what the class name was, even with the typo it would have worked.
Clifford
i fixed the typo error, but im wondering if the WinMain() function is setup properly so that it enters the message loop, because nothing is displayed. what would i need to add anything to the project so that it might display what i need?
OT
Have you ever done any programming before?
If No go Here: http://newdata.box.sk/bx/c/
not the best but will get you familiarized with C++
If yes
Have you ever done Windows Programming?
If No go Here: http://winprog.org/tutorial/
windows tutorials
if Yes
Have you ever done anything in OpenGL?
if No go Here: http://nehe.gamedev.net/
and here: http://www.opengl.org/
and here: http://www.opengl.org/code/
its obvious at this point you are in way over your head.
On the 14th January I suggested that you attempt to build the basic Win32 template code before attempting any additional code. Did you do that? Did it work? The basic Windows framework should be much the same. Compare them.
Another suggestion was to step the code in the debugger. Did you try that?
Look at the code, the window is displayed when ShowWindow() is called, but the code exits before that if hwnd is zero, which it will be if CreateWindowEx() fails. So I suggest that you check the parameters against the documentation - I did not check them all. And put a breakpoint on the exit(0) to see if that is where it is failing.
I have done very little GUI development (I work on embedded systems), and certainly none of this 'Petzold' style code for over 10 years - yet I am answering your questions. I'll tell you how - I am studying your code, your build logs, and checking the API documentation. You could do all that for yourself, and would learn much more from it. Its time to learn how to become a little more self reliant.
I have in my installation an OpenGL DevPak. I don't know where it came from or which one it is (DevPaks.org has several via teh WebUpdate tool in Dev-C++) I must have installed it to assist with someone else's problem. However the template code is as below, it runs out of the box:
CUT-----------------------------------------------
/****
* Includes
*****/
include <windows.h>
include <gl/gl.h>
/****
* Function Declarations
*****/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
/****
* WinMain
*****/
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
}
/****
* Window Procedure
*****/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
}
/***
* Enable OpenGL
****/
void EnableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
}
/**
* Disable OpenGL
***/
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}
END-CUT-----------------------------------------------
Clifford
i've tried a lot of things that were relevent in what is to be displayed. but something is just not telling it to give a display. also i did try and compare the code to the opengl template. i added a few things but no luck. and yes the opengl template does work on my os.
So how did you get on with the debugger? Is hwnd a valid value when ShowWindow() is called? Is ShowWindow even being called? There is a possible exit point before that.
We cannot debug it for you, but only tell you how to debug it yourself. If you want assistance, you have to tell us your actions and observations other wise we are blind.
repost this info,
Compile log
Code you are using and not just a snippit.
for reference... get use to using {} for "if" statements
This
if (!hwnd){
return 0;
}
is better then this
if (!hwnd)
return 0;
also Tell yourself that it failed by using a messagebox
if (!hwnd){
MessageBox(NULL, "Crap my window creation failed", "Error", MB_OK);
return 0;
}
i appreciate your help! Thank You!
Here is my compile log when i used the 'if' statement. But the (intentional?) errors are occuring when i let the program know that the window creation fails.
Compiler: Default compiler
Building Makefile: "C:\ATimetoKill\Makefile.win"
Executing make...
make.exe -f "C:\ATimetoKill\Makefile.win" all
g++.exe -c winmain.cpp -o winmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -g3 -O0
winmain.cpp: In function
int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': winmain.cpp:162: warning: converting to non-pointer type
UINT' from NULLC:/Dev-Cpp/include/winuser.h:3675: error: too many arguments to function `int MessageBoxA(HWND__, const CHAR, const CHAR*, UINT)'
winmain.cpp:162: error: at this point in file
winmain.cpp:163: warning: converting to non-pointer type `int' from NULL
make.exe: *** [winmain.o] Error 1
Execution terminated
Here is the code:
define WIN32_LEAN_AND_MEAN
define WIN32_EXTRA_LEAN
include <windows.h>
include <gl/gl.h>
include <gl/glu.h>
include "CGfxOpenGL.h"
bool exiting = false;
long windowWidth = 800;
long windowHeight = 600;
long windowBits = 32;
bool fullscreen = false;
HDC hDC;
// global poointer to the CGfxOpenGL fendering class
CGfxOpenGL *g_glRender = NULL;
void SetupPixelFormat(HDC hDC)
{
int pixelFormat;
and yeah i have tried using the debugger but i have a hard time understanding it, even after reading over the FAQ. i did use my first breakpoint on the int WINAPI winmain() and from there to the showwindow 'hwnd sw_show'
AGAIN
Have you ever done any programming before?
If No go Here: http://newdata.box.sk/bx/c/
not the best but will get you familiarized with C++
If yes
Have you ever done Windows Programming?
If No go Here: http://winprog.org/tutorial/
windows tutorials
if Yes
Have you ever done anything in OpenGL?
if No go Here: http://nehe.gamedev.net/
and here: http://www.opengl.org/
and here: http://www.opengl.org/code/
its obvious at this point you are in way over your head.
NOW for what is the problem.
again I will state that you are not following directions.
Had you listened to me the first time about telling yourself when something fails you would have found that it has nothing to do with the ShowWindow function.
Your window class never gets registered and produces an error. This again is where you need to stop and go look at the resources provided so that you are not so clueless.
you have
// register the windows class
if (!RegisterClassEx(&windowClass)){
return 0;
}
So if this fails how do you know? you can use the debugger but at your skill level this is probably beyond you.
you should have had
// register the windows class
if (!RegisterClassEx(&windowClass)){
MessageBox(NULL, "Sigh! Registering Window failed", "Error", MB_OK);
return 0;
}
so when you run the program it would tell you that the registration of the windowclass failed.
which would then point you in the right direction.
// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = MainWindowProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = NULL; //DELETE THIS LINE, you already have it defined below
windowClass.lpszClassName = "GLClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
The window class is failing cause you have not defined all the correct parameters
This is when you should go here http://www.functionx.com/win32/Lesson01b.htm and
go here http://msdn2.microsoft.com/en-us/library/ms633577(VS.85).aspx
so with the resources provided, find what parameter you are missing.
You are driving me nuts!
You cannot even copy a piece of code directly from the forum! Then you cannot read and understand very clear error messages. MessageBox() takes FOUR parameters not FIVE! Where did the extra NULL come from! Its like swimming through treacle.
Then you cheerfully ignored my advice/question about the debugger. Unlike BiT, I do not believe that using a debugger is in any way "advanced". It should be learned after learning "hello, world" and before learning anything else about programming. The MessageBox (or printf) approach to debugging is fine if you know where and when to instrument your code, but it is not very flexible or practical in the longer term, or for more complex problems.
As BiT says read the documentation. It seems that wherever you are copying this stuff from is not a particularly reliable resource. There really is no substitute for knowing what you are doing!
... further hint WNDCLASSEX has 12 members, you have assigned a value to only 11, and one of them twice!
:)
The WNDCLASSEX 12th member (the one i did twice) should have been the hbr background.
i also did not have to have "error" in my message box it just made things further complicated.
What i did need to have was the brackets after the "if" statements, and one after the return 0 statement.
Thanks a lot! im so greatful!!!
Hoorah!