[求助]如何禁止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);
}
}
----------------解决方案--------------------------------------------------------
用临界区好了...
----------------解决方案--------------------------------------------------------
说详细点好么?我不懂临界区阿
----------------解决方案--------------------------------------------------------
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时另一个必须等待。。应该可以满足你的要求
----------------解决方案--------------------------------------------------------
哎呀,sun兄真是想的太复杂了,
我认为只要定义一个全局变量bool bCanClick
即可。
判断bCanClick 的代码你可以放在OnLButtonDown里,
如果
bCanClick == true就说明可以点鼠标;
==false就不可以点鼠标
就这么简单
----------------解决方案--------------------------------------------------------
我以为他是在做多线程的。。如果是用多线程的话还是用临界区稍微好点。。当然做一个标记变量模拟也可以的
----------------解决方案--------------------------------------------------------
楼主自己的设计方法显然有问题,那个函数不是给你自己调用的
[color=white]
----------------解决方案--------------------------------------------------------