Skip to main content
gamedev.net
🔒 Locked

windows not talking to simp program

Started by omega arts 0 replies 450+ views
Original Post
omega arts
omega arts
I rewrote all the base code that I use because I want it in differnet cpp and I have got it down to two problems one windows does not react I can not close the window and reshape it and the second problem is it does not go to fullscreen here is the code if you can tell me the problem plz show me the problem.
  
main.hextern HDC hDC;
extern HDC g_HDC;
extern HWND hwnd;
extern MSG msg;
extern DWORD dwExStyle;
extern DWORD dwStyle;
extern RECT windowRect;
extern HINSTANCE hInstance;		
extern width;
extern height;
extern bits;
extern bool fullScreen;	
extern HGLRC hRC;

HWND CreateMyWindow();
LRESULT CALLBACK WndProc(HWND, UINT , WPARAM ,LPARAM);
int WINAPI WinMain(HINSTANCE ,HINSTANCE , LPSTR,
				   int);
void render();
void goToFullScreen();

//void setupOpenGL(HWND hwnd);


void SetupPixelFormat(HDC hDC);

mainLoop();

//void CreateOpenGLWindow(HWND);

Init.cpp
#include "main.h"
HINSTANCE hInstance;
DWORD dwStyle;
DWORD dwExStyle;
MSG msg;
HDC hDC;
int height;
int width;
int bits;
HGLRC hRC;
bool fullScreen = true;
HWND hwnd;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,
				   int nShowCmd)
{
	HWND  hwnd;
   hwnd =	CreateMyWindow();

	//CreateOpenGLWindow(hwnd);


return	mainLoop();

}

HWND CreateMyWindow()
{
WNDCLASSEX windowClass;
DWORD   dwExStyle;
DWORD	dwStyle;
RECT	windowRect;
fullScreen = true;
int width = 800;
int height = 600;
int bits = 32;

windowRect.left=(long)0;
windowRect.right=(long)width;
windowRect.top=(long)0;
windowRect.bottom=(long)height;

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);
windowClass.hCursor			=LoadCursor(NULL,IDC_ARROW);
windowClass.hbrBackground	=NULL;
windowClass.lpszMenuName	=NULL;
windowClass.lpszClassName	="HELLO";
windowClass.hIconSm			=LoadIcon(NULL,IDI_WINLOGO);

if(!RegisterClassEx(&windowClass))
{
	return 0;
}

if (fullScreen)
{

	void goToFullScreen();
}
if (!fullScreen)
{
	dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
	dwStyle=WS_OVERLAPPEDWINDOW;
}

AdjustWindowRectEx(&windowRect,dwStyle,FALSE,dwExStyle);

hwnd = CreateWindowEx(NULL,"HELLO","beta",dwStyle |WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
					  0,0, windowRect.right - windowRect.left,windowRect.bottom-windowRect.top,
					  NULL,NULL, hInstance, NULL);

if (!hwnd)
return 0;

ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
SetFocus(hwnd);			
return hwnd;
}


 
void goToFullScreen()
{


if (fullScreen)
	{




	DEVMODE dmScreenSettings;
	memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
	dmScreenSettings.dmSize=sizeof(dmScreenSettings);
	dmScreenSettings.dmPelsWidth=width;
	dmScreenSettings.dmPelsHeight=height;
	dmScreenSettings.dmBitsPerPel=bits;
	dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

	if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)  !=
				DISP_CHANGE_SUCCESSFUL)
				{
		MessageBox(NULL,"Display mode failed", NULL,MB_OK);
		fullScreen=FALSE;
	}
	dwExStyle=WS_EX_APPWINDOW;
	dwStyle=WS_POPUP;
	ShowCursor(FALSE);

}	
}

/*void setupOpenGL(HWND hwnd)
{
		
	hDC=GetDC(hwnd);
	g_HDC = hDC;
	SetupPixelFormat(hDC);
	hRC=wglCreateContext(hDC);
	wglMakeCurrent(hDC,hRC);

}
*/
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,
			16,
			0,
			0,
			PFD_MAIN_PLANE,
			0,
			0, 0, 0, };

		nPixelFormat = ChoosePixelFormat(hDC, &pfd);

		SetPixelFormat(hDC, nPixelFormat, &pfd);
}
input.cpp
#include "main.h"


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
	static HGLRC hRC;
	static HDC hDC;
switch(message)
{
case WM_CREATE:
hDC=GetDC(hwnd);
	g_HDC = hDC;
	SetupPixelFormat(hDC);
	hRC=wglCreateContext(hDC);
	wglMakeCurrent(hDC,hRC);

    return 0;
	break;
case WM_CLOSE:

	wglMakeCurrent(hDC, NULL);
	wglDeleteContext(hRC);
	PostQuitMessage(0);
	return 0;
	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;
break;

default:
	break;
	
}
return (DefWindowProc(hwnd,message, wParam, lParam));
}
main.cpp
#include "main.h"
HDC g_HDC;
bool	done = false;



/*void CreateOpenGLWindow(HWND hwnd)
{
	setupOpenGL(hwnd);									
}
*/
mainLoop()
{

			while(1)
			{		
				if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		
			{		
					if (msg.message == WM_QUIT)			
					TranslateMessage(&msg);		
			DispatchMessage(&msg);
						break;		
			
				}	
			else	
			{		
				render();	
				
			}

			}
	if (fullScreen)
	{
		ChangeDisplaySettings(NULL,0);
		ShowCursor(TRUE);
	}

	return msg.wParam;
}
render.cpp
#include "main.h"

void render()
{
	glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glColor3f(1.0,.5,1.0);
	glBegin(GL_TRIANGLES);
		glVertex3f(-10.0f,0.0f,2.0f);
		glVertex3f(1.0f,0.0f,2.0f);
		glVertex3f(0.0f,1.0f,2.0f);
	glEnd();

	glFlush();
	SwapBuffers(g_HDC);

}
  
it does not want to work this is the 3rd time i have tryed to rewrite the code its upsetting because i can do kind of hi lvl programming with openGL but when i go to win32 programming I cant do it, windows is a mess
DerekSaw
DerekSaw
Just s suggestion:

...
case WM_CLOSE:
...
DestroyWindow(...);
break;
case WM_DESTROY:
...
PostQuitMessage(..);
break;
...
"after many years of singularity, i'm still searching n the event horizon" o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.