代码如下
# include <windows.h>
# include <stdlib.h>
# include <string.h>
char str1[]="you have input up key";
char str3[]="you have input control key";
char str4[]="you have input shift key";
char str5[]="you have input cotrol a key";
char str6[]="you have input shift b key";
bool nUpKeyDown,nCtrlKeyDown,nShiftKeyDown,nCtrlAkeyDown,nShiftBKeyDwon;
LRESULT CALLBACK Winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass1;
wndclass1.lpfnWndProc=Winsunproc;
wndclass1.style=0;
wndclass1.cbClsExtra=0;
wndclass1.cbWndExtra=0;
wndclass1.hInstance=hInstance;
wndclass1.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass1.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass1.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass1.lpszMenuName="大爷";
wndclass1.lpszClassName="杂碎";
if(!RegisterClass(&wndclass1))
{
MessageBeep(0); return FALSE;
}
hwnd=CreateWindow("杂碎","大爷",WS_OVERLAPPEDWINDOW,0,0,600,400, NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}LRESULT CALLBACK Winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
bool nUpKeyDown,nCtrlkeyDown,nShiftKeyDown,nCtrlAkeyDown,nShiftBKeyDwon;
HDC hdc;
PAINTSTRUCT ps;
HPEN hpen;
HBRUSH hbrush;
switch(uMsg)
{
case WM_KEYDOWN:
{switch(wParam)
{
case VK_UP:
nUpKeyDown=true;
break;
case VK_CONTROL:
nCtrlKeyDown=true;
break;
case VK_SHIFT:
nShiftKeyDown=true;
break;
default:
break;
}
}
case WM_KEYUP:
InvalidateRect(hwnd,NULL,FALSE);
case WM_CHAR:
if(wParam=(65&VK_CONTROL))
{
if(nCtrlkeyDown=true)
{nCtrlAKeyDown=true;
nCtrlkeyDown=false;
nCtrlAKeydOWN=false;}}
if(wParam=98 | wParam=66)
{ if(nShiftKeyDown=true)
nShiftBKeyDwon=true;
nShiftKeyDown=false;
break;
}
case WM_PAINT;
{
hdc=BeginPaint(hwnd,&ps);
hpen=(HPEN)GetStockObject(WHITE_PEN);
hbrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hpen);
SelectObject(hdc,hbrush);
SetTextColor(hdc,RGB(255,0,255));
if(nUpKeyDown==true)
{Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str1,strlen(str1));
nUpKeyDown=false;
if(nCtrlKeyDown==true&&nCtrlAkeyDown=false)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str3,strlen(str3));
nCtelKeyDown=false;
nCtrlAkeyDown=false;
}
if(nShiftKeyDown==true&&nShiftBKeyDwon=false)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str4,strlen(str4));
nShiftKeyDown=false;
nShiftBKeyDwon=false;
}
if(nCtrlAkeyDown==true)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str5,strlen(str5));
nCtrlAkeyDown=true;
}
if(nShiftBKeyDwon==true)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str6,strlen(str6));
nShiftBKeyDwon=false;
}
DeleteObject(hbrush);
DeleteObject(hpen);
EndPaint(hwnd,&ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hwnd,uMsg,wParam,lParam));
}
return 0;
}
: error C2065: 'nCtrlAKeyDown' : undeclared identifier
: error C2065: 'nCtrlAKeydOWN' : undeclared identifier
: error C2106: '=' : left operand must be l-value
: error C2143: syntax error : missing ':' before ';'
: error C2106: '=' : left operand must be l-value
: error C2065: 'nCtelKeyDown' : undeclared identifier
D: error C2106: '=' : left operand must be l-value
: fatal error C1004: unexpected end of file found
# include <windows.h>
# include <stdlib.h>
# include <string.h>
char str1[]="you have input up key";
char str3[]="you have input control key";
char str4[]="you have input shift key";
char str5[]="you have input cotrol a key";
char str6[]="you have input shift b key";
bool nUpKeyDown,nCtrlKeyDown,nShiftKeyDown,nCtrlAkeyDown,nShiftBKeyDwon;
LRESULT CALLBACK Winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass1;
wndclass1.lpfnWndProc=Winsunproc;
wndclass1.style=0;
wndclass1.cbClsExtra=0;
wndclass1.cbWndExtra=0;
wndclass1.hInstance=hInstance;
wndclass1.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass1.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass1.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass1.lpszMenuName="大爷";
wndclass1.lpszClassName="杂碎";
if(!RegisterClass(&wndclass1))
{
MessageBeep(0); return FALSE;
}
hwnd=CreateWindow("杂碎","大爷",WS_OVERLAPPEDWINDOW,0,0,600,400, NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}LRESULT CALLBACK Winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
bool nUpKeyDown,nCtrlkeyDown,nShiftKeyDown,nCtrlAkeyDown,nShiftBKeyDwon;
HDC hdc;
PAINTSTRUCT ps;
HPEN hpen;
HBRUSH hbrush;
switch(uMsg)
{
case WM_KEYDOWN:
{switch(wParam)
{
case VK_UP:
nUpKeyDown=true;
break;
case VK_CONTROL:
nCtrlKeyDown=true;
break;
case VK_SHIFT:
nShiftKeyDown=true;
break;
default:
break;
}
}
case WM_KEYUP:
InvalidateRect(hwnd,NULL,FALSE);
case WM_CHAR:
if(wParam=(65&VK_CONTROL))
{
if(nCtrlkeyDown=true)
{nCtrlAKeyDown=true;
nCtrlkeyDown=false;
nCtrlAKeydOWN=false;}}
if(wParam=98 | wParam=66)
{ if(nShiftKeyDown=true)
nShiftBKeyDwon=true;
nShiftKeyDown=false;
break;
}
case WM_PAINT;
{
hdc=BeginPaint(hwnd,&ps);
hpen=(HPEN)GetStockObject(WHITE_PEN);
hbrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(hdc,hpen);
SelectObject(hdc,hbrush);
SetTextColor(hdc,RGB(255,0,255));
if(nUpKeyDown==true)
{Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str1,strlen(str1));
nUpKeyDown=false;
if(nCtrlKeyDown==true&&nCtrlAkeyDown=false)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str3,strlen(str3));
nCtelKeyDown=false;
nCtrlAkeyDown=false;
}
if(nShiftKeyDown==true&&nShiftBKeyDwon=false)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str4,strlen(str4));
nShiftKeyDown=false;
nShiftBKeyDwon=false;
}
if(nCtrlAkeyDown==true)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str5,strlen(str5));
nCtrlAkeyDown=true;
}
if(nShiftBKeyDwon==true)
{
Rectangle(hdc,0,0,600,400);
TextOut(hdc,0,0,str6,strlen(str6));
nShiftBKeyDwon=false;
}
DeleteObject(hbrush);
DeleteObject(hpen);
EndPaint(hwnd,&ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hwnd,uMsg,wParam,lParam));
}
return 0;
}
: error C2065: 'nCtrlAKeyDown' : undeclared identifier
: error C2065: 'nCtrlAKeydOWN' : undeclared identifier
: error C2106: '=' : left operand must be l-value
: error C2143: syntax error : missing ':' before ';'
: error C2106: '=' : left operand must be l-value
: error C2065: 'nCtelKeyDown' : undeclared identifier
D: error C2106: '=' : left operand must be l-value
: fatal error C1004: unexpected end of file found
解决方案 »
- 有没有人用MFC和ATL混合编写COM组件?
- 问一个透明窗口的问题
- 关于button显示位图的问题
- 自己写的继承于MFC的类什么时候应该要自己写DECLEAR_DYNAMEIC,DECLARE_DYNCREATE,DECLARE_SERIAL这些宏?
- 我定义了一个char *buffer="12,3,4,5,jOhn"怎样查找“,“,从字符串的末尾开始查?
- 单文档多视的工具栏ON_UPDATE_COMMAND_UI消息?
- 求救!!!!!!!!!!!!!!SOS
- 如何让一个基于对话框的程序启动后自动隐藏窗口?
- 请教编译问题
- 为什么没有人理我????
- 穿透NAT怎么写?VC++,只需要给服务器发信息(这个好实现),服务器需要向(内网IP)发信息
- 用ClassWizard生成类时出错
#include "stdafx.h" 加到第一行
{nCtrlAKeyDown=true;
nCtrlkeyDown=false;
nCtrlAKeydOWN=false;}
你这是乱写的。。nCtrlAKeydOWN=false
下面是你的错误,看看大小写
'nCtrlAKeyDown'
'nCtrlAKeydOWN'