C++ 学习之路(四)_itoa_s strcat_s

_itoa_s:  将整数转为字符串

 strcat_s:连接两个字符串

1.render 代码部分

#pragma once

class lsfMain
{
public:

	void render();
	bool hitPong(int x, int y, int sx, int sy, int sw, int sh);
	void WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	lsfMain(LPDIRECT3DDEVICE9 pDevice, HWND hwnd);
	LPDIRECT3DDEVICE9 m_pDevice;
	HWND m_hwnd;
	~lsfMain(void);
	LPD3DXFONT m_pFont;
	LPD3DXFONT m_pBtnFont;
};
#include "StdAfx.h"
#include ".\lsfmain.h"
#include ".\SXBFps.h"
lsfMain::lsfMain(LPDIRECT3DDEVICE9 pDevice, HWND hwnd)
{
	m_hwnd = hwnd;
	m_pDevice = pDevice;
	// 初始化字体格式,如大小,字体
	D3DXCreateFont(m_pDevice, 40, 0, FW_SEMIBOLD&FW_DEMIBOLD, 1, FALSE, DEFAULT_CHARSET,
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
		"幼圆", &m_pFont); 
	D3DXCreateFont(m_pDevice, 80, 0, FW_SEMIBOLD&FW_DEMIBOLD, 1, FALSE, DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
			"幼圆", &m_pBtnFont);
}
lsfMain::~lsfMain(void)
{
	//SAFE_DELETE(m_mainImage);
	//SAFE_DELETE(m_2DCtrl);
}
void lsfMain::render()
{
	// 画矩形
	RECT rect1 = { 5,5,1000,1000 };//FPS显示
	RECT rect = { 5,40,1000,1000 };
	RECT rectBtn = { 5,80,1000,1000 };
	//m_pFont为定义的 LPD3DXFONT类型 输出 Text 内容
	m_pFont->DrawText(NULL, "HELLO李胜福", (int)strlen("HELLO李胜福"), &rect, DT_LEFT, D3DCOLOR_XRGB(0, 255, 0));
	m_pBtnFont->DrawText(NULL, "Button", (int)strlen("Button"), &rectBtn, DT_LEFT, D3DCOLOR_XRGB(0, 0, 255));
	char buffer[60];
	char buffer2[60] = "FPS:";
	int currentFPS = getFPS();
	// 将整数转为字符串
	_itoa_s(currentFPS, buffer, 10);
	// 连接两个字符串
	strcat_s(buffer2, buffer);
	m_pFont->DrawText(NULL, buffer2, (int)strlen(buffer2), &rect1, DT_LEFT, D3DCOLOR_XRGB(255, 0, 0));

}

2.效果图如下:

C++ 学习之路(四)_itoa_s strcat_s_第1张图片

你可能感兴趣的:(c++)