PDA

View Full Version : my application still running, how if is closed?



oscar leo
03-27-2011, 05:46 PM
I using wxwidgets and opengl with wxcanvas but when i close my application, the Visual Studio stay running i need to open the task manager to finalize with the process
why still running my app? if it's "closed"

Alfonse Reinheart
03-27-2011, 07:59 PM
You should probably ask in a wxWidgets forum. This likely has nothing to do with OpenGL proper.

oscar leo
03-27-2011, 09:22 PM
also using in win32 api app in other project and happen the same


// windoGL.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "windoGL.h"
#include "gl/gl.h"
#include "gl/glu.h"
#include <cmath>
#include "OGDC.h"

#define MAX_LOADSTRING 100
#define DEFAULT_BUTTON_WIDTH 150
#define DEFAULT_BUTTON_HEIGHT 130


// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name


// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
RECT rect;
MSG msg;

cOpenGLDeviceContext oGLdevice;
HWND cRenderpanel;
HWND cCreatePaneButton;

void ResizeGLWindow(long width, long height)
{
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200, 200, -200, -200, -2000, 2000);
glMatrixMode(GL_MODELVIEW);

}

void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.6f, 0.6f, 0.6f, 1.0f);

glLoadIdentity();
glPushMatrix();
glTranslatef(0.0f, 0.0f, 0.0f);

glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);

glNormal3f( 0.0f, 0.0f,-1.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);

glNormal3f( 0.0f, 1.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);

glNormal3f( 0.0f,-1.0f, 0.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);

glNormal3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);

glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glEnd();

glPopMatrix();
SwapBuffers(oGLdevice.hDC);
}

void WMSize(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
GetClientRect(hWnd, &amp;rect);
MoveWindow(cRenderpanel,DEFAULT_BUTTON_WIDTH, 0, rect.right-rect.left-DEFAULT_BUTTON_HEIGHT, rect.bottom-rect.top, true);

GetClientRect(cRenderpanel, &amp;rect);
ResizeGLWindow(rect.right-rect.left, rect.bottom-rect.top);

}

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;



// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WINDOGL, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{

return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOGL));

// Main message loop:
while (GetMessage(&amp;msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg))
{
TranslateMessage(&amp;msg);
DispatchMessage(&amp;msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOGL));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WINDOGL);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&amp;wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
//HWND createTextwin;
//HWND cRenderpanel;
// HWND cCreatePaneButton;



hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

// createTextwin = CreateWindow(L"TExt", NULL, WS_EX_CLIENTEDGE | WS_VISIBLE | WS_CHILD, 0, 100, DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT, hWnd, NULL, hInstance,NULL);

cCreatePaneButton = CreateWindow(L"Button", L"Create Test", WS_CHILD | WS_VISIBLE,
0, 100, DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT, hWnd, NULL, hInstance, NULL);

cRenderpanel = CreateWindow(L"STATIC", NULL, WS_CHILD |WS_VISIBLE| WS_BORDER , DEFAULT_BUTTON_WIDTH, 0, rect.right-rect.left-DEFAULT_BUTTON_WIDTH, rect.bottom-rect.top, hWnd, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

GetClientRect(cRenderpanel, &amp;rect);
ResizeGLWindow(rect.right-rect.left, rect.bottom-rect.top);

HDC hDC = GetDC(hWnd);
ReleaseDC(hWnd, hDC);

if(!oGLdevice.Init(cRenderpanel)) return(0);

while (1)
{
Render();

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

}
oGLdevice.Release(cRenderpanel);
return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &amp;ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &amp;ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);


case WM_SIZE:
WMSize(hWnd, message, wParam, lParam);
}
return 0;

HGLRC hWindowRC = wglCreateContext(hdc);
glClearColor(0.75f, 0.75f, 0.75f, 1.0f);
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}


#include <Windows.h>

class cOpenGLDeviceContext
{
public:
HDC hDC;
HGLRC glrc;

cOpenGLDeviceContext();
~cOpenGLDeviceContext();

bool Init(HWND hWnd, unsigned char color_bits= 24, unsigned char depth_bits=32);
bool Release(HWND hWnd);
};

bool cOpenGLDeviceContext::Init(HWND hWnd, unsigned char color_bits, unsigned char depth_bits)
{
PIXELFORMATDESCRIPTOR pfd;

int PixelFormat;

hDC = GetDC(hWnd);

if(hDC == NULL)
{
MessageBox(hWnd, L"Error: Can't Get Device Context for Windows", L"ERROR", MB_OK | MB_ICONERROR);
return (false);
}

memset(&amp;pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.cColorBits = color_bits;
pfd.cDepthBits = depth_bits;

PixelFormat = ChoosePixelFormat(hDC, &amp;pfd);
if(PixelFormat == 0)
{
MessageBox(hWnd, L"Error: Can't choose pixel format", L"ERROR", MB_OK | MB_ICONERROR);
ReleaseDC(hWnd, hDC);
hDC = NULL;
return(false);
}

if(SetPixelFormat(hDC, PixelFormat, &amp;pfd) == 0)
{
MessageBox(hWnd, L"Error: Can't Set Pixel Format", L"ERROR", MB_OK| MB_ICONERROR);
ReleaseDC(hWnd, hDC);
hDC = NULL;
return(false);
}

glrc = wglCreateContext(hDC);
if(glrc == NULL)
{
MessageBox(hWnd, L"ERROR: Can't create GL Context", L"ERROR", MB_OK | MB_ICONERROR);
wglDeleteContext(glrc);
ReleaseDC(hWnd, hDC);
hDC = NULL;
return(false);
}

if(!wglMakeCurrent(hDC, glrc))
{
MessageBox(hWnd, L"ERROR: Can't Make Current GL Context", L"ERROR", MB_OK | MB_ICONERROR);
wglDeleteContext(glrc);
ReleaseDC(hWnd, hDC);
glrc = NULL;
hDC = NULL;
return(false);
}

return (true);
}

bool cOpenGLDeviceContext::Release(HWND hWnd)
{
if(hDC == NULL || glrc == NULL)
return (false);

if(wglMakeCurrent(NULL, NULL) == false)
{
MessageBox(hWnd, L"ERROR", L"Release Failed", MB_OK | MB_ICONERROR);
return (false);
}

if(wglDeleteContext(glrc) == false)
{
MessageBox(hWnd, L"ERROR", L"Release Error", MB_OK | MB_ICONERROR);
return (false);

}
glrc = NULL;

if(ReleaseDC(hWnd, hDC) == false)
{
MessageBox(hWnd, L"ERROR", L"Release Error", MB_OK | MB_ICONERROR);
return (false);
}
return (true);
}

cOpenGLDeviceContext::cOpenGLDeviceContext()
{
}

cOpenGLDeviceContext::~cOpenGLDeviceContext()
{

}

mhagain
03-28-2011, 10:31 AM
My guess: GetMessage can return -1 if there is an error (http://msdn.microsoft.com/en-us/library/ms644936%28v=vs.85%29.aspx), you're only checking for 0 as your exit condition, an error is happening and hence you never exit your message loop.

oscar leo
03-28-2011, 05:45 PM
ho!! thanks I've create other message loop so i delete and works perfectly