| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 362 人关注过本帖
标题:请问一下为什么我这段程序,在我按下键盘后没有输出的
只看楼主 加入收藏
lgybecks
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-1-16
收藏
 问题点数:0 回复次数:0 
请问一下为什么我这段程序,在我按下键盘后没有输出的
#include<windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
    WNDCLASS wndclass;
    HWND hwnd;
    MSG msg;
    static TCHAR tName[]=TEXT("Title");

    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.hCursor=LoadCursor(hInstance,IDC_ARROW);
    wndclass.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
    wndclass.hInstance=hInstance;
    wndclass.lpfnWndProc=WndProc;
    wndclass.lpszClassName=tName;
    wndclass.lpszMenuName=NULL;
    wndclass.style=CS_HREDRAW|CS_VREDRAW;

    if(!RegisterClass(&wndclass))
    {
        MessageBox(NULL,NULL,tName,MB_YESNO);
        return 0;
    }

    hwnd=CreateWindow(tName,TEXT("WindowName"),
                            WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
                            CW_USEDEFAULT,CW_USEDEFAULT,
                            NULL,NULL,hInstance,NULL);
   
    ShowWindow(hwnd,nShowCmd);
    UpdateWindow(hwnd);

    while(GetMessage(&msg,hwnd,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
   
    return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT nmsg,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;

    static TCHAR Shift[]=TEXT("You've hitted the shift key");
    static TCHAR Ctrl[]=TEXT("You've hitted the ctrl key");
    static TCHAR Up[]=TEXT("You've hitted the up key");
    static TCHAR ShiftB[]=TEXT("You've hitted the shift and B");
    static TCHAR CtrlA[]=TEXT("You've hitted the ctrl and A");

    bool fUp=false;
    bool fCtrl=false;
    bool fShift=false;
    bool fCtrlA=false;
    bool fShiftB=false;

    switch(nmsg)
    {
    case WM_KEYDOWN:
        {
            switch(wParam)
                case VK_UP:
                    fUp=true;
                    break;
                case VK_CONTROL:
                    fCtrl=true;
                    break;
                case VK_SHIFT:
                    fShift=true;
                    break;
                default:
                    break;
        }
        break;
    case WM_KEYUP:
        InvalidateRect(hwnd,NULL,true);
        break;
    case WM_CHAR:
        if(wParam==97||wParam==65)
        {
            if(fCtrl)
            {
                fCtrlA=true;
                fCtrl=false;
            }
        }
        else
        {
            if(wParam==98||wParam==66)
            {
                if(fShift)
                {
                    fShiftB=true;
                    fShift=false;
                }
            }
        }
        break;
    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        SetTextColor(hdc,RGB(255,0,0));
        if(fShift)
        {
            TextOut(hdc,1,1,Shift,lstrlen(Shift));
        }
        else
            if(fUp)
            {
                TextOut(hdc,1,1,Up,lstrlen(Up));
            }
            else
                if(fCtrl)
                {
                    TextOut(hdc,1,1,Ctrl,lstrlen(Ctrl));
                }
                else
                    if(fCtrlA)
                    {
                        TextOut(hdc,1,1,CtrlA,lstrlen(CtrlA));
                    }
                    else
                        if(fShiftB)
                        {
                            TextOut(hdc,1,1,ShiftB,lstrlen(ShiftB));
                        }
        EndPaint(hwnd,&ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hwnd,nmsg,wParam,lParam);
}

搜索更多相关主题的帖子: 键盘 include 
2011-01-16 22:14
快速回复:请问一下为什么我这段程序,在我按下键盘后没有输出的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016151 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved