HotKey Control For Windows Mobile

Windows CE 3.0 及以后版本均可用!

此控件显示一文本框用户于捕获用户按键,常用于程序的设置功能(设置HotKey)。

可捕获除关机键外的任何按键。

用法:
CMS_HotKeyEdit::RegisterClass(hInstance); //注册窗口类,之后就可以用CreateWindow创建控件了。

#define  MSHKM_GETKEY WM_USER+101     // 获取字符
#define  MSHKM_SETKEY WM_USER+102     // 设置字符 wParam为字符

/*
 * HotKey Control
 * 2009.04.20 By Frank
 * Mood Sunshiny Workroom
 * Http://Www.MoodSun.Cn/
 *
 * Default Style(For Custom Control): 0x50810080
 * ClassName: MS_HotKeyEdit
*/
static   class  CMS_HotKeyEdit
{
private :
    
static  WNDPROC m_OldWinProc;  // 原窗口处理过程

    
static  LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

public :
    
static  BOOL RegisterClass(HINSTANCE hInstance);
};

 

#include  " StdAfx.h "
#include 
" MS_HotKeyEdit.h "
#include 
< gx.h >
#pragma  comment(lib,"gx.lib")

WNDPROC CMS_HotKeyEdit::m_OldWinProc
= NULL;

LRESULT CALLBACK CMS_HotKeyEdit::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    
switch (uMsg)
    {
    
case  WM_CREATE:
        {
            
/* 设置只读 */
            LONG lOldLong
= GetWindowLong(hwnd,GWL_STYLE);
            
if ((lOldLong & ES_READONLY) != ES_READONLY)SetWindowLong(hwnd,GWL_STYLE,lOldLong | ES_READONLY);
            
break ;
        }
    
case  WM_SETFOCUS:
        GXOpenInput(); 
// 接管硬件按键
         break ;

    
case  WM_KILLFOCUS:
        GXCloseInput();
        
break ;

    
case  WM_KEYUP:
        {
            
// 通知父窗口内容变化
            HWND hParent = NULL;
            
if ( ! (hParent = GetParent(hwnd)))
            {
                
throw  TEXT( " 此控件必须做为子控件! " );
            }
            NMHDR nmd
= {hwnd,GetDlgCtrlID(hwnd),(DWORD)wParam};
            LRESULT lRS
= SendMessage(hParent,WM_NOTIFY,nmd.idFrom,(LPARAM) & nmd);

            
// 给父窗口一个机会决定是否允许此HotKey
             if (lRS == S_OK)
            {
                
// 设置新值到文本
                TCHAR tcTxt[ 2 ] = { 0 , 0 };
                tcTxt[
0 ] = (TCHAR)wParam;
                SetWindowText(hwnd,tcTxt);
            }
            
break ;
        }

    
case  MSHKM_GETKEY:
        {
            TCHAR tcTxt[
2 ] = { 0 , 0 };
            GetWindowText(hwnd,tcTxt,
2 );
            
return  (LRESULT)(tcTxt[ 0 ] == TEXT( ' ' ) ? 0 :tcTxt[ 0 ]);
        }
    
case  MSHKM_SETKEY:
        {
            TCHAR tcTxt[
2 ] = { 0 , 0 };
            tcTxt[
0 ] = wParam == 0 ? TEXT( ' ' ):(TCHAR)wParam;
            SetWindowText(hwnd,tcTxt);
            
return  S_OK;
        }
    }
    
    
return  CallWindowProc(m_OldWinProc,hwnd,uMsg,wParam,lParam);
}

BOOL CMS_HotKeyEdit::RegisterClass(HINSTANCE hInstance)
{
    WNDCLASS wc;
    
if ( ! GetClassInfo(hInstance,TEXT( " EDIT " ), & wc)) return  FALSE;

    m_OldWinProc
= wc.lpfnWndProc;
    wc.hInstance
= hInstance;
    wc.lpszClassName 
=  TEXT( " MS_HotKeyEdit " );
    wc.lpfnWndProc 
=  WindowProc;

    
//  注册自定义类
     return  (::RegisterClass( & wc)  !=   0 );
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值