具体代码如下:void RenderScene()
{
g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,0,0), 1.0f, 0);
g_D3DDevice->BeginScene();
ShowTips();
g_D3DDevice->EndScene();
g_D3DDevice->Present(NULL, NULL, NULL, NULL);
}
void ShowTips()
{
D3DXFONT_DESC d3dFont;
memset(&d3dFont,0,sizeof(d3dFont));
d3dFont.Height = 37;
d3dFont.Width = 15;
d3dFont.Weight = 1000;
d3dFont.Italic = FALSE;
d3dFont.CharSet = DEFAULT_CHARSET;
d3dFont.OutputPrecision = 0;
d3dFont.MipLevels = D3DX_DEFAULT;
d3dFont.Quality = 0;
d3dFont.PitchAndFamily = 0;
wcscpy_s(d3dFont.FaceName, L"Times New Roman");
ID3DXFont* font=0;
if(FAILED(D3DXCreateFontIndirect(g_D3DDevice, &d3dFont, &font)))
return ;
TCHAR tip[] = TEXT ("试验");
RECT rect = {::GetSystemMetrics(SM_CXSCREEN)/2-250 + 10,10,::GetSystemMetrics(SM_CXSCREEN)/2+240,50};
// HDC hdc = font->GetDC();
// SetTextColor(hdc, RGB(255,255,255)) ;
// DrawText(hdc,tip,sizeof(tip),&rect,DT_CENTER);
font->DrawText(
NULL,
tip,
-1,
&rect,
DT_CENTER,
D3DCOLOR_ARGB(0,255,0,100)
);
font->Release();
} 响应的是WM_PAINT消息 渲染有效果 但是文字未显示出来 调试 font->DrawText 返回值为36 说明执行成功了 为什么不显示呢
void CreatTipsWnd(HINSTANCE hInstance)
{
static TCHAR szAppName[] = TEXT ("tips");
wndclasstips.style = CS_HREDRAW | CS_VREDRAW ;
wndclasstips.lpfnWndProc = WndProc;
wndclasstips.cbClsExtra = 0 ;
wndclasstips.cbWndExtra = 0 ;
wndclasstips.hInstance = hInstance ;
wndclasstips.hIcon = /*LoadIcon (NULL, NULL)*/ NULL;
wndclasstips.hCursor = /*LoadCursor (NULL, IDC_ARROW)*/ NULL;
wndclasstips.hbrBackground= (HBRUSH) GetStockObject (BLACK_BRUSH);
wndclasstips.lpszMenuName = NULL ;
wndclasstips.lpszClassName= szAppName ;
if (!RegisterClass (&wndclasstips))
return ;
TipsWnd = CreateWindow( szAppName,
szAppName,
WS_EX_TOOLWINDOW|WS_POPUP,
::GetSystemMetrics(SM_CXSCREEN)/2-250,
0,
//::GetSystemMetrics(SM_CXSCREEN),
//::GetSystemMetrics(SM_CYSCREEN),
500,
100,
NULL,
NULL,
hInstance,
NULL) ;
//dx写提示
if(InitializeD3D(TipsWnd,false))
{
//show windows
RenderScene();
ShowWindow(TipsWnd,SW_SHOW);
UpdateWindow(TipsWnd);
}
//gdi写提示
// ::TextOut(hdc,r.left - 10,r.top - 15,TipContent,sizeof(TipContent));
// SetWindowPos(TipsWnd,HWND_TOPMOST, ::GetSystemMetrics(SM_CXSCREEN)/2-250,
// 0,
// 500,
// 100,SWP_HIDEWINDOW);
// ShowWindow (TipsWnd, SW_HIDE);
// UpdateWindow (TipsWnd) ;
}
这个是窗口创建 注册函数