读书人

很奇怪,该怎么解决

发布时间: 2012-03-07 09:13:51 作者: rapoo

很奇怪
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]= "窗口 ";
char lpszTitle[]= "My_Sixth_Windows ";
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return 0;
}
hwnd=CreateWindow(lpszClassName,lpszTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
HFONT hF;
int i,j;
SIZE size;
string str= "欲穷千里目更上一层楼 ";
switch(message)
{
case WM_PAINT:
hDC=BeginPaint(hwnd,&ps);
SetBkColor(hDC,RGB(255,255,255));
hF=CreateFont(30,0,0,0,1000,1,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH ,
"大号字 ");
SelectObject(hDC,hF);
while(true)
{
for(i =1;i <= 4;i++)
{
switch(i)
{case 1:
SetTextColor(hDC,RGB(255,0,0));
break;
case 2:
SetTextColor(hDC,RGB(0,255,0));
break;
case 3:
SetTextColor(hDC,RGB(0,0,0));
break;

case 4:
SetTextColor(hDC,RGB(0,0,255));
break;
}
for(j = 0;j < 10;j++)
{
GetTextExtentPoint32(hDC,str.c_str(),j,&size);
TextOut(hDC,400-2*size.cx,200,str.c_str(),2*(j+1));
Sleep(300);
}
TextOut(hDC,400-2*size.cx,200,str.c_str(),20);
Sleep(300);
SetTextColor(hDC,RGB(255,255,255));
TextOut(hDC,400-2*size.cx,200,str.c_str(),20);
}
}
EndPaint(hwnd,&ps);
DeleteObject(hF);
break;
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}

为什么去掉for(j = 0;j < 10;j++)
{
GetTextExtentPoint32(hDC,str.c_str(),j,&size);
TextOut(hDC,400-2*size.cx,200,str.c_str(),2*(j+1));
Sleep(300);
}
TextOut(hDC,400-2*size.cx,200,str.c_str(),20);
Sleep(300);
SetTextColor(hDC,RGB(255,255,255));
TextOut(hDC,400-2*size.cx,200,str.c_str(),20);
中的TextOut(hDC,400-2*size.cx,200,str.c_str(),20);
Sleep(300);
两行,不能显示出来“楼”字呢


[解决办法]
不懂
帮你顶一下
------解决方案--------------------


str= "欲穷千里目更上一层楼 ";这里面一共是21个字符,不是20个字符.
for(j = 0;j < 10;j++)
{
GetTextExtentPoint32(hDC,str.c_str(),j,&size);
TextOut(hDC,400-2*size.cx,200,str.c_str(),2*(j+1));
//这样改下就可以了TextOut(hDC,400-2*size.cx,200,str.c_str(),2*(j+1)+1);

Sleep(300);
}

读书人网 >C++

热点推荐