为什么会出现这种错误???
编绎能够正常通过,但却无法创建.exe文件。。。。。
提示说:
--------------------Configuration: keyboard - Win32 Debug-----------------
Linking...
LINK : fatal error LNK1168: cannot open Debug/keyboard.exe for writing
Error executing link.exe.
keyboard.exe - 1 error(s), 0 warning(s)
源码如下:
#include"windows.h"
#include"stdlib.h"
#include"string.h"
long WINAPI WndProc
( HWND hWnd,
UINT iMessage,
UINT wParam,
LONG lParam
);
void WINAPI CaretPos(HWND hWnd,int nArrayPos,char *cCharBuf,int *xCaret,int *yCaret,int nCharWidth);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow);
HWND hWndMain;
int WINAPI WinMain
(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG Message;
if(! InitWindowsClass(hInstance))
return FALSE;
if( ! InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))
{TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc
(HWND hWnd,
UINT iMessage,
UINT wParam,
LONG lParam)
{
#define BufSize 30
static char cCharBuf[BufSize];
static int nNumChar=0;
static int nArrayPos=0;
static int nLnHeight;
static int nCharWidth;
static int xCaret, yCaret;
int x;
HDC hDC;
TEXTMETRIC tm;
PAINTSTRUCT PtStr;
switch(iMessage)
{
case WM_CHAR:
{ if(wParam==VK_BACK)
{ if(nArrayPos==0)
MessageBox(hWnd, "当前位置是文本的起始位置,不有回退",NULL,MB_OK);
else
{
nArrayPos=nArrayPos-1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
for(x=nArrayPos;x<nNumChar;x=x+1)
cCharBuf[x]=cCharBuf[x+1];
nNumChar=nNumChar-1;
InvalidateRect(hWnd,NULL,TRUE);
}
break;
}
if(wParam==VK_ESCAPE)
{
MessageBox(hWnd,"您现在不能按ESC键,请继续其他操作",NULL,MB_OK);
break;
}
if(nNumChar>=BufSize)
{
MessageBox(hWnd, "缓冲区已满,不能再输入字符了\n若需要删除字符,请用BackSpace键",NULL,MB_OK);
break;
}
for(x=nNumChar;x>nArrayPos;x=x-1)
cCharBuf[x]=cCharBuf[x-1];
cCharBuf[nArrayPos]=(unsigned char)wParam;
nArrayPos=nArrayPos+1;
nNumChar=nNumChar+1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case WM_CREATE:
hDC=GetDC(hWnd);
GetTextMetrics(hDC,&tm);
nLnHeight=tm.tmHeight+tm.tmExternalLeading;
nCharWidth=tm.tmAveCharWidth;
yCaret=nLnHeight;
ReleaseDC(hWnd,hDC);
break;
case WM_SETFOCUS:
CreateCaret(hWnd,0,0,nLnHeight);
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
ShowCaret(hWnd);
break;
case WM_KILLFOCUS:
DestroyCaret();
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_END:
nArrayPos=nNumChar;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
break;
case VK_HOME:
nArrayPos=0;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
break;
case VK_DELETE:
if(nArrayPos==nNumChar)
MessageBox(hWnd,"缓冲区已空,没有字符可供删除",NULL,MB_OK);
else
{for(x=nArrayPos;x<nNumChar;x=x+1)
cCharBuf[x]=cCharBuf[x+1];
nNumChar=nNumChar-1;
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case VK_LEFT:
if(nArrayPos>0)
{
nArrayPos=nArrayPos-1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
}
else
MessageBox(hWnd,"您已经移动到起始位置,不能再住前了",NULL,MB_OK);
break;
case VK_RIGHT:
if(nArrayPos<nNumChar)
{
nArrayPos=nArrayPos+1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
}
else
MessageBox(hWnd,"已经到缓冲区末,不能再向右移动了 ",NULL,MB_OK);
break;
}
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&PtStr);
TextOut(hDC,nCharWidth,nLnHeight,cCharBuf,nNumChar);
EndPaint(hWnd,&PtStr);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
}
void WINAPI CaretPos(HWND hWnd, int nArrayPos, char *cCharBuf,int *xCaret,int *yCaret,int nCharWidth)
{
DWORD dWord;
HDC hDC;
hDC=GetDC(hWnd);
ReleaseDC(hWnd,hDC);
*xCaret=LOWORD(dWord)+nCharWidth;
SetCaretPos(*xCaret,*yCaret);
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="WinKeyboard";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinKeyboard",
" 键盘操作例程",
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;
}