昨天和两个同学一起玩魔兽3C的时候,由于很长时间我都是躲在练功房里砍木头人升级,而这种体力活不需要我监视英雄的举动,所以我就不断地切出游戏去上网,这种行为弄得两个哥们十分郁闷。呵呵,谁让我是主机呢,于是就不断地出现掉线的情况。

过后我就在想,那么如何在游戏中限制用户这种动作呢,使得他无法利用 WIN功能键不断地切进切出。

      下面就是我给出的一个解决方案,原理是:利用一个底层的键盘钩子函数对待处理的键盘消息进行过滤。这个钩子即使在用户对窗口最小化或切换到另一个应用程序也是有效的。

Disabling Shortcut Keys in Full Screen mode// demo0.cpp : Defines the entry point for the application.
Disabling Shortcut Keys in Full Screen mode
//******************************
Disabling Shortcut Keys in Full Screen mode
//Author:phinecos
Disabling Shortcut Keys in Full Screen mode
//Date:2008-4-17
Disabling Shortcut Keys in Full Screen mode
//*******************************
Disabling Shortcut Keys in Full Screen mode

Disabling Shortcut Keys in Full Screen mode#include 
"stdafx.h"
Disabling Shortcut Keys in Full Screen mode#include 
"demo0.h"
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen mode
#define MAX_LOADSTRING 100
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen mode
// Global Variables:
Disabling Shortcut Keys in Full Screen mode
HINSTANCE hInst;                                // current instance
Disabling Shortcut Keys in Full Screen mode
HWND hWnd = NULL; //窗口句柄
Disabling Shortcut Keys in Full Screen mode
HHOOK g_hKeyboardHook;
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen modeTCHAR szTitle[MAX_LOADSTRING];                    
// The title bar text
Disabling Shortcut Keys in Full Screen mode
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
Disabling Shortcut Keys in Full Screen mode
BOOL isFullScreen = TRUE;//是否全屏
Disabling Shortcut Keys in Full Screen mode
BOOL isActive=TRUE;        // Window Active Flag Set To TRUE By Default
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen mode
// Forward declarations of functions included in this code module:
Disabling Shortcut Keys in Full Screen mode
ATOM                MyRegisterClass(HINSTANCE hInstance);
Disabling Shortcut Keys in Full Screen modeBOOL                InitInstance(HINSTANCE, 
int);
Disabling Shortcut Keys in Full Screen modeLRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen mode
Disabling Shortcut Keys in Full Screen modeLRESULT CALLBACK LowLevelKeyboardProc( 
int nCode, WPARAM wParam, LPARAM lParam )


参考资料:

1,  Disabling Shortcut Keys in Games

2,  Nehe OpenGL tutorial

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-09
  • 2021-11-10
  • 2021-12-17
  • 2021-11-11
  • 2022-01-02
  • 2021-06-07
  • 2021-10-19
相关资源
相似解决方案