cant fill up hwnd wit windows data
i tried to make my own basecode for an opengl app
but it doesnt work
i narrowed the problem down to the hwnd being empty even after calling createwindow function,, help me....
heres the code, i skipped some code that has nothing to do wit the problem(...hope someone would be kind enough to read all this..)
///////////////stuff...//////////////////
#include <windows.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <gl.h>#include <glu.h>
#define WIDTH 640#define HEIGHT 480
bool keys[256];HWND hwnd;HDC hdc;HGLRC hrc;RECT rect;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
void msg(char* message)
{ MessageBox(NULL,message,"ERROR",MB_OK); }
bool fullscreen()
//code skipped because fullscreen works
//////////////important stuff..////////////////////
void WindowCreate(HINSTANCE hInst)
{
WNDCLASS wc;
memset(&wc,0,sizeof(wc));
wc.nonostyle=CS_VREDRAW|CS_HREDRAW;
wc.lpfnWndProc=WndProc;
wc.hInstance=hInst;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName="app";
if(!RegisterClass(&wc)) msg("register class error");
fullscreen();
///////////PROBLEM//////////////////////////////////
hwnd=CreateWindow("app","app",WS_POPUP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,WIDTH,HEIGHT,NULL,NULL,hInst,NULL);
////////////////////////////////////////////////////
if(!hwnd)msg("create window error");
if(!ShowWindow(hwnd,SW_SHOWNORMAL))msg("show window error");
if(!UpdateWindow(hwnd))msg("update window error");
SetFocus(hwnd);
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst, PSTR cmdshow, int cmdline)
{
WindowCreate(hInst);
hdc=GetDC(hwnd);
pixelformat();
hrc=wglCreateContext(hdc);
wglMakeCurrent(hdc,hrc);
resize(640,480);
GLinit();
//main loop was here as well as msg translate/dispatch
return (msg.wParam);
}
//////////the rest...///////////////////
bool pixelformat()
{
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd,0,sizeof(pfd));
pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion=1;
pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
pfd.dwLayerMask=PFD_MAIN_PLANE;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=16;
pfd.cDepthBits=16;
pfd.cStencilBits=0;
int pixel=ChoosePixelFormat(hdc,&pfd);
if(!pixel)msg("pixelformat choose unsuccessful");
if(!SetPixelFormat(hdc,pixel,&pfd))msg("pixelformat setting unsuccessful");
return true;
}
void resize(GLsizei width,GLsizei height)
//code skipped
void GLinit()
//code skipped
void DeInit()
//code skipped
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM
//code skipped
/i dont know how to put all code inside a white box...sorry..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement