Annoying problems with Visual Studio 6.0

Started by
8 comments, last by Shadow1234567890 21 years, 8 months ago
I am trying to write an OpenGL program, but for some reason it ALWAYS writes invalid files. I am guessing the .obj files are corrupted somehow. Regardless it keeps saying that it cannot open the .exe in the debug folder for writing. I have tried starting a new project with new source code, but it does the same thing. I will post my code at the end of this message, becasue I think the problem is in the code. If anyone can give me some compiler settings that can avoid this problem I will be saved (if I don't get help I simply cannot continue). Another problem I have which isn't serious but VERY ANNOYING is the fact that I am getting all the errors from webpages. They vary from errors such as "Object required" to "Missing ';'". Every message box that comes up asks me if I would like to debug. If I click debug it opens the source for the actual webpage. I want to turn this off somehow, but I am not sure how. Ok here is the code for my opengl program that insist on not working. I am new so it is very possible that my errors are simple.

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>


HDC g_hDc;		//don't create global variables
	
void SetupPixelFormat(HDC hDc) {		
	int nPixelFormat;
	static PIXELFORMATDESCRIPTOR pfd = { 
			sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW |
			PFD_SUPPORT_OPENGL |
			PFD_DOUBLEBUFFER,
			PFD_TYPE_RGBA,
			32,
			0,0,0,0,0,0,
			0,
			0,
			0,
			0,0,0,0,
			16,
			0,
			0,
			PFD_MAIN_PLANE,
			0,
			0,0,0
	};
	nPixelFormat = ChoosePixelFormat(hDc, &pfd);
	SetPixelFormat(hDc, nPixelFormat, &pfd);

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
static HGLRC hRc;
static HDC hDc;
int width, height;
switch(message) {
case WM_CREATE:
   hDc = GetDC(hwnd);
   hRc = wglCreateContext(hDc);
   g_hDc = hDc;
   SetupPixelFormat(hDc);
   wglMakeCurrent(hDc, hRc);
   return 0 ;
	
case WM_QUIT:
	wglMakeCurrent(hDc, 0);
	wglDeleteContext(hRc);
	DestroyWindow(hwnd);		////////This was suggested by someone else, not from the book!
	PostQuitMessage(0);

	return 0;
	break;		//don't use break

case WM_SIZE:
	height = HIWORD(lParam);
	width = LOWORD(lParam);
	if(height == 0) 
		height = 1;

	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	return 0;
	
/*		//All of this is more appropriate in the WM_SIZE case
case WM_PAINT:
	height = HIWORD(lParam);
	width = LOWORD(lParam);
	if(height == 0) 
		height = 1;

	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	return 0;
	*/


default:
	break;
	}

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

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
	WNDCLASSEX WindowClass;
	HWND hwnd;

	MSG msg;
	bool done;
	WindowClass.cbSize = sizeof(WNDCLASSEX);
	WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	WindowClass.lpfnWndProc = WndProc;
	WindowClass.cbClsExtra = 0;
	WindowClass.cbWndExtra = 0;
	WindowClass.hInstance = hInstance;
	WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);
	WindowClass.hCursor = LoadCursor(0, IDC_CROSS);
	WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	WindowClass.hIconSm = LoadIcon(0, IDI_WINLOGO);
	WindowClass.lpszClassName = "My class";
	WindowClass.lpszMenuName = "My windows application";	

	if(!RegisterClassEx(&WindowClass))
		return 0;

		hwnd = CreateWindowEx(NULL,
		"My class",
		"My window",
		WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN |
		WS_CLIPSIBLINGS,
		0, 0, 
		512, 512,
		NULL,
		NULL,
		hInstance,
		NULL);
		
			HDC hDc = GetDC(hwnd);

		if(!hwnd)
			return 0;

		done = false;

		ShowWindow(hwnd, SW_SHOW);
		UpdateWindow(hwnd);

		while(!done) {
			PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
			if(msg.message == WM_QUIT)
			{
				done = true;
			}
			else {
				glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
				glLoadIdentity();
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				glColor3f(0.0f, 1.0f, 0.0f);

				glBegin(GL_LINES);
					glVertex3f(0.0f, 0.0f, -1.0f);
					glVertex3f(1.0f, 1.0f, -1.0f);
				glEnd();

				SwapBuffers(hDc);
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			}
		}
		return 0;
}


    
[edited by - Shadow1234567890 on August 13, 2002 12:27:32 PM] [edited by - Shadow1234567890 on August 13, 2002 12:27:51 PM] [edited by - Shadow1234567890 on August 13, 2002 12:28:34 PM]
What do you mean ''Someday become a programmer?'' I'm a programmer right now!
Advertisement
Are you sure you''re killing your program appropriately? It might still be hanging in the background so you can''t change the executable. Ctrl-Alt-Del and see if it''s there, I doubt it''s a compiler problem.

Attn moderators: This should probably be moved to one of the programming forums, right?
I''d agree, chances are WM_QUIT is not getting fired.
What BitBlt said seems the most likely cause of the problem. If that''s not it, make sure the exe file isn''t write protected.

500 error O_O
I had the same problem once with an app that didn''t exit properly. After using CTRL_ALT_DEL I could compile again. Check your Window creating code, my problem laid there.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)
Ok umm I already supplied creation and quit code...I''m not exactly sure what I did wrong, if anything...if you could tell me specifically what to change in my code that would help...I will scrutinize it more but I don''t know much windows programming...
What do you mean ''Someday become a programmer?'' I'm a programmer right now!
Just wondering... Why do you ever do PostQuitMessage(0); in the case of WM_QUIT...?

Just wondering, but from the code stuff I did, I learned to stuff the stuff you put in the WM_QUIT case, in the WM_CLOSE case... and then do a PostQuitMessage(0), and leave the main Message Pump.
quote:
Attn moderators: This should probably be moved to one of the programming forums, right?

Right.
Like everyone else said, the program probably isn''t terminating.

But about the debug errors in IE, go to tools->options->advanced and check disable script debugging
quote:
case WM_QUIT:
wglMakeCurrent(hDc, 0);
wglDeleteContext(hRc);
DestroyWindow(hwnd); ////////This was suggested by someone else, not from the book!
PostQuitMessage(0);
return 0;
break; //don''t use break


You''re trying to send a WM_QUIT message (PostQuitMessage(0)) after receiveg the WM_QUIT message. Bit of a paradox there, I think. Like Robin said, move that to WM_CLOSE and the PostQuitMessage(0) to WM_DESTROY. That should fix your problem. For more info, check out this page .

**500

This topic is closed to new replies.

Advertisement