用于制作Win32窗口的库?

时间:2010-10-31 21:53:44

标签: directx winapi

我想尝试一些D3D编程,但我讨厌编写代码来创建和管理Win32窗口。我真的不喜欢原生的Win32 API。是否有任何库或辅助类可以更容易地创建和管理Win32窗口对象?

由于

3 个答案:

答案 0 :(得分:0)

您可以查看WTL

答案 1 :(得分:0)

QtwxWidgetsFLTKGTK+是一些最明显的可能性。

答案 2 :(得分:0)

您实际需要处理的Win32窗口很少。

您可以尝试这样做,例如:

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;
}

这就是你需要的所有特定窗口相关代码。