Window not appearing on-screen

I'm writing a program which can read HTML files, or at least trying to. I'm using Visual Studio 2010 Professional, so when I want to test this project out I just hit the "Debug" button at the top of the screen. In every other project I've worked on, doing this creates a window of some sort, be it a console window or otherwise, and I can see how my program works. With this project, however, doing that produces no meaningful result whatsoever, meaning that no window shows up. I've done a search on these forums for people with a similar problem and have found a number of those, yet none of their fixes work for me, or the fixes are really poorly explained. So, does anyone know why my code isn't producing a window?

DaveChrome.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

#include "stdafx.h"
#include "resource.h"

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);
void init();
void update();
void paint( HDC );

RECT clientArea;
int screenHeight = 500, screenWidth = 500;

void init()
{
	srand( time(NULL) );
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 60, 1, 0.1, 100000 );
	glMatrixMode( GL_MODELVIEW );
}

void update()
{}

void paint( HDC hDC )
{
    glClear (GL_COLOR_BUFFER_BIT);
    glPushMatrix ();
    glLoadIdentity();

    glColor3f( 0.0f, 0.0f, 1.0f );
    glBegin( GL_QUADS );
    glVertex2i( 20, -20 );
    glVertex2i( 20, -100 );
    glVertex2i( 100, -100 );
    glVertex2i( 100, -20 );
    glEnd();

    glPopMatrix ();
    SwapBuffers (hDC);
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "OpenGL Application";							
    RegisterClass (&wc);
    hWnd = CreateWindow ( "OpenGL Applicatione", "OpenGL Application",
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      100, 0, 512, 512,
      NULL, NULL, hInstance, NULL);
    EnableOpenGL (hWnd, &hDC, &hRC);
    ShowWindow( hWnd, iCmdShow );
    init();
    while (!bQuit)
    {
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
            if (msg.message == WM_QUIT)
                bQuit = TRUE;
            else
            {
				TranslateMessage (&msg);
				DispatchMessage (&msg);
            }
        else
        {
	    update();
            paint( hDC );
            Sleep(1);
        }
    }
    DisableOpenGL (hWnd, hDC, hRC);
    DestroyWindow (hWnd);
    return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
    HDC hDC;
    switch (message)
    {
		case WM_CREATE:
			return 0;

		case WM_PAINT:
			hDC = BeginPaint( hWnd, &ps );
			TextOut( hDC, 10, 10, TEXT("Hello World!"), 11 );
			//paint( hDC );
			EndPaint( hWnd, &ps );
			break;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{}
			return 0;

		case WM_CLOSE:
			PostQuitMessage (0);
			return 0;
		case WM_DESTROY:
			return 0;

		case WM_KEYDOWN:
			switch (wParam)
			{
				case VK_ESCAPE:
					PostQuitMessage(0);
					return 0;
			}
			return 0;

		default:
			return DefWindowProc (hWnd, message, wParam, lParam);
			break;
		}
}

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;
    *hDC = GetDC (hWnd);
    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);
    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC );
}

void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (hRC);
    ReleaseDC (hWnd, hDC);
}


stdafx.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <time.h>


// TODO: reference additional headers your program requires here

//OpenGL stuff
#include <gl/GL.h>
#include <gl/GLU.h>

//C++ includes
#include <iostream>
#include <fstream>
#include <vector> 


Resource.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by DaveChrome.rc
//

#define IDS_APP_TITLE			103

#define IDR_MAINFRAME			128
#define IDD_DAVECHROME_DIALOG	102
#define IDD_ABOUTBOX			103
#define IDM_ABOUT				104
#define IDM_EXIT				105
#define IDI_DAVECHROME			107
#define IDI_SMALL				108
#define IDC_DAVECHROME			109
#define IDC_MYICON				2
#ifndef IDC_STATIC
#define IDC_STATIC				-1
#endif
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NO_MFC					130
#define _APS_NEXT_RESOURCE_VALUE	129
#define _APS_NEXT_COMMAND_VALUE		32771
#define _APS_NEXT_CONTROL_VALUE		1000
#define _APS_NEXT_SYMED_VALUE		110
#endif
#endif 
Last edited on
I think you copy pasted the wrong code. This appears to be an OpenGL tutorial. In something that is expected to "read HTML files" I would expect to see the functions "CreateFile()", "ReadFile()", "ReadMemory()" maybe or "InternetOpen()" but nothing in this piece of code you posted matches what you are describing.
Topic archived. No new replies allowed.