//해당 HDC에 정보 찍기 void timeManager::render(HDC hdc) { char str[256] = {}; std::string strFrame = ""; //글자 배경모드 (TRANSPARENT: 투명, QPAQUEL: 불투명) SetBkMode(hdc, TRANSPARENT); //글자 색상 SetTextColor(hdc, RGB(255, 255, 255)); #ifdef _DEBUG if(_timer != NULL) { //프레임 찍는다 sprintf_s(str, "framePerSec : %d", _timer->getFrameRate()); TextOutA(hdc, 0, 0, str, strlen(str)); //월드 타임 찍는다(경과시간) sprintf_s(str, "worldTime : %f", _timer->getWorldTime()); TextOutA(hdc, 0, 20, str, strlen(str)); //갱신 tick 찍는다 sprintf_s(str, "elapsedTime : %f", _timer->getElapsedTime()); TextOutA(hdc, 0, 40, str, strlen(str)); } #else if(time != NULL) { //프레임 찍는다 sprintf(str, "framePerSec : %d", _timer->getFrameRate()); TextOut(hdc, 0, 0, str, strlen(str)); } #endif }
void LGameWindow::PaintLineChart(HDC hdc) { static int s_bestScore = 0; int width = GetWidth(); int height = GetHeight(); int currentBestIndex = m_bestSocreList.size() - 1; int currentBestScore = 0; if (currentBestIndex >= 0) { currentBestScore = m_bestSocreList[currentBestIndex]; if (currentBestScore > s_bestScore) s_bestScore = currentBestScore; } float hSlice = (float)width/(m_generationCount + 1); float vSlice = (float)height/((s_bestScore + 1) * 1.3f); char strCurrentBestScore[256]; int length = sprintf_s(strCurrentBestScore, 256, "Current Best Score: %d", currentBestScore); SetBkMode(hdc, TRANSPARENT); // 设置文本背景透明 TextOutA(hdc, 10, 20, strCurrentBestScore, length); SetBkMode(hdc, OPAQUE); // 设置文本背景不透明 SelectObject(hdc, m_hRedPen); float x = 0; MoveToEx(hdc, 0, height, NULL); for (unsigned int i = 0; i < m_bestSocreList.size(); ++i) { x += hSlice; LineTo(hdc, (int)x, int(height - vSlice * m_bestSocreList[i])); } int currentAvgIndex = m_avgSocoreList.size() - 1; int currentAvgScore = 0; if (currentBestIndex >= 0) { currentAvgScore = m_avgSocoreList[currentAvgIndex]; } char strCurrentAvgScore[256]; length = sprintf_s(strCurrentAvgScore, 256, "Current Avg Score: %d", currentAvgScore); SetBkMode(hdc, TRANSPARENT); // 设置文本背景透明 TextOutA(hdc, 10, 40, strCurrentAvgScore, length); SetBkMode(hdc, OPAQUE); // 设置文本背景不透明 SelectObject(hdc, m_hBluePen); x = 0; MoveToEx(hdc, 0, height, NULL); for (unsigned int i = 0; i < m_avgSocoreList.size(); ++i) { x += hSlice; LineTo(hdc, (int)x, (int)(height - vSlice * m_avgSocoreList[i])); } SelectObject(hdc, m_hOldPen); }
INT_PTR CALLBACK GameOverPro(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); static HWND hCtrlBlock; static int num = 0; HDC hDC = 0; PAINTSTRUCT PtStr; switch (message) { case WM_TIMER: SetTimer(hDlg, 0, 10000, 0); if (num) { KillTimer(hDlg, 0); PostMessage(hDlg, WM_CLOSE, wParam, lParam); } num++; break; case WM_INITDIALOG: { return (INT_PTR)TRUE; } case WM_PAINT: { char str1[20] = "YOU FOOD:"; char str2[20] = "YOU SCORE :"; char str3[20] = { 0 }; hDC = BeginPaint(hDlg, &PtStr); _itoa_s(PointNumber, str3, 20); strcat_s(str1, str3); strcat_s(str2, str3); strcat_s(str2, "0"); TextOutA(hDC, 210, 460, str1, strlen(str1)); TextOutA(hDC, 210, 490, str2, strlen(str2)); EndPaint(hDlg, &PtStr); hCtrlBlock = GetDlgItem(hDlg, IDC_PAINT); Backgroundpaste(hCtrlBlock, IDB_SNAKE, -20, 0); PostMessage(hDlg, WM_TIMER, wParam, lParam); } break; case WM_COMMAND: if (LOWORD(wParam) == ID_OK || LOWORD(wParam) == IDCANCEL) { PostMessage(hDlg, WM_CLOSE, wParam, lParam); } break; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); break; } return (INT_PTR)FALSE; }
void DrawText_GUI(int x, int y) { static DWORD t = timeGetTime(); static DWORD frm = 0; static unsigned int m_deltaTime = 0; ++frm; static char strFPS[256] = { "FPS:" }; const int maxFrm = 100; DWORD curTime = timeGetTime(); DWORD deltaT = (curTime - t); static DWORD lastTime = curTime; m_deltaTime = curTime - lastTime; lastTime = curTime; if (deltaT > 500) { float fps = frm / (deltaT / 1000.f); frm = 0; t = timeGetTime(); sprintf_s(strFPS, "FPS:%5.1f, POLY:%d", fps, draw_polys); } HDC hdc; hdc = GetDC(main_window_handle); SetTextColor(hdc, RGB(255, 255, 255)); SetBkMode(hdc, TRANSPARENT); TextOutA(hdc, x, y, strFPS, strlen(strFPS)); ReleaseDC(main_window_handle, hdc); }
void W32ColorComboBox::drawItemCallback(DRAWITEMSTRUCT &di) { RECT rectangle; rectangle.top = di.rcItem.top + 1; rectangle.bottom = di.rcItem.bottom - 2; rectangle.left = di.rcItem.left + 2; rectangle.right = rectangle.left + 3 * (myPixelHeight - 4) / 2; MoveToEx(di.hDC, rectangle.left, rectangle.top, 0); LineTo(di.hDC, rectangle.left, rectangle.bottom); LineTo(di.hDC, rectangle.right, rectangle.bottom); LineTo(di.hDC, rectangle.right, rectangle.top); LineTo(di.hDC, rectangle.left, rectangle.top); ++rectangle.top; ++rectangle.left; ZLColor color = this->color(di.itemID); HBRUSH brush = CreateSolidBrush(RGB(color.Red, color.Green, color.Blue)); FillRect(di.hDC, &rectangle, brush); DeleteObject(brush); TEXTMETRIC tm; const ZLUnicodeUtil::Ucs2String &txt = text(di.itemID); GetTextMetrics(di.hDC, &tm); if (!txt.empty()) { TextOutW(di.hDC, rectangle.right + 8, (rectangle.top + rectangle.bottom - tm.tmHeight) / 2, ::wchar(txt), txt.size() - 1); } else { std::string colorString = "("; ZLStringUtil::appendNumber(colorString, color.Red); colorString += ","; ZLStringUtil::appendNumber(colorString, color.Green); colorString += ","; ZLStringUtil::appendNumber(colorString, color.Blue); colorString += ")"; TextOutA(di.hDC, rectangle.right + 8, (rectangle.top + rectangle.bottom - tm.tmHeight) / 2, colorString.data(), colorString.length()); } }
inline void draw() { time_t t = clock(); render(&back_buffer); HDC winhdc = GetDC( winhwnd ) ; // Now copy the back buffer to the front buffer. BitBlt( winhdc, // destination buffer 0, 0, // x, y to start writing to in the destination buffer // counted from top left corner of dest HDC (window) // Width, height to copy for back_buffer.width, back_buffer.height, back_buffer.back_dc, // SOURCE buffer. We're taking from that back canvas 0, 0, // x pt, y pt to START copying from // SOURCE. counted from top left again // And we just want a straight copy. SRCCOPY ); int fps = CLOCKS_PER_SEC/(clock() - (float)t); char buffer[128]; sprintf(buffer, "FPS: %d", fps); TextOutA(winhdc, 20, 20, buffer, strlen(buffer)); ReleaseDC( winhwnd, winhdc ) ; }
void PrintMessage(char *buffer) { // Write input text in the graphics window // Input line is in the upper portion of the graphics window if (strlen(buffer) > 0) TextOutA(hdc, START_TEXT_X, start_text_y, (LPCSTR)buffer, strlen(buffer)); }
int GameScene::render() { D3DXMATRIXA16* pmat=new D3DXMATRIXA16; D3DXMatrixTranslation(pmat,0,0,0); ostringstream oss; oss<<rendercs*x; TextOutA(Hwdc,50,50,oss.str().c_str(),5); rendercs++; //测试SceneObject对象run pOList->resetIterator(); do { SceneObject*pSOm=pOList->getObject(); if(NULL==pSOm) { break; } //渲染场景的位置------------------------------------------------------------------------------------------------------------------- if(pSOm->pShap!=NULL) { RenderMesh(pSOm->pShap->mesh,pSOm->pShap->pMeshMaterials,pSOm->pShap->pMeshTextures,pSOm->pShap->dwNumMaterials,&(pSOm->mMat)); } TextOutA(Hwdc,50,100,pOList->getObject()->sName.c_str(),5); ostringstream oss2; oss2<<pOList->L_SceneObject.size(); TextOutA(Hwdc,50,150,oss2.str().c_str(),5); }while(NULL!=pOList->nextObject()); //lua测试 /* luaL_openlibs(pSLua); lua_pushcfunction(pSLua, luatestGlue); lua_setglobal(pSLua, "luatestGlue"); luaL_dofile(pSLua,"testlua.lua"); TextOutA(Hwdc,50,50,,5); */ return 1; }
///////////////////////////////////// H_TextOutA 函数 ///////////////////////////////////////// //我们的替换函数,可以在里面实现我们所要做的功能 //这里我做的是显示一个对话框,指明是替换了哪个函数 BOOL WINAPI H_TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpString,int cbString) { // FILE *stream=fopen("logfile.txt","a+t"); MessageBox(NULL,"TextOutA","APIHook_Dll ---rivershan",MB_OK); TextOutA(hdc,nXStart,nYStart,lpString,cbString);//返回原来的函数,以显示字符 // fprintf(stream,lpString); // fclose(stream); return TRUE; }
void EmfPaintEngine::drawTextItem ( const QPointF & p, const QTextItem & textItem ) { setClipping(); SetBkMode( metaDC, TRANSPARENT ); QFont f = textItem.font(); QFontMetrics fm(f); HFONT wfont = CreateFontA(fm.height() - 1, fm.averageCharWidth(), 0, 0, 10*f.weight(), f.italic(), f.underline (), f.strikeOut(), DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, f.family().toAscii().data()); SelectObject( metaDC, wfont); QColor colour = painter()->pen().color(); SetTextColor( metaDC, RGB(colour.red(), colour.green(), colour.blue())); QString text = textItem.text(); int size = text.size(); QMatrix m = painter()->worldMatrix(); XFORM xf; xf.eM11 = m.m11(); xf.eM12 = m.m12(); xf.eM21 = m.m21(); xf.eM22 = m.m22(); xf.eDx = m.dx(); xf.eDy = m.dy(); SetWorldTransform(metaDC, &xf); #ifdef Q_WS_WIN wchar_t *wtext = (wchar_t *)malloc(size*sizeof(wchar_t)); if (!wtext){ qWarning("EmfEngine: Not enough memory in drawTextItem()."); return; } size = text.toWCharArray(wtext); TextOutW(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), wtext, size); free(wtext); #else TextOutA(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), text.toLocal8Bit().data(), size); #endif xf.eM11 = 1.0; xf.eM12 = 0.0; xf.eM21 = 0.0; xf.eM22 = 1.0; xf.eDx = 0.0; xf.eDy = 0.0; SetWorldTransform(metaDC, &xf); resetClipping(); DeleteObject(wfont); }
void DropMessage(int errorlevel, const char *format, ...) { #ifdef _DEBUG char szBuffer[512]; va_list ap; va_start(ap, format); vsnprintf_s(szBuffer, 512, 512, format, ap); va_end(ap); HDC screen = GetDC(NULL); int dropcolor[] = {0x000000, 0x008888, 0x0000FF}; SetTextColor(screen, dropcolor[errorlevel]); TextOutA(screen, 0, messageOffset*16, szBuffer, strlen(szBuffer)); messageOffset = (messageOffset+1)%40; const char *szSpaces = " "; TextOutA(screen, 0, messageOffset*16, szSpaces, strlen(szSpaces)); ReleaseDC(NULL, screen); #endif }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static char s1[100], s2[100], s3[100]; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); LoadStringA(hInst, 129, s1, 100); LoadStringA(hInst, 130, s2, 100); LoadStringA(hInst, 132, s3, 100); TextOutA(hdc, 10, 10, s1, 10); TextOutA(hdc, 10, 30, s2, 10); TextOutA(hdc, 10, 50, s3, 10); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void CLevel::DrawScore() { HDC hdc = CGame::GetInstance().GetBackBuffer()->GetBFDC(); const int kiX = 0; const int kiY = m_iHeight - 14; SetBkMode(hdc, TRANSPARENT); TextOutA(hdc, kiX, kiY, m_strScore.c_str(), static_cast<int>(m_strScore.size())); }
void CtrlDisAsmView::drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> ¤tArguments) { if (line.params.empty()) { return; } // Don't highlight the selected lines. if (isInInterval(selectRangeStart, selectRangeEnd - selectRangeStart, line.info.opcodeAddress)) { TextOutA(hdc, x, y, line.params.c_str(), (int)line.params.size()); return; } int highlightedColor = 0xaabb00; if (textColor == 0x0000ff) { highlightedColor = 0xaabb77; } UINT prevAlign = SetTextAlign(hdc, TA_UPDATECP); MoveToEx(hdc, x, y, NULL); size_t p = 0, nextp = line.params.find(','); while (nextp != line.params.npos) { const std::string arg = line.params.substr(p, nextp - p); if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xffffff) { SetTextColor(hdc, highlightedColor); } TextOutA(hdc, 0, 0, arg.c_str(), (int)arg.size()); SetTextColor(hdc,textColor); p = nextp + 1; nextp = line.params.find(',', p); TextOutA(hdc, 0, 0, ",", 1); } if (p < line.params.size()) { const std::string arg = line.params.substr(p); if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xffffff) { SetTextColor(hdc, highlightedColor); } TextOutA(hdc, 0, 0, arg.c_str(), (int)arg.size()); SetTextColor(hdc,textColor); } SetTextAlign(hdc, prevAlign); }
//=========================================================================== void __fastcall Tform_Main::Timer1Timer(TObject *Sender) { if ( isChildMomEnabled == false ) return; if ( isShowTimer == false ) return; ScreenDC = GetDC(0); SelectObject(ScreenDC, fFont); TextOutA(ScreenDC, Screen->Width - 380, 100, STRMessage.c_str(), STRMessage.Length() ); if ( ScreenDC != NULL ) ReleaseDC(0, ScreenDC); ScreenDC = NULL; }
// // 함수: WndProc(HWND, UINT, WPARAM, LPARAM) // // 목적: 주 창의 메시지를 처리합니다. // // WM_COMMAND - 응용 프로그램 메뉴를 처리합니다. // WM_PAINT - 주 창을 그립니다. // WM_DESTROY - 종료 메시지를 게시하고 반환합니다. // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; // 페인트 구조체 HDC hdc; // Device Context 핸들 // WM_~ WindowMessage 의 약자. switch (message) { case WM_COMMAND: // 메뉴를 선택하면 발생되는 이벤트 wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 메뉴 선택을 구문 분석합니다. switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; // 화면 갱신 메세지 case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); // Device Context 핸들 얻음. TextOutA( hdc, 10, 10, "hello World", 11); RECT r; SetRect(&r, 100, 100, 200, 200); DrawTextA( hdc, "hello World", 11, &r, DT_CENTER); EndPaint(hWnd, &ps); // 화면 갱신 종료 } break; // 윈도우 종료 메세지 case WM_DESTROY: PostQuitMessage(0); break; // 그 밖에 나머지 메세지는 DefWindowProc() 함수에서 처리한다. default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void OutputStatus(const char *format, ...) { #ifdef _DEBUG char szBuffer[512]; va_list ap; va_start(ap, format); vsnprintf_s(szBuffer, 512, 512, format, ap); va_end(ap); HDC screen = GetDC(NULL); TextOutA(screen, 0, 40*16, szBuffer, strlen(szBuffer)); ReleaseDC(NULL, screen); #endif }
BOOL WINAPI ShadowTextOutA(HDC textdc, int x, int y, LPCSTR lptext, int cb) { BOOL bRet = FALSE; // write text buffer WriteToTextBuffer(lptext, cb); // pass on call to real function UnhookFunction((PHOOKREC)&_hrTextOutA); bRet = TextOutA(textdc, x, y, lptext, cb); HookFunction((PHOOKREC)&_hrTextOutA); return bRet; }
void TextOutWind(char *str, int color) { char String[1024]; SetTextColor(hDC, color); sprintf(String, str); int len = strlen(String); TextOutA(hDC, x, y, String, len); y += 16; }
void ZLWin32PaintContext::drawString(int x, int y, const char *str, int len) { if (myDisplayContext == 0) { return; } y -= stringHeight(); y += myTextMetric.tmDescent; int utf8len = ZLUnicodeUtil::utf8Length(str, len); if (utf8len == len) { TextOutA(myDisplayContext, x, y, str, len); } else { static ZLUnicodeUtil::Ucs2String ucs2Str; ucs2Str.clear(); ZLUnicodeUtil::utf8ToUcs2(ucs2Str, str, len, utf8len); TextOutW(myDisplayContext, x, y, ::wchar(ucs2Str), utf8len); } }
LRESULT CWindow::OnPaint(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; CHAR szText[] = "TestString²âÊÔ×Ö·û´®"; static POINT pt[] = { { 100, 10 }, { 100, 100 }, { 10, 100 }, { 10, 10 } }; BeginPaint(hWnd, &ps); TextOutA(ps.hdc, 0, 10, szText, sizeof(szText) - 1); MoveToEx(ps.hdc, pt[countof(pt) - 1].x, pt[countof(pt) - 1].y, NULL); PolylineTo(ps.hdc, pt, countof(pt)); EndPaint(hWnd, &ps); return ERROR_SUCCESS; }
void SFNetworkView::updateView() { if ( !PNetwork ) return; if ( !UpdateDisplay ) return; SFRetina& Retina = PNetwork->getRetina(); UINT32 RetinaWidth = Retina.getWidth(); HDC DC = GetDC( Handle); HDC BackBufferDC = CreateCompatibleDC( DC); SelectObject( BackBufferDC , BackBuffer); PatBlt( BackBufferDC, 0,0, ClientRect.right , ClientRect.bottom, WHITENESS); HDC RetinaDC = Retina.startDraw(DC); BitBlt( BackBufferDC , 0, 0, Retina.getWidth() , Retina.getWidth() , RetinaDC , 0, 0, SRCCOPY); Retina.endDraw(); std::vector<SFLayer>& Layers = PNetwork->getLayers(); UINT32 OffsetX = RetinaWidth + 2 ; UINT32 OffsetY = RetinaWidth + 2; for ( UINT32 I = 0 ; I < Layers.size() ; I++ ) { displayOutput(BackBufferDC , Layers[I].getWidth() , Layers[I].getOutput(), Layers[I].getTargetOutput() == NULL ? Layers[I].getSnapshot():Layers[I].getTargetOutput() , OffsetX, 0 ); OffsetX += Layers[I].getWidth() + 2 ; } OffsetX *= 2; if ( SelectedLayer == -1 ) displayReconstruction(BackBufferDC, Layers[0] , Layers[0].getOutput() , 0 , OffsetY); else displayWeights( BackBufferDC , Layers[SelectedLayer], 0, OffsetY); OffsetY += RetinaWidth + 2; char Buf[256]; sprintf_s( Buf , 256 , "%d" , PNetwork->getTrainingCount() ); TextOutA( BackBufferDC , RetinaWidth + 4 , RetinaWidth + 5 , Buf, strlen(Buf) ); StretchBlt( DC , 0, 0, ClientRect.right , (OffsetY * ClientRect.right) / OffsetX , BackBufferDC, 0, 0, OffsetX , OffsetY ,SRCCOPY); DeleteDC(BackBufferDC); ReleaseDC(Handle,DC); Scale = (float)ClientRect.right / (float)OffsetX; }
//-----------------------Render-------------------------------------- // // given a GDI surface this function renders the ship and the // landing pad //------------------------------------------------------------------- void CController::Render(HDC &surface) { //change the mapping mode so that the origin is at the bottom left //of our window and so that the y axis increases as it goes from //bottom to top SetMapMode( surface, MM_ANISOTROPIC ); SetViewportExtEx( surface, 1, -1, NULL ); SetWindowExtEx( surface, 1, 1, NULL ); SetViewportOrgEx( surface, 0, m_cyClient, NULL ); //select in the pen we want to use HPEN OldPen = (HPEN)SelectObject(surface, GetStockObject(WHITE_PEN)); //first render the stars for (int i=0; i<m_vecStarVB.size(); ++i) { //add some twinkle if (RandFloat() > 0.1) { SetPixel(surface, m_vecStarVB[i].x, m_vecStarVB[i].y, RGB(255, 255, 255)); } } //render the user controlled ship m_pUserLander->Render(surface); //render the landing pad... RenderLandingPad(surface); //return the mapping mode to its default state so text is rendered //correctly SetMapMode( surface, MM_ANISOTROPIC ); SetViewportExtEx( surface, 1, 1, NULL ); SetWindowExtEx( surface, 1, 1, NULL ); SetViewportOrgEx( surface, 0, 0, NULL ); //Render additional information SetBkMode(surface, TRANSPARENT); SetTextColor(surface, RGB(0,0,255)); string s= "Cursor Keys - Rotate Spacebar - Thrust R - Retry"; TextOutA(surface, 30, m_cyClient - 20, s.c_str(), s.size()); //replace the pen SelectObject(surface, OldPen); }
/* ANT_CANVAS::RENDER_TEXT_SEGMENT() --------------------------------- */ long long ANT_canvas::render_text_segment(ANT_point *where, ANT_rgb *colour, char *string, long long string_length, ANT_point *text_size) { TEXTMETRIC text_metrics; SIZE size; static const long long RIGHT_MARGIN = 5; HGDIOBJ hfont; SelectObject(hDC, ascii_font); SetTextColor(hDC, RGB(colour->red, colour->green, colour->blue)); TextOutA(hDC, where->x + RIGHT_MARGIN, where->y, string, string_length); GetTextExtentPointA(hDC, string, string_length, &size); text_size->x = size.cx; text_size->y = size.cy; return string_length; }
// печатать текст // NOTE: пока сделаю через GDI - это, канечно, заплатка, но // городить менеджер ресурсов, текстуры, шрифт - много работы и я не успею void RenderWindow::draw(char* text, int x, int y) { static HFONT Font = 0; if(Font == 0) { HDC hdc; long lfHeight; hdc = GetDC(NULL); lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(NULL, hdc); Font = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman"); SelectObject(reinterpret_cast<HDC>(_dc), g_hfFont); SetTextColor(reinterpret_cast<HDC>(_dc), RGB(255, 255, 255)); SetBkMode(reinterpret_cast<HDC>(_dc), TRANSPARENT); } TextOutA(reinterpret_cast<HDC>(_dc), x, y, text, strlen(text)); }
/****************************************************************************** * OleMetaFilePictFromIconAndLabel (OLE2.56) * * Returns a global memory handle to a metafile which contains the icon and * label given. * I guess the result of that should look somehow like desktop icons. * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex. * This code might be wrong at some places. */ HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16( HICON16 hIcon, LPCOLESTR16 lpszLabel, LPCOLESTR16 lpszSourceFile, UINT16 iIconIndex ) { METAFILEPICT16 *mf16; HGLOBAL16 hmf16; HMETAFILE hmf; INT mfSize; HDC hdc; if (!hIcon) { if (lpszSourceFile) { HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile); /* load the icon at index from lpszSourceFile */ hIcon = HICON_16(LoadIconA(HINSTANCE_32(hInstance), (LPCSTR)(DWORD)iIconIndex)); FreeLibrary16(hInstance); } else return 0; } FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex); hdc = CreateMetaFileW(NULL); DrawIcon(hdc, 0, 0, HICON_32(hIcon)); /* FIXME */ TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */ hmf = CloseMetaFile(hdc); hmf16 = GlobalAlloc16(0, sizeof(METAFILEPICT16)); mf16 = (METAFILEPICT16 *)GlobalLock16(hmf16); mf16->mm = MM_ANISOTROPIC; mf16->xExt = 20; /* FIXME: bogus */ mf16->yExt = 20; /* dito */ mfSize = GetMetaFileBitsEx(hmf, 0, 0); mf16->hMF = GlobalAlloc16(GMEM_MOVEABLE, mfSize); if(mf16->hMF) { GetMetaFileBitsEx(hmf, mfSize, GlobalLock16(mf16->hMF)); GlobalUnlock16(mf16->hMF); } return hmf16; }
// // Print a text to the surface // VOID TextPrint(int x, int y, LPCSTR message) { HRESULT hr; HDC hdc = NULL; // Get the device context handle. hr = IDirectDrawSurface_GetDC(ScreenVirtual,&hdc); if (hr != DD_OK) return; // Write the message. SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(255, 255, 255)); TextOutA(hdc, x, y, message, (int)strlen(message)); // Release the device context. hr = IDirectDrawSurface_ReleaseDC(ScreenVirtual,hdc); }
EXPORT BOOL CALLBACK EdrCenterTextA(HDC hdc, PRECT prc, PCSTR pString) { int iLength; SIZE size; iLength = lstrlenA(pString); GetTextExtentPoint32A(hdc, pString, iLength, &size); return TextOutA(hdc, (prc->right - prc->left - size.cx) / 2, (prc->bottom - prc->top - size.cy) / 2, pString, iLength); }
void LGameWindow::PaintGame() { m_backDC.Clear(255, 255, 255); HDC hBackDC = m_backDC.GetBackDC(); if (!m_bFastGenerate) { // 绘制所有扫雷机 m_hOldPen = (HPEN)SelectObject(hBackDC, m_hRedPen); for (int i = 0; i < m_sweeperNum && i < 6; i++) { m_backDC.Draw((IPaint*)&m_sweeperList[i]); } SelectObject(hBackDC, m_hBluePen); for (int i = 6; i < m_sweeperNum; i++) { m_backDC.Draw((IPaint*)&m_sweeperList[i]); } // 绘制地雷集合 SelectObject(hBackDC, m_hGreenPen); m_backDC.Draw((IPaint*)&m_mineSet); SelectObject(hBackDC, m_hOldPen); } else { PaintLineChart(hBackDC); } // 绘制遗传的代数 char strGeneration[256]; int length = sprintf_s(strGeneration, 256, "Generation: %d", m_generationCount); SetBkMode(hBackDC, TRANSPARENT); // 设置文本背景透明 TextOutA(hBackDC, 10, GetHeight() - 20, strGeneration, length); SetBkMode(hBackDC, OPAQUE); // 设置文本背景不透明 m_backDC.CopyToFrontDC(); }
void dispA(HWND hwnd, const char* str, ...) { va_list args; va_start(args, str); ZeroMemory(cmsg, TXTCOUNT); //StringCchPrintfA(cmsg, TXTCOUNT, str, args); vsprintf(cmsg, str, args); va_end(args); HFONT hfont, hOldfont; HDC hdc; hfont = (HFONT)GetStockObject(SYSTEM_FONT); hdc = GetDC(hwnd); hOldfont = (HFONT)SelectObject(hdc, hfont); if (hOldfont){ TextOutA(hdc, 5, text_cnt * 20, cmsg, std::strlen(cmsg)); SelectObject(hdc, hOldfont); } ReleaseDC(hwnd, hdc); text_cnt++; }