在vc中写了一个Win32程序,希望动态画出一条正弦曲线,可当在屏幕上显示所画的点数时,数字后面却跟有乱码, 不知道为什么!!!请高手赐教, 小弟不胜感激!!
//resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by SIN.RC
//
#define IDR_MAINFRAME 128
#define IDD_SIN_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_SIN             107
#define IDI_SMALL 108
#define IDC_SIN             109
#define IDC_MYICON 2
#define IDC_STATIC                     -1
// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE        129
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           110
#endif
#endif
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Sin.cpp : Defines the entry point for the application.
//#include <windows.h>
#include "resource.h"
#include <stdio.h>
#include <math.h>#define MAX_LOADSTRING 100
#define TIMER_ID 1
#define NUM    1000
#define TWOPI  (2 * 3.14159)
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//VOID CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime);
        int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SIN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow)) 
{
return FALSE;
} hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIN);
while (GetMessage(&msg, NULL, 0, 0)) 
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return msg.wParam;
}ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIN);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);//默认的背景色为COLOR_WINDOW+1即白色
wcex.lpszMenuName = (LPCSTR)IDC_SIN;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;   hInst = hInstance;    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);   if (!hWnd)
   {
      return FALSE;
   }   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);   return TRUE;
}
POINT point;//当前点
POINT prevpt;//保存前一点
static int i = 0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int  cxClient, cyClient ;
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
RECT rt;
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) 
{
case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
case WM_COMMAND:
wmId    = LOWORD(wParam); 
wmEvent = HIWORD(wParam); 
// Parse the menu selections:
switch (wmId)
{

case IDM_ABOUT:
   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
   break;
case IDM_EXIT:
   DestroyWindow(hWnd);
   break;
default:
   return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
GetClientRect(hWnd, &rt);

point.x =  0;
point.y =  rt.bottom/2;
prevpt.x = 0;
prevpt.y = rt.bottom/2;
SetTimer(hWnd,TIMER_ID,10,NULL);

break;
case WM_PAINT:
char szBuffer [50] ;
            sprintf (szBuffer, "%i", i) ;//格式化字符串,这是个C运行库中的函数,要包含stdio.h
            
hdc = BeginPaint(hWnd ,&ps);

RECT rect;

rect.left=0;
rect.top=0;
rect.right=100;
rect.bottom=100;

DrawText(hdc,szBuffer,sizeof(szBuffer),&rect,DT_LEFT);//显示所画的点数,却出现乱码???????????????????????????????????????????
//TextOut (hdc, 0, 0,TEXT(szBuffer), sizeof(szBuffer)) ;//也可以调用这个函数显示 HPEN hpen;
hpen = CreatePen(PS_DOT,3,RGB(255,166,0));
SelectObject(hdc,hpen);

MoveToEx(hdc,prevpt.x,prevpt.y,NULL);
//SetPixel (hdc, point.x, point.y, RGB(255,255,0) );
        LineTo(hdc,point.x,point.y);
            
EndPaint(hWnd,&ps);
break;
case WM_TIMER:
            hdc = GetDC(hWnd);
    GetClientRect(hWnd,&rt);
prevpt.x = point.x;
prevpt.y = point.y;//存储前一点
i++;

    point.x = i * cxClient / NUM ;
point.y = (int) (cyClient / 2 * (1 - sin (10*TWOPI * i / NUM))) ;//前面的数字10可以
                                              //调节周期


//InvalidateRect(hWnd, &rt,TRUE);//如果最后一个参数是TRUE的话,则擦除以前
                          //画的曲线!!这时只能看到一个小点儿在做正弦运动
            InvalidateRect(hWnd, &rt,FALSE);
ReleaseDC(hWnd, hdc);
break;

case WM_DESTROY:
KillTimer(hWnd,TIMER_ID);

PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
    return FALSE;
}/*
VOID CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
}
*/