Free Spline Editor
Click here to go to the Spline_Ed program

Template (II)


By Alan Baylis 24/12/2003


Download the Demo with Source

Before rewriting my OpenGL demos I decided to write a new Win32 template that uses an object orientated approach to the window creation. The program is still under development but should give you an idea of how it will work; and also give you the opportunity to have your say/input. There are a few different ways to wrap a window in an object but the one I chose to use was conceived by Bradley Manske and he describes the process well so I wont go into the details of patching the WndProc callback. For now I will just whet your appetite with a look at the new and improved WinMain function and I will write a full tutorial later when the template is finished.
int WINAPI WinMain( HINSTANCE    hInstance,
                HINSTANCE    hPrevInstance,
                LPSTR    lpCmdLine,
                int        nCmdShow)
{
    MSG    Msg;

    cWindow* MainWindow = new cWindow(hInstance, "MainWinClass", SW_SHOW);
    MainWindow->AddButton(SW_SHOW);
    MainWindow->AddButton(0, 40, 100, 40, SW_SHOW);
    MainWindow->AddDialog("DialogClass1", 300, 300, 200, 120, SW_SHOW);
    MainWindow->Dialogs[0]->AddButton(SW_SHOW);
    MainWindow->Dialogs[0]->AddDialog("DialogClass2", 400, 400, 200, 120, SW_SHOW);
    MainWindow->Dialogs[0]->Dialogs[0]->AddButton(SW_SHOW);

    SetDlgItemText(MainWindow->hWnd, MainWindow->Buttons[0]->idControl, "G'day");
    SetDlgItemText(MainWindow->hWnd, MainWindow->Buttons[1]->idControl, "Hello");
    SetDlgItemText(MainWindow->Dialogs[0]->hWnd,
        MainWindow->Dialogs[0]->Buttons[0]->idControl, "Hi");
    SetDlgItemText(MainWindow->Dialogs[0]->Dialogs[0]->hWnd,
        MainWindow->Dialogs[0]->Dialogs[0]->Buttons[0]->idControl, "Aloha");

    while(GetMessage(&Msg, NULL, 0, 0))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);

        if (key[VK_ESCAPE])
            SendMessage(MainWindow->hWnd, WM_CLOSE, 0, 0);
    }

    return Msg.wParam;
}
As you can see, it is a lot cleaner and convenient to wrap the windows, dialogs and controls in objects. The final program will modify the default settings of the windows through accessor functions and include enumerated constants to reference the controls and dialogs but this should give you the idea. Check back soon for a complete description of the source code.

Copyright © 1998 - 2010 Alan Baylis, All Rights Reserved