注册 登录
编程论坛 VC++/MFC

win32编程中的问题

Sakerjin 发布于 2015-09-15 23:18, 2123 次点击
/*
       程序实现的是输入字符并且在窗口显示出来,按下backspace键的时候消去一个
*/
下面是主要代码
i,还有szBuffer设置为全局变量
case WM_CHAR:
            
              switch(wParam)
              {
                  case '\b':
                         i--;
                         if(i<=0)
                         i=0;
                        szBuffer[i]=' ';
                       break;
             default:                     
                        szBuffer[i]=wParam;
                        i++;
                        szBuffer[i]=0;
              }
                 break;
           case  WM_PAINT:
                 GetClientRect(hwnd,&rect);
                 hdc=BeginPaint(hwnd,&ps);
                 DrawText(hdc,szBuffer,-1,&rect,DT_LEFT);
                InvalidateRect(hwnd,&rect,false);//这一句如果不加上的话字符为什么不显示,加上之后就会闪烁,问一下有没有其他方案
                 EndPaint(hwnd,&ps);
                 return 0;
3 回复
#2
yangfrancis2015-09-16 09:10
把带注释那句放到WM_CHAR里面去试试
#3
Sakerjin2015-09-19 23:02
回复 2楼 yangfrancis
这个无法输入了就,你可以试试,
我已经解决了,谢谢你了
WM_CHAR:
   ......
   hdc=GetDC();
   GetClientRect();
   DrawText();
   ReleaseDC();   
我用了这几个实现了效果,不过输入汉字,删除的时候会因为编码出现问题,所以这个还是需要解决的
多谢你了
#4
农民工2015-09-30 16:56
case WM_CHAR:
            
              switch(wParam)
              {
                  case '\b':
                         i--;
                         if(i<=0)
                         i=0;
                        szBuffer[i]=' ';
                       break;
             default:                     
                        szBuffer[i]=wParam;
                        i++;
                        szBuffer[i]=0;
              }
            {
                GetClientRect(hwnd,&rect);
                InvalidateRect(hwnd,&rect,false);
            }
                 break;
           case  WM_PAINT:
                 GetClientRect(hwnd,&rect);
                 hdc=BeginPaint(hwnd,&ps);
                 DrawText(hdc,szBuffer,-1,&rect,DT_LEFT);

                 EndPaint(hwnd,&ps);
                 return 0;
1