|
|
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- // TODO: Place code here.
- MSG msg;
- HACCEL hAccelTable;
- // Initialize global strings
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_TEST, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST);
- ///
- /**
- * 创建一个 DirectDraw 对象
- */
- LPDIRECTDRAW _lpDD = NULL;
- HRESULT ddrval = DirectDrawCreate(NULL, &_lpDD, NULL);
- if (FAILED(ddrval))
- {
- MessageBox(NULL, "Failed to DirectDrawCreate", NULL, MB_OK);
- return FALSE;
- }
- LPDIRECTDRAW lpDDraw = NULL;
- if(FAILED(_lpDD->QueryInterface(IID_IDirectDraw, (LPVOID *)&lpDDraw)))
- {
- MessageBox(NULL,TEXT("DirectDraw QueryInterface error!"), TEXT("Wrong!"), MB_OK);
- return(0);
- }
- /**//**
- * 设置执行模式
- */
- if (FAILED(lpDDraw->SetCooperativeLevel(g_hwnd, DDSCL_NORMAL )))
- {
- MessageBox(NULL,TEXT("DirectDraw SetCooperativeLevel error!"), TEXT("Wrong!"), MB_OK);
- return(0);
- }
- /**//**
- * 创建一个表层
- */
- DDSURFACEDESC ddsd;
- LPDIRECTDRAWSURFACE lpDDSPrimary;
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS ;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- ddsd.dwBackBufferCount = 1;
- ddrval = lpDDraw->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
- if (FAILED(ddrval))
- {
- MessageBox(NULL, "Failed to CreateSurface", NULL, MB_OK);
- return FALSE;
- }
- LPDIRECTDRAWCLIPPER lpddclipper = NULL;
- if( FAILED( _lpDD->CreateClipper(0,&lpddclipper,NULL) ) )
- {
- MessageBox(NULL,TEXT("DirectDraw CreateClipper error!"), TEXT("Wrong!"), MB_OK);
- return(0);
- }
- if( FAILED( lpddclipper->SetHWnd(0, g_hwnd) ) )
- {
- MessageBox(NULL,TEXT("DirectDraw SetHWnd error!"), TEXT("Wrong!"), MB_OK);
- return(0);
- }
-
- if( FAILED( lpDDSPrimary->SetClipper(lpddclipper) ))
- {
- MessageBox(NULL,TEXT("DirectDraw SetClipper error!"), TEXT("Wrong!"), MB_OK);
- return(0);
- }
- HDC hdc;
- if(lpDDSPrimary->GetDC(&hdc) == DD_OK)
- {
- SetBkColor(hdc, RGB(0,0,255));
- SetTextColor( hdc,RGB(255,255,0 ) );
- TextOut( hdc, 0, 0, "test", lstrlen("test"));
- lpDDSPrimary->ReleaseDC(hdc);
- }
- // Main message loop:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return msg.wParam;
- }
复制代码 |
|