当前位置:求职简历网 > 知识 > 正文

textout

C++ TextOutA函数无法显示内容。 #includeusing namespace std;class Array_max{public: void Max_value(int array[],int n);};int main(){ Array_max T; int a[10] = {12,12,39,-34,17,134,0,

C++ TextOutA函数无法显示内容。

#includeusing namespace std;class Array_max{public: void Max_value(int array[],int n);};int main(){ Array_max T; int a[10] = {12,12,39,-34,17,134,0,45,-91,76}; T.Max_value(a,10); return 0;}void Array_max::Max_value(int array[],int n) //::这个符号是错的,是英文状态下的{ int i,max; max = array[0]; for(i = 1;i < n;i++) { if(max < array[i]) max = array[i]; } cout<


如何控制Textout函数输出的文字的颜色和背景

1、可以调用dos控制台的命令system("color xx");改变文字颜色。
设置默认的控制台文字和背景颜色。
COLOR [attr]
attr 指定控制台输出的颜色属性
颜色属性由两个十六进制数字指定 -- 第一个为背景,第二个则为文字。每个数字可以为以下任何值之一:
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 A = 淡绿色
3 = 浅绿色 B = 淡浅绿色
4 = 红色 C = 淡红色
5 = 紫色 D = 淡紫色
6 = 黄色 E = 淡黄色
7 = 白色 F = 亮白色
如果没有给定任何参数,该命令会将颜色还原到 CMD.EXE 启动时
的颜色
2、例程:


1
2
3
4
5
6
7

#include
#include


关于mfc中TextOut()的相关问题。

用TextOut想实现垂直输出,需要自己计算长度,一个字符一个字符的输出,还得要考虑汉字与英文的不同,可以写个函数来来实现,如下:
void CMyView::DrawTextVert(int x, int y, CString str, CDC*pDC)
{
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
long lHeigh = tm.tmHeight;
int nLine = 0;
for(int i=0; i<str.GetLength();i++)
{
if((BYTE)str[i] > 127)
{
pDC->TextOut(x, y+nLine*lHeigh, str.Mid(i,2));
nLine++;
i++;
}
else
{
pDC->TextOut(x, y+nLine*lHeigh, str.Mid(i,1));
nLine++;
}
}
}
在OnDraw中的测试代码为:
DrawTextVert(100,100,一个字符串,pDC);


MFC TEXTOUT()输出的字符如何垂直居中显示?

使用drawText函数吧
CRect rect;
CRect rectTmp;
GetClientRect( &rect );
rectTmp = rect;

//计算要显示的字符串高度
int height = dc.DrawText( m_szText, &rectTmp, DT_CALCRECT|DT_CENTER|DT_EDITCONTROL|DT_WORDBREAK );

//垂直、水平居中显示
rect.top += (rect.Height() - height)/2;
dc.DrawText( m_szText, &rect, DT_CENTER|DT_EDITCONTROL|DT_WORDBREAK );


一个简单的win32应用程序

#include
#include
#define IDC_EDIT1 1
#define IDC_EDIT2 2
#define IDC_STATIC 3
#define IDC_BTN 4
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
HINSTANCE hinst;
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
TCHAR* classname="test";
hinst=hInstance;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)::GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=classname;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
::RegisterClass(&wndclass);

HWND hwnd=::CreateWindow(classname,TEXT("ADD"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
250,120,NULL,NULL,hInstance,0);

::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);

MSG msg;
while(::GetMessage(&msg,NULL,0,0)){
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static double sum;
int c=01011;
static char a[20],b[20],s[40];
switch(uMsg)
{
case WM_CREATE:
{
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,10,10,60,20,hwnd,(HMENU)IDC_EDIT1,hinst,0);
::CreateWindow("STATIC","+",WS_CHILD|WS_VISIBLE|SS_CENTER,70,10,30,20,hwnd,(HMENU)IDC_STATIC,hinst,0);
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,100,10,60,20,hwnd,(HMENU)IDC_EDIT2,hinst,0);
::CreateWindow("BUTTON","=",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,170,10,60,20,hwnd,(HMENU)IDC_BTN,hinst,0);
}break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BTN:
{
::GetDlgItemText(hwnd,IDC_EDIT1,a,20);
::GetDlgItemText(hwnd,IDC_EDIT2,b,20);
sum=atof(a)+atof(b);
sprintf(s,"%s+%s=%lf",a,b,sum);
HDC hdc=::GetDC(hwnd);
::TextOut(hdc,10,40,s,strlen(s));
::ReleaseDC(hwnd,hdc);
}break;
}
}break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,40,s,strlen(s));
::EndPaint(hwnd,&ps);
}break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}


一个简单的win32程序问题(我是新手)

switch句子有问题,搞的乱七八糟,代码些清晰点
// testarray.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"


#include
#include
#include
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
void WINAPI CaretPos(int *,int *);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="libeiqi";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;

RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("libeiqi","键盘信息",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG message;
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
#define bufsize 30
static char ccharbuf[bufsize];
static int nnumchar=0;
static int narraypos=0;
static int nlnheight;
static int ncharwidht;
static int xcaret,ycaret;
int x;
HDC hdc;
TEXTMETRIC tm;
PAINTSTRUCT ps;
switch(message)
{
case WM_CHAR:


for(x=nnumchar;x>narraypos;x=x-1)
ccharbuf[x]=ccharbuf[x-1];
ccharbuf[narraypos]=(unsigned char)wParam;
narraypos=narraypos+1;
nnumchar=nnumchar+1;
CaretPos(&xcaret,&ycaret);
InvalidateRect(hwnd,NULL,TRUE);


break;
case WM_CREATE:

hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
nlnheight=tm.tmHeight+tm.tmExternalLeading;
ncharwidht=tm.tmAveCharWidth;
ycaret=nlnheight;
ReleaseDC(hwnd,hdc);

break;
case WM_SETFOCUS:

CreateCaret(hwnd,0,0,nlnheight);
CaretPos(&xcaret,&ycaret);
ShowCaret(hwnd);

break;
case WM_KILLFOCUS:
DestroyCaret();
break;
case WM_KEYDOWN:


switch(wParam)
{
case VK_DELETE:
if(narraypos==nnumchar)
MessageBox(hwnd,"缓冲区已空,没有字符可供删除。","提示",MB_OK);
else
{
for(x=narraypos;x<nnumchar;x=x+1)
ccharbuf[x]=ccharbuf[x+1];
nnumchar=nnumchar-1;
InvalidateRect(hwnd,NULL,TRUE);
}
break;
}
case WM_PAINT:


hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,ncharwidht,nlnheight,ccharbuf,nnumchar);
EndPaint(hwnd,&ps);

break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}


return 0;
}

void WINAPI CaretPos(int *xcaret,int *ycaret)
{
SetCaretPos(*xcaret,*ycaret);
}


MFC中能改变TextOut输出的字体的大小吗

当然可以,过程稍复杂,如下例子:
CDC *pDC;
//这里要将 pDC = 你要写字的那个窗口的DC
CFont newfont;//用来保存新字体
CFont *oldFont;//用来保存旧字体
newfont.CreateFontW(20,
11,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS,
_T("宋体")
);//创建新字体
oldFont=pDC->SelectObject(&newfont);//选择新字体
pDC->SetTextColor(RGB(0,255,0));//设置字体颜色
pDC->TextOutW(10, 10, pDoc->text); //输出
pDC->SelectObject(oldFont);//选择回老字体
newfont.DeleteObject();//删除新字体


知识相关

知识推荐

求职简历网为你分享个人简历、求职简历、简历模板、简历范文等求职简历知识。

Copyrights 2018-2024 求职简历网 All rights reserved.