Ich habe ein minimales win32 projekt geschrieben, das einfach ein Fenster öffnet. Dieses kann dann lediglich geschlossen werden. Das ganze wird mal ein Frame für eine OpenGL-Anwendung.
Das klappt auch prima, allerdings wird beim Programmstart neben dem eigentlichen Windows-Fenster (welches ich verschieben und schließen kann) auch noch ein Consolenfenster geöffnet. Was hat es damit auf sich und wie kann ich das vermeiden?
Wenn ich übrigens das Konsolenfenster schließe, beendet sich auch das Windows-Fenster.
Den Code habe ich mal dazu gepostet.
Danke und Gruß
Code: Alles auswählen
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
HDC m_hDC = NULL; // Private GDI Device Context
HGLRC m_hRC = NULL; // Permanent Rendering Context
HWND m_hWnd = NULL; // Holds Our Window Handle
HINSTANCE m_hInstance = NULL; // Holds The Instance Of The Application
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLvoid KillGLWindow()
{
if (m_hRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hRC);
m_hRC = NULL;
}
ReleaseDC(m_hWnd, m_hDC);
DestroyWindow(m_hWnd);
UnregisterClass("OpenGL", m_hInstance);
}
BOOL CreateGLWindow(const char *title,
int width,
int height,
int bits)
{
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left = (long) 0;
WindowRect.right = (long) width;
WindowRect.top = (long) 0;
WindowRect.bottom = (long) height;
m_hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";
RegisterClass(&wc);
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
// Create The Window
m_hWnd = CreateWindowEx(dwExStyle,
"OpenGL",
title,
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
NULL, NULL, m_hInstance, NULL);
m_hDC = GetDC(m_hWnd);
ShowWindow(m_hWnd, SW_SHOW); // Show The Window
SetForegroundWindow(m_hWnd); // Slightly Higher Priority
SetFocus(m_hWnd); // Sets Keyboard Focus To The Window
return TRUE; // Success
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
}
// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
bool bDone = false;
// Create Our OpenGL Window
if (!CreateGLWindow("mainWindow", 640, 480, 32))
{
return 0;
}
while (!bDone)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
bDone = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
// Shutdown
KillGLWindow();
return (msg.wParam);
}