mfc小问题

这篇博客探讨了一个MFC应用中遇到的问题,即在窗口中显示汉字时出现异常。作者提供了包含WM_PAINT消息处理和光标改变的代码,并询问为何输出的汉字不正确。文章涉及WinAPI和MFC的窗口类初始化以及窗口过程处理。
摘要由CSDN通过智能技术生成

代码如下:

#include"windows.h"
#include"string"
#include"tchar.h"
void WINAPI CaretPos(HWND hWnd,int nArrayPos,char *cCharBuf,int*xCaret,int*yCaret,int nCharWidth );
long WINAPI WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain;
static wchar_t lpszclassname[]=_T("shegan");
static wchar_t lpszTitle[]=_T("s");
char line1[]="这是第行";
static wchar_t line2[]=_T("这是第二行");
HDC Hdc;
TEXTMETRIC tm;
HWND hWnd;
PAINTSTRUCT pt;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
 MSG msg;
 if(!InitWindowsClass(hInstance))
  return FALSE;
 if(!InitWindows(hInstance,nCmdShow))
  return FALSE;
 while(GetMessage(&msg,0,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return msg.wParam;


}
long WINAPI WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
WORD x,y;
HCURSOR hCursor;
switch(message)
  {
case WM_PAINT:
     Hdc=BeginPaint(hWnd,&pt);
     SetTextColor(Hdc,RGB(255,0,0));
  TextOut(Hdc,60,10,(LPCWSTR)line1,strlen(line1));
     //GetTextMetrics(Hdc,&tm);
    //SetTextColor(Hdc,RGB(0,0,255));

case WM_MOUSEMOVE:
 x=LOWORD(lParam);//取低4位
 y=HIWORD(lParam);//取高4位
   if(x>=50&&x<=400&&y>=50&&y<=300)
   {
    if(x>=50&&x<=100&&y>=50&&y<=100)
     {
      hCursor=LoadCursor(NULL,IDC_CROSS);
   SetCursor(hCursor);
     }
    if(x>=100&&x<=150&&y>=50&&y<=100)
    {
    hCursor=LoadCursor(NULL,IDC_SIZE);
    SetCursor(hCursor);
    }
    if(x>=150&&x<=200&&y>=50&&y<=100)
    {
    hCursor=LoadCursor(NULL,IDC_SIZE);
    SetCursor(hCursor);
    }
       if(x>=50&&x<=100&&y>=100&&y<=150)
    {
    hCursor=LoadCursor(NULL,IDC_SIZENESW);
    SetCursor(hCursor);
   
    }
    if(x>=250&&x<=400&&y>=100&&y<=150)
    {
    hCursor=LoadCursor(NULL,IDC_SIZENWSE);
    SetCursor(hCursor);
    }
    if(x>=50&&x<=100&&y>=150&&y<300)
    {
    hCursor=LoadCursor(NULL,IDC_SIZEWE);
    SetCursor(hCursor);
    }
    if(x>=100&&x<=250&&y>=150&&y<=300)
    {
    hCursor=LoadCursor(NULL,IDC_UPARROW);
    SetCursor(hCursor);
    }
    if(x>=250&&x<=400&&y>=150&&y<=300)
    {
    hCursor=LoadCursor(NULL,IDC_WAIT);
    SetCursor(hCursor);
    }

   }
    else
          {
            hCursor=LoadCursor(NULL,IDC_ARROW);
   SetCursor(hCursor);//该函数确定光标的形状


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

    }
}
 
  BOOL InitWindowsClass(HINSTANCE hInstance)
 {
 WNDCLASS wndclass;
 wndclass.cbClsExtra=0;
 wndclass.cbWndExtra=0;
 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 wndclass.hCursor=LoadCursor(NULL,IDC_UPARROW);
 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);//END什么意思

 wndclass.hInstance=hInstance;
 wndclass.lpfnWndProc=WndProc; 
 wndclass.lpszClassName=lpszclassname;
 wndclass.lpszMenuName=NULL;
 wndclass.style=CS_HREDRAW|CS_VREDRAW;//
 return RegisterClass(&wndclass);
 
 }

  BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
  {
 hWnd=CreateWindow(
                lpszclassname,
       lpszTitle,
       WS_OVERLAPPEDWINDOW,
       CW_USEDEFAULT,
       0,
       CW_USEDEFAULT,
       0,
       NULL,
       NULL,
       hInstance,
       NULL
                  );
  if(!hWnd)
   return FALSE;
 hWndMain=hWnd;
 ShowWindow(hWnd,nCmdShow);
 UpdateWindow(hWnd);
 return TRUE;
  }

请问:为什么输出是的汉子不正确?

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值