按键响应只设置了一个,但是运行其他按键也能响应

static int n=10;
    switch(message)
    {
    case WM_CREATE:
        SetTimer(hwnd,9999,100,NULL);
        break;
    case WM_TIMER:
        if(wParam==9999)
            InvalidateRect(hwnd,NULL,0);
        break;
    case WM_SIZE:               //窗口尺寸发生变化时,应该刷新窗口
            InvalidateRect(hwnd,NULL,0);
    break;

    case WM_CHAR:/*按键设置*/
        if(wParam=='q')
        {
            i=1;
        }
        else if(wParam==VK_ESCAPE)
        {
            i=2;
        }
        else if(wParam=='3')
        {
            i=4;
        }
        /*战斗*/
        //向左
        else if(wParam='a')
        {
            n=021;
        }
        //向右
        else if(wParam='d')
        {
            n=011;
        }
        //攻击
        else if(wParam='j')
        {
             i=8;
        }

        InvalidateRect(hwnd,NULL,1);
        break;

    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        if(i==0)
        {

        hMemDC=CreateCompatibleDC(hdc);
        hBitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
        SelectObject(hMemDC,hBitmap);
        GetObject(hBitmap,sizeof(BITMAP),&bitmap);
        GetClientRect(hwnd,&rect);
        StretchBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,hMemDC,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
        }

        if(i==1)
        {
            hMemDC2=CreateCompatibleDC(hdc);    
            hBitmap2=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP2));            
            SelectObject(hMemDC2,hBitmap2);
            GetObject(hBitmap2,sizeof(BITMAP),&bitmap2);
            StretchBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,hMemDC2,0,0,bitmap2.bmWidth,bitmap2.bmHeight,SRCCOPY);
        }

        /*开始*/


        if(i==4)
        {
            hMemDC4=CreateCompatibleDC(hdc);    
            hBitmap4=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP4));            
            SelectObject(hMemDC4,hBitmap4);
            GetObject(hBitmap4,sizeof(BITMAP),&bitmap4);
            StretchBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,hMemDC4,0,0,bitmap4.bmWidth,bitmap4.bmHeight,SRCCOPY);

//第一个人

switch(n)
{
case 10:
hMemDC10=CreateCompatibleDC(hdc);

hBitmap10=LoadBitmap(hInst,MAKEINTRESOURCE(n));

SelectObject(hMemDC10,hBitmap10);
GetObject(hBitmap10,sizeof(BITMAP),&bitmap10);
TransparentBlt(hdc,p1.x,rect.top+(rect.top+rect.bottom)/4,bitmap10.bmWidth, bitmap10.bmHeight,hMemDC10,0,0,bitmap10.bmWidth, bitmap10.bmHeight, RGB(255,255,255));//绘图。白色透明
break;

            case 11:
            p1.x=p1.x+(rect.right+rect.left)/16;

/*右*/ hMemDC11=CreateCompatibleDC(hdc);

hBitmap11=LoadBitmap(hInst,MAKEINTRESOURCE(n));

SelectObject(hMemDC11,hBitmap11);
GetObject(hBitmap11,sizeof(BITMAP),&bitmap11);
TransparentBlt(hdc,p1.x,rect.top+(rect.top+rect.bottom)/4,bitmap11.bmWidth, bitmap11.bmHeight,hMemDC11,0,0,bitmap11.bmWidth, bitmap11.bmHeight, RGB(255,255,255));//绘图。白色透明
n=20;
break;
case 20:
hMemDC20=CreateCompatibleDC(hdc);

hBitmap20=LoadBitmap(hInst,MAKEINTRESOURCE(n));

SelectObject(hMemDC20,hBitmap20);
GetObject(hBitmap20,sizeof(BITMAP),&bitmap20);
TransparentBlt(hdc,p1.x,rect.top+(rect.top+rect.bottom)/4,bitmap20.bmWidth, bitmap20.bmHeight,hMemDC20,0,0,bitmap20.bmWidth, bitmap20.bmHeight, RGB(255,255,255));//绘图。白色透明
n=10;
break;

            case 21:
            p1.x=p1.x-(rect.right+rect.left)/16;

/*左*/ hMemDC21=CreateCompatibleDC(hdc);

hBitmap21=LoadBitmap(hInst,MAKEINTRESOURCE(n));

SelectObject(hMemDC21,hBitmap21);
GetObject(hBitmap21,sizeof(BITMAP),&bitmap21);
TransparentBlt(hdc,p1.x,rect.top+(rect.top+rect.bottom)/4,bitmap11.bmWidth, bitmap21.bmHeight,hMemDC21,0,0,bitmap21.bmWidth, bitmap21.bmHeight, RGB(255,255,255));//绘图。白色透明
n=22;
break;
case 22:
hMemDC22=CreateCompatibleDC(hdc);

hBitmap22=LoadBitmap(hInst,MAKEINTRESOURCE(n));

SelectObject(hMemDC22,hBitmap22);
GetObject(hBitmap22,sizeof(BITMAP),&bitmap22);
TransparentBlt(hdc,p1.x,rect.top+(rect.top+rect.bottom)/4,bitmap22.bmWidth, bitmap22.bmHeight,hMemDC22,0,0,bitmap22.bmWidth, bitmap22.bmHeight, RGB(255,255,255));//绘图。白色透明
n=10;
break;

            }
    以上是部分代码,当我按下“a” “d”后位图消失(我做的效果应该是左移,右移),即使不按“a”“d” 按其他键也会造成同样的情况。

你看看当窗口尺寸变化,被遮挡后位图会不会消失。如果按什么键都有问题那可能是InvalidateRect()刷新窗口造成的,看看WM_PAINT里面有没有什么错误。

在WM_PAINT 里面只有一个InvalidateRect()

 Sleep(1000);
            j=j-1;
        InvalidateRect(hwnd,NULL,1);

        EndPaint(hwnd,&ps);

建议单步跟踪一下,看一下执行的代码是不是自己设想的

怀疑有代码弄错位置

WM_CHAR里面有InvalidateRect(hwnd,NULL,1);
就是说无论你按什么按键都会刷新界面,不知道你所说的是不是这个问题。
如果是这样,你在最后一个if后面加上else{ return; }