如何为应用程序MFC创建虚拟键盘MFC? [英] How to create a virtual keyboard MFC for a application MFC?

查看:165
本文介绍了如何为应用程序MFC创建虚拟键盘MFC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

上一次,我曾经使用C#对嵌入在应用程序中的虚拟键盘进行编码,而这一次,我必须针对1个应用程序MFC使用MFC对V-keyboard进行编码.

我用C#编码VK时所做的工作:
1.创建一个窗体,使其在单击时不会获得焦点.(重写Form的WndProc函数并处理消息以防止其本身成为焦点)
2.创建一个继承自Button基础的按钮,并且单击该按钮时也不会获得焦点.
一个.使用"createParams.ExStyle = WS_EX_NOACTIVATE"覆盖CreateParams功能.
b.覆盖WndProc功能并处理WM_MOUSEACTIVATE消息.
3.单击按钮时设置事件sendkey.

这是虚拟键盘MFC的问题:
1.如何创建CDialog在MFC中单击时无法获得焦点?
2.如何创建与C#创建的按钮相同的新按钮(见上).

P/S:我在Google上搜索了很多天,但仍然找不到确切答案.
请帮帮我!!!

对不起,我的英语不好.很难解释清楚.
希望您能帮助我.

最好的问候.

Hi everybody,

The last time, I used to coded a virtual keyboard embeded in a applicaiotn by C#, and this time, i must coded V-keyboard by MFC for 1 application MFC.

The work i did when i code VK by C#:
1. Create a form don''t get focus when click on it.(override WndProc funtion of Form and process mesage to prevent focus in itself)
2. Create a button inherited Button base, and this button also don''t get focus when click on it.
a. Override CreateParams funtion with "createParams.ExStyle = WS_EX_NOACTIVATE".
b. Override WndProc funtion and process WM_MOUSEACTIVATE message.
3. Make event sendkey when click on button.

And this is questions for virtual keyboard MFC:
1. How to create a CDialog don''t get focus when click on it in MFC?
2. How to create a new button which the same with button i created by C# (above).

P/S: I searched on google for many days, but i still not find answer exactly.
Please help me!!!

I''m sorry,my english is not good. so difficult to explain more clearly.
Hope you try to help me.

Best regard.

推荐答案

我几乎可以正常工作了.我没有为按钮添加新类.只需执行以下操作即可:

创建对话框:
I almost got it to work. I didn''t add a new class for the button. Just do this:

To create the dialog box:
CNotFocusedDlg* dlg = new CNotFocusedDlg();
dlg->Create(IDD_NOT_FOCUSED);
dlg->ShowWindow(SW_SHOW);
//don''t forget to delete the pointer
//when you don''t need the dialog anymore



在对话框类中,使用以下代码添加WM_ACTIVATE和WM_MOUSEACTIVATE处理程序:

在.h中:



In your dialog class, add the WM_ACTIVATE and WM_MOUSEACTIVATE handlers with the following code:

In the .h:

class CNotFocusedDlg : public CDialog
{
	DECLARE_DYNAMIC(CNotFocusedDlg)
public:
	CNotFocusedDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CNotFocusedDlg();
// Dialog Data
	enum { IDD = IDD_NOT_FOCUSED };
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	DECLARE_MESSAGE_MAP()

	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
	afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
        afx_msg void OnBnClickedButton1();
};


然后在.cpp中:


Then in the .cpp:

BEGIN_MESSAGE_MAP(CNotFocusedDlg, CDialog)
    ON_WM_ACTIVATE()
    ON_WM_MOUSEACTIVATE()
    ON_BN_CLICKED(IDC_BUTTON1, &CNotFocusedDlg::OnBnClickedButton1)
END_MESSAGE_MAP()

void CNotFocusedDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
    if (nState == WA_ACTIVE || nState == WA_CLICKACTIVE)
    {
        if (pWndOther != NULL)
            pWndOther->SetActiveWindow();
    }

    CDialog::OnActivate(nState, pWndOther, bMinimized);
}

int CNotFocusedDlg::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
    return MA_NOACTIVATE;
}

void CNotFocusedDlg::OnBnClickedButton1()
{
    //do something here...
}



除了第一个WM_ACTIVATE消息,此代码似乎正常工作.我尝试使用WM_EX_NOACTIVATE样式,但似乎我在那里缺少某些东西...
无论如何,我希望它能对您有所帮助.



This code seems to work except for the first WM_ACTIVATE message. I tried to use the WM_EX_NOACTIVATE style but it seems I''m missing something there...
Anyway I hope it will help you a bit.


我不确定它是否会起作用,但是您可以尝试覆盖PreTranslateMessage函数.在这里,您可以决定是否处理每个消息(例如,WM_MOUSEACTIVATE).

要更改对话框样式,请查看ModifyStyleModifyStyleEx

要从代码发送键盘事件,这可能会有所帮助:
使用keybd_event()函数进行键盘事件模拟 [
I am not sure if it will work, but you may try to override the PreTranslateMessage function. Here, you can decide to process each message or not (WM_MOUSEACTIVATE for example).

To change the dialog styles, have a look to ModifyStyle and ModifyStyleEx

To send keyboard events from code, maybe this could help:
Keyboard Events Simulation using keybd_event() function[^]


设置键盘对话框的WS_EX_NOACTIVATE样式,这样就不会集中注意力.您也许应该也可以在按钮控件上使用相同的样式.
Set the WS_EX_NOACTIVATE style for your keyboard dialog, that way it won''t get focus. You should probably be able to get the same style to work on your button controls too.


这篇关于如何为应用程序MFC创建虚拟键盘MFC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆