开发者

Library for making Win32 windows?

I want to experiment with some D3D programming, but I hate writing code to create and manage Win32 windows. I really don't like the native Win32 API. Is there any libraries or helper classes out there that make it easier t开发者_开发问答o create and manage Win32 window objects?

Thanks


There is very little handling of Win32 windows you actually need to do.

You could try this, for example:

ATOM MyRegisterClass( HINSTANCE hInstance, TCHAR* szWindowClass );
HWND InitInstance(HINSTANCE hInstance, int nCmdShow, TCHAR* szWindowClass, TCHAR* szTitle, int width, int height );

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    // TODO: Place code here.
    HACCEL hAccelTable;

    // Initialize global strings
    MyRegisterClass( hInstance, _T( "MyWinClass" ) );

    // Perform application initialization:
        HWND hWnd = InitInstance (hInstance, SW_SHOWDEFAULT, _T( "MyWinClass" ), _T( "D3D Renderer" ), 1024, 768 );
    if ( hWnd == NULL ) 
    {
        return FALSE;
    }

    // INIT D3D!
    // INIT D3D!
    // INIT D3D!


    MSG msg;
    msg.message = 0;
    // Main message loop:
    while( msg.message != WM_QUIT ) 
    {
        // DO D3D RENDERING!
        // DO D3D RENDERING!
        // DO D3D RENDERING!

        if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
            Sleep( 0 );
        }
    }

    // SHUTDOWN D3D!
    // SHUTDOWN D3D!
    // SHUTDOWN D3D!

    return 0;
}

ATOM MyRegisterClass( HINSTANCE hInstance, TCHAR* szWindowClass )
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX); 

    wcex.style          = CS_CLASSDC;
    wcex.lpfnWndProc    = (WNDPROC)WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = NULL;
    wcex.hCursor        = NULL;
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = NULL;

    return RegisterClassEx(&wcex);
}

HWND InitInstance(HINSTANCE hInstance, int nCmdShow, TCHAR* szWindowClass, TCHAR* szTitle, int width, int height )
{
   hInst = hInstance; // Store instance handle in our global variable

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

   if ( hWnd == NULL )
   {
      return hWnd;
   }

   ShowWindow(ghWnd, nCmdShow);
   UpdateWindow(ghWnd);

   return hWnd;
}

And that is literally all the specifically windowing related code you need.


You might take a look at WTL.


Qt, wxWidgets, FLTK, and GTK+, are a few of the most obvious possibilities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜