I've been programming for 2 days now, and I ran in a problem now that I can't solve. I've been trying to find a solution for a day now, and I can't find anything.

The problem is, that a loop is exited to early, causing the program to terminate. I'll post the whole code of the file where the problem is located. The problem-loop is surrounded by red comments.

Code:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#include "global.h"
#include "structures.h"
#include "gl.h"

#define SKY_WIDTH     640
#define SKY_HEIGHT 480

LONG APIENTRY WndProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam);
GLvoid KillGLWindow(GLvoid);
BOOL CreateGLWindow(char* title, int width, int height, int bits);

/***globals***/

struct Global *G;

HDC            hdc            =    NULL;
HGLRC        hrc            =    NULL;
HWND        hwnd        =    NULL;
HINSTANCE   hInstance;


/***********
****code****
***********/

int WINAPI WinMain(    HINSTANCE    hInstance,
                    HINSTANCE    hPrevInstance,
                    LPSTR        lpszCmdParam,
                    int            nCmdShow )
{
    //declaratie variabelen
    MSG msg;
    char *appName = "Sky";

    //G een geheugenplaats toewijzen
    G = (Global *)malloc(sizeof(Global));
    initGlobal(G);

    //venster creŽren
    CreateGLWindow(appName, SKY_WIDTH, SKY_HEIGHT, 16);

    //main lus
/******************************************/
/*****************problemare..........******************/
/******************************************/
    while (!G->st->done)
    {
        if(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                G->st->done = 1;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        switch (G->ev->key)
        {
        case SKY_R:
            if (G->ev->syskey & SKY_CTRL){
                G->st->fullscreen = 1;
                KillGLWindow();
                CreateGLWindow(appName, SKY_WIDTH, SKY_HEIGHT, 16);
            }
            break;
        case SKY_ESC:
            G->st->done = 1;
            break;
        case SKY_Q:
            if (G->ev->syskey & SKY_CTRL && 
                G->ev->syskey & SKY_SHIFT &&
                G->ev->syskey & SKY_ALT) G->st->done = 1;
            break;
        }
    }
/******************************************/
/*****************problemare..........******************/
/******************************************/

    KillGLWindow();
    return msg.wParam;
}

/**************************************************************************************/

//windows event procedure
LONG APIENTRY WndProc (HWND hwnd,
                         UINT msg,
                         UINT wParam,
                         LONG lParam)
{
    switch (msg)
    {
        case WM_KEYDOWN:
            switch (wParam)
            {
                case 81:                            //Q
                    G->ev->key = SKY_Q;
                    return 0;
                case 82:                            //R
                    G->ev->key = SKY_R;
                    return 0;
                case VK_UP:                            //Pijltje Boven
                    G->ev->key = SKY_UP;
                    return 0;
                case VK_RIGHT:                        //Pijltje Rechts
                    G->ev->key = SKY_RIGHT;
                    return 0;
                case VK_DOWN:                        //Pijltje Onder
                    G->ev->key = SKY_DOWN;
                    return 0;
                case VK_LEFT:                        //Pijltje Links
                    G->ev->key = SKY_LEFT;
                    return 0;
                case VK_ESCAPE:                        //Escape
                    G->ev->key = SKY_ESC;
                    return 0;
                case VK_RETURN:
                    G->ev->key = SKY_RETURN;
                    return 0;
                case VK_CONTROL:                    //Control
                    G->ev->syskey |= SKY_CTRL;
                    return 0;
                case VK_SHIFT:                        //Shift
                    G->ev->syskey |= SKY_SHIFT;
                    return 0;
                case VK_MENU:                        //Alt
                    G->ev->syskey |= SKY_ALT;
                    return 0;
            }

        case WM_KEYUP:
            switch (wParam)
            {
                case VK_CONTROL:
                    G->ev->syskey &= ~SKY_CTRL;
                    return 0;
                case VK_SHIFT:
                    G->ev->syskey &= ~SKY_SHIFT;
                    return 0;
                case VK_MENU:
                    G->ev->syskey &= ~SKY_ALT;
                    return 0;
                default:
                    G->ev->key = 0;
                    return 0;
            }


        case WM_PAINT:
            //UpdateWindow (hwnd);
            return 0;

        case WM_CLOSE:
        case WM_DESTROY:
            G->st->done = 1;
            return 0;

        default:
            return (DefWindowProc (hwnd, msg, wParam, lParam));
    }
    return (1);
}

/**************************************************************************************/

void KillGLWindow()
{
    if (G->st->fullscreen)
    {
        //terug naar gewone desktop settings
        ChangeDisplaySettings(NULL,0);
        ShowCursor(1);

        //alles afsluiten en unregistreren
        if (hrc){
            if (!wglMakeCurrent(NULL,NULL)){
                MessageBox(NULL,"Release Of DC And RC Failed.", "SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            }

            if (!wglDeleteContext(hrc)){
                MessageBox(NULL,"Release Rendering Context Failed.", "SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            }

            hrc = NULL;
        }

        if (hdc && !ReleaseDC(hwnd,hdc)){
            MessageBox(NULL,"Release Device Context Failed.", "SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hdc = NULL;
        }

        if (hwnd && !DestroyWindow(hwnd)){
            MessageBox(NULL,"Could Not Release hWnd.", "SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hwnd = NULL;
        }

        if (!UnregisterClass("Sky",hInstance)){
            MessageBox(NULL,"Could Not Unregister Class.", "SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
            hInstance = NULL;
        }
    }
}

/**************************************************************************************/

int CreateGLWindow(char* title, int width, int height, int bits)
{
    //declaratie variabelen
    GLuint                    PixelFormat;
    DWORD                    dwExStyle;    
    DWORD                    dwStyle;    
    RECT                    WindowRect;
    PIXELFORMATDESCRIPTOR    pfd;
    WNDCLASS                wc;

    //client rechthoek
    WindowRect.left        =    (long)0;
    WindowRect.right    =    (long)width;
    WindowRect.top        =    (long)0;    
    WindowRect.bottom    =    (long)height;

    //registreren van venster klasse
    hInstance            = GetModuleHandle(NULL);
    wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc        = (WNDPROC) WndProc;
    wc.cbClsExtra        = 0;
    wc.cbWndExtra        = 0;
    wc.hInstance        = hInstance;
    wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);    
    wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = NULL;            
    wc.lpszMenuName        = NULL;        
    wc.lpszClassName    = "Sky";
    
    if (!RegisterClass (&wc)){
        MessageBox (NULL,"Failed To Register The Window Class.", "ERROR",MB_OK|MB_ICONEXCLAMATION);
        return 0;
    }

    //fullscreen settings invullen
    if (G->st->fullscreen)    
    {
        //set screensettings
        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;

        //verander screensettings
        if (ChangeDisplaySettings (&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL){
            if (MessageBox (NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?", "OPENGL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES){
                G->st->fullscreen = 0;
            }
            else{
                MessageBox (NULL,"Program Will Now Close.", "ERROR",MB_OK|MB_ICONSTOP);
                return 0;
            }
        }
    }

    //windows stijlen invullen
    if (G->st->fullscreen)    
    {
        dwExStyle    =    WS_EX_APPWINDOW;
        dwStyle        =    WS_POPUP;    
        ShowCursor(0);
    }
    else
    {
        dwExStyle    =    WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;    
        dwStyle        =    WS_OVERLAPPEDWINDOW;    
    }

    AdjustWindowRectEx(&WindowRect, dwStyle, 0, dwExStyle);

    //maak het window
    if (!(hwnd = CreateWindowEx(    dwExStyle,    
                                    "Sky",    
                                    title,        
                                    dwStyle |        
                                    WS_CLIPSIBLINGS |    
                                    WS_CLIPCHILDREN,
                                    0, 0,                
                                    WindowRect.right-WindowRect.left,
                                    WindowRect.bottom-WindowRect.top,
                                    NULL,            
                                    NULL,        
                                    hInstance,        
                                    NULL)))    
    {
        KillGLWindow();        // Reset The Display
        MessageBox (NULL, "Window Creation Error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;            
    }

    //pixelformatdescriptor
    memset(&pfd, 0, sizeof (PIXELFORMATDESCRIPTOR));

    pfd.nVersion    =    1;
    pfd.nSize        =    sizeof (PIXELFORMATDESCRIPTOR);
    pfd.dwFlags        =    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType    =    PFD_TYPE_RGBA;
    pfd.cColorBits    =    bits;


    //device context ?
    if (!(hdc = GetDC (hwnd))){
        KillGLWindow();
        MessageBox (NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;
    }

    //goed pixelformaat ?
    if (!(PixelFormat = ChoosePixelFormat (hdc, &pfd))){
        KillGLWindow();
        MessageBox (NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;
    }

    //pixelformaat gezet ?
    if (!SetPixelFormat (hdc, PixelFormat, &pfd)){
        KillGLWindow();
        MessageBox (NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;
    }

    //rendering context ?
    if (!(hrc = wglCreateContext (hdc))){
        KillGLWindow();
        MessageBox (NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;
    }

    //activeer render context
    if(!wglMakeCurrent (hdc,hrc)){
        KillGLWindow();
        MessageBox (NULL, "Can't Activate The GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
        G->st->done = 1;
        return 0;
    }

    ShowWindow (hwnd,SW_SHOW);
    SetForegroundWindow (hwnd);
    SetFocus (hwnd);
    resizeScene (width, height);

    if (!initGl()){
        KillGLWindow();
        G->st->done = 1;
        return 0;
    }

    return 1;
}
When pressing CTRL-R, this code is executed :
Code:
case SKY_R:
            if (G->ev->syskey & SKY_CTRL){
                G->st->fullscreen = 1;
                KillGLWindow();
                CreateGLWindow(appName, SKY_WIDTH, SKY_HEIGHT, 16);
            }
            break;
Now the problem is that everything inside this case is executed well (I think), but that the while loop is terminated to soon. After pressing CTRL-R, the program ends, returning 82, which is the wParam value representing 'R'.

Does anyone know what I'm doing wrong?

Thanks in advance.