如何使用位图实现按钮类型效果

发布于 2024-09-16 08:44:26 字数 1560 浏览 7 评论 0原文

您好,我有一个与启用位图的对话框窗口的使用相关的问题。我创建了一个键盘类型布局,我也希望通过键盘获取输入。当我使用鼠标时,我能够获取按钮按下并且所有按钮都工作正常 - 其他图像 DEFAULT,SELECTED,DISABLED ..全部加载并工作,因为我在这里使用该函数 m_BtnBtn1Ctrl.LoadBitmaps ,但是,键盘上按下的任何键和屏幕上的相应字符都无法执行与我通过单击鼠标(并使用 Loadbitmaps() 函数)相同的操作)。

我使用这3个函数来实现与使用鼠标相同的动作和效果
加载位图()
设置位图()
Invalidate()

我也尝试了这段代码

HBITMAP hbm = (HBITMAP)LoadImage(NULL, "\\res\\Selected\\bitmap21.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

bitmap.Attach((HBITMAP)LoadImage(NULL, "\\res\\Selected\\bitmap21.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION));

但这些代码似乎没有给出按下按钮的效果,尽管它们在内部工作。有人可以帮我解决这个问题吗?

谢谢和问候 Sayonee

崩溃

BOOL KeyBoard_press::PreTranslateMessage(MSG* pMsg)
{
    // TODO: Add your specialized code here and/or call the base class
    CString strTemp;
    if (pMsg->message == WM_KEYDOWN)
    {
        if ( pMsg->wParam == 0x41 || pMsg->wParam == 0x61) //check for both 'a' and 'A'
            OnBtnBtn1();
        if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_DELETE ||
            pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_TAB ||
            pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || GetKeyState (VK_CONTROL))
            {
                ::TranslateMessage (pMsg);
                ::DispatchMessage (pMsg);
                return TRUE;                // DO NOT process further
            }
    }
    return CDialog::PreTranslateMessage(pMsg);
}

Hello there I have a issue related to the usage of the bitmap enabled Dialog window.I have created a keyboard type layout and i wish to get the input through keyboard also.When i use the mouse I am able to get the button(s) pressed and also all the buttons are working fine - the other images DEFAULT,SELECTED,DISABLED ..all get loaded and work since I am using the function here m_BtnBtn1Ctrl.LoadBitmaps ,But then any key pressed on keyboard and the corresponding character on the screen isn't able to do the same as I have been able to do it with clicking of the mouse(and using the Loadbitmaps() function ).

I am using these 3 functions to achieve the same action and effect as that using a mouse
LoadBitmap()
SetBitmap()
Invalidate()

I also tried this piece of code

HBITMAP hbm = (HBITMAP)LoadImage(NULL, "\\res\\Selected\\bitmap21.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

and

bitmap.Attach((HBITMAP)LoadImage(NULL, "\\res\\Selected\\bitmap21.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION));

but these don't seem to give the pressed button effect though internally they work.Can some one please help me with this

Thanks and regards
Sayonee

Collapse

BOOL KeyBoard_press::PreTranslateMessage(MSG* pMsg)
{
    // TODO: Add your specialized code here and/or call the base class
    CString strTemp;
    if (pMsg->message == WM_KEYDOWN)
    {
        if ( pMsg->wParam == 0x41 || pMsg->wParam == 0x61) //check for both 'a' and 'A'
            OnBtnBtn1();
        if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_DELETE ||
            pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_TAB ||
            pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || GetKeyState (VK_CONTROL))
            {
                ::TranslateMessage (pMsg);
                ::DispatchMessage (pMsg);
                return TRUE;                // DO NOT process further
            }
    }
    return CDialog::PreTranslateMessage(pMsg);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赤濁 2024-09-23 08:44:26

据我了解,您有一系列模拟计算机键盘布局的按钮。每当用户按下键盘上的某个键时,您都需要在对话框中模拟按钮单击。您已经为每个按钮的每种状态提供了位图。

为此,我将处理 WM_KEYDOWNWM_KEYUP 消息。在处理程序中,使用按键到实际按钮实例的某种映射。然后,将BM_SETSTATE发送到按钮控件。

然后,处理来自每个按钮的 WM_COMMAND 消息并检查 BN_CLICKED 代码。

As far as I understand, you have a series of buttons that simulate a computer keyboard layout. whenever the user presses a key on the keyboard, you need to simulate a button click in your dialog box. You have provided bitmaps for each state of each button.

To do this, I would process the WM_KEYDOWN and WM_KEYUP messages. In the handlers, use some mapping of the key to the actual button instance. Then, send the BM_SETSTATE to the button control.

Then, process the WM_COMMAND message from each of the buttons and check for the BN_CLICKED code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文