设为首页 加入收藏

TOP

TEST TC CURSOR鼠标操作(TC)
2015-01-22 20:56:53 来源: 作者: 【 】 浏览:13
Tags:TEST CURSOR 鼠标 操作
代码中用到的鼠标操作的代码就是用 常用寄存器_AX,_BX,_CX,_DX 来控制的
很想用TC多线程来解决这个问题,但是在网上没有找到具体的实现方法,难道只有C++中或MS VC中有提供多线程的方法吗?让人懊恼不已啊

int main()
{
    char szText[20] = "";
    for(;;)
    {
        if(LeftPress())
        {
            MouseGetXY();
            if(MouseX < 0 || MouseX > 800 || MouseY < 0 || MouseY > 600)
                printf("Cursor is not in the Active Area of the screen!\n");
            else
            {
                printf("LeftButton Pressed!\n");
                sprintf(szText, "cursorX,Y:(%d, %d)\n", MouseX, MouseY);
                printf(szText);
            }
            //sleep(1);
        }
        if(RightPress())
        {
            MouseGetXY();
            if(MouseX < 0 || MouseX > 400 || MouseY < 0 || MouseY > 300)
                printf("Cursor is not in the Active Area of the screen!\n");
            else
            {
                printf("RightButton Pressed!\n");
                sprintf(szText, "CursorX,Y:(%d, %d)\n", MouseX, MouseY);
                printf(szText);
                /*moveto(120,240);*/
                textcolor(5);
                cprintf("/*RButton Test*/");
                printf("\n");
            }
            //sleep(1);
        }
        if(kbhit())
        {
            if(0x011b == bioskey(0))
            {
                printf("\ntestEnd\n");
                break;
            }
        }
        if(!LeftPress() && !RightPress())
            continue;
        printf("test again:\n");
    }
    getch();
}


问题:这段代码在执行左键按下 或 右键按下时,执行打印语句会打印多次

解决办法:在其对应的所有语句都执行完毕之后,加一个sleep(1);便可解决。

原因:这个问题应该属于是多线程轮询所造成的混乱的问题;
????????????????textcolor(6);
????????????????textbackground(7);
????????????????cprintf("Left and Right button both Pressed!\n");
这三句话的执行效率太低
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c语言--直接插入算法 下一篇C语言指针教程----入门到精通(二)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: