C++ Fenster Erstellen funzt nicht...

Vicki

Cadet 3rd Year
Registriert
Juli 2007
Beiträge
48
Hi Leuts,

hoffe, dass mir jemand helfen kann.
Habe bisher C, Ada und Java programmiert.

Nun wollte ich einwenig in c++ einsteigen mit diesem Tut:
http://www.directxtutorial.com/index.aspx
Ich benutze Visual Studio 08.

Hierzu wollte ich zu allererst ein einfaches leeres Fenster erstellen, wie hier beschrieben:
http://www.directxtutorial.com/Tutorial9/A-Win32/dx9A3.aspx

Ich habe den Code, der da steht 1 zu 1 kopiert:
Code:
// include the basic windows header file
#include <windows.h>
#include <windowsx.h>

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam);

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    // the handle for the window, filled by a function
    HWND hWnd;
    // this struct holds information for the window class
    WNDCLASSEX wc;

    // clear out the window class for use
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass1";

    // register the window class
    RegisterClassEx(&wc);

    // create the window and use the result as the handle
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass1",    // name of the window class
                          L"Our First Windowed Program",   // title of the window
                          WS_OVERLAPPEDWINDOW,    // window style
                          300,    // x-position of the window
                          300,    // y-position of the window
                          500,    // width of the window
                          400,    // height of the window
                          NULL,    // we have no parent window, NULL
                          NULL,    // we aren't using menus, NULL
                          hInstance,    // application handle
                          NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);

    // enter the main loop:

    // this struct holds Windows event messages
    MSG msg;

    // wait for the next message in the queue, store the result in 'msg'
    while(GetMessage(&msg, NULL, 0, 0))
    {
        // translate keystroke messages into the right format
        TranslateMessage(&msg);

        // send the message to the WindowProc function
        DispatchMessage(&msg);
    }

    // return this part of the WM_QUIT message to Windows
    return msg.wParam;
}

// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch(message)
    {
        // this message is read when the window is closed
        case WM_DESTROY:
            {
                // close the application entirely
                PostQuitMessage(0);
                return 0;
            } break;
    }

    // Handle any messages the switch statement didn't
    return DefWindowProc (hWnd, message, wParam, lParam);
}

Ich kann das Programm normal kompilieren und starten, jedoch erscheint kein Fenster!!. Und eigentlich sollte es erscheinen...
Auch im Taskmanager wird das laufende Programm unter Prozesse angezeigt.

Habe schon einwenig gegoogelt, aber nichts vernünftiges gefunden. Kann natürlich sein,
dass ich nach den falschen Begriffen gesucht habe...

Kann es vielleicht am OS liegen?
Ich benutze Win Vista Home Premium 32bit

Hardware:
e6850
4gig ram
Gigabyte board
8800 gts 512

Falls Infos fehlen, einfach fragen. Hoffe, dass jemand Bescheid weiß ;)

Danke schonmal :)
 
Als Projekttyp habe ich win32-Projekt ausgewählt.

Müsste ja stimmen, oder?

EDIT:
Ok ich Idiot habs. Ich hätte beim Projekt Erstellen "Leeres Projekt" auswählen müssen.
Nach haufenweise Ausprobieren gings dann endlich. Danke für den Tipp mit den Projekteinstellungen :)
 
Zuletzt bearbeitet:
man man... Hast du vielleicht auch Unicode mitreingenohmen? Kann ja auch daran liegen ;)
Musst du gucke. Alles steht in den Projekteigenschaften.

Und ja, wenn du 1 zu 1 kopierst, dann gucke auch bei MSDN hilfe nach ob alles stimmt oder nicht.

Unicode, Widechar und ANSI Methoden in c++ sind teilweise unterschiedlich.
 
Zurück
Oben