| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 803 人关注过本帖
标题:[求助]如何禁止OnLButtonDown的鼠标输入
只看楼主 加入收藏
andyzhshg
Rank: 2
等 级:论坛游民
帖 子:111
专家分:20
注 册:2007-9-1
收藏
 问题点数:0 回复次数:6 
[求助]如何禁止OnLButtonDown的鼠标输入
在做一个人机博弈的小程序,人的输入使用鼠标,想通过调用CXXXView::OnLButtonDown(UINT nFlags, CPoint point)来实现电脑走棋的输入,但是我如何在电脑走棋的过程中禁止人的鼠标输入呢?

大致的调用过程如下:

void CXXXView::OnPaint()
{
    ......
    NextStep();
}
void CXXXView::OnLButtonDown(UINT nFlags, CPoint point)
{

    DoSomeThing(point);
    ......

}
void CXXXView::NextStep()
{
    if(man_move)
        return;
    else if(computer_move)
    {
        CPoint point = xxx;
        OnLButtonDown(NULL,point);
    }
}
搜索更多相关主题的帖子: 鼠标 输入 
2008-06-01 16:37
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
用临界区好了...

学习需要安静。。海盗要重新来过。。
2008-06-01 16:38
andyzhshg
Rank: 2
等 级:论坛游民
帖 子:111
专家分:20
注 册:2007-9-1
收藏
得分:0 
说详细点好么?我不懂临界区阿

编程并快乐着
2008-06-01 16:53
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
HANDLE hMutex;


h = CreateMutex
      (
      NULL,                             // no security attributes
      FALSE,                            // initially not owned
      "MutexToProtectDatabase");        // name of mutex

if (hMutex == NULL)
{
                                        // Check for error.
}

When a thread of this process writes to the database, it first requests ownership of the mutex. If it gets ownership, the thread writes to the database and then releases its ownership.

The example uses the try-finally structured exception-handling syntax to ensure that the thread properly releases the mutex object. To prevent the mutex object from being abandoned inadvertently, the finally block of code is executed no matter how the try block terminates — unless the try block includes a call to the TerminateThread function.

BOOL FunctionToWriteToDatabase(HANDLE hMutex)
{
      DWORD dwWaitResult;

 
      dwWaitResult = WaitForSingleObject(
         hMutex,        // handle of mutex
         5000L);        // five-second time-out interval
 
      switch (dwWaitResult)
      {
         case WAIT_OBJECT_0:
            try
            {
                        // Write to the database.
            }

            finally
            {
               if (! ReleaseMutex(hMutex))
               {
                        // Deal with error.
               }

            break;
            }

                        // Cannot get mutex ownership due to time-out.
        case WAIT_TIMEOUT:
            return FALSE;

                        // Got ownership of the abandoned mutex object.
        case WAIT_ABANDONED:
            return FALSE;
      }

      return TRUE;
}
 
上面是一个数据库同步的例子,当一个线程获得Mutex时另一个必须等待。。应该可以满足你的要求

学习需要安静。。海盗要重新来过。。
2008-06-01 20:24
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
收藏
得分:0 
哎呀,sun兄真是想的太复杂了,
我认为只要定义一个全局变量bool bCanClick
即可。

判断bCanClick 的代码你可以放在OnLButtonDown里,
如果
bCanClick == true就说明可以点鼠标;
==false就不可以点鼠标

就这么简单

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2008-06-01 20:59
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
我以为他是在做多线程的。。如果是用多线程的话还是用临界区稍微好点。。当然做一个标记变量模拟也可以的

学习需要安静。。海盗要重新来过。。
2008-06-01 21:42
Loli
Rank: 1
来 自:飞燕算法群46520219
等 级:新手上路
帖 子:348
专家分:0
注 册:2008-5-27
收藏
得分:0 
楼主自己的设计方法显然有问题,那个函数不是给你自己调用的

" border="0" />[color=white]
2008-06-02 09:20
快速回复:[求助]如何禁止OnLButtonDown的鼠标输入
数据加载中...
 
   



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

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