15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Keyboard data entry when using CBitmapButton controls

puzz -- puzz@nconline.com
Tuesday, February 11, 1997

Environment: Visual C++ 4.0 Windows 95


I'm creating a modal dialog application with CBitmapButton Controls. My
problem is that I want to be able to use the keyboard to enter data in
addition to clicking on the buttons with the mouse. Here is the code
that I have come up with so far. I'm basically trying to use the
LoadAccelerators() and TranslateAccelerators() functions. It compiles,
but the .exe doesn't do anything.




Dialog.h
{...
protected:
LPCTSTR lpTableName;
HINSTANCE hInstance;
HACCEL hAccTable;
HWND hWnd;
LPMSG lpMsg;
int Test;
int TwoTest;
int ThreeTest;
...} 

Dialog.cpp
BOOL CNewCalcDlg::OnInitDialog()
{...
        Test = IDR_STANDCALCACCEL;
        lpTableName = MAKEINTRESOURCE(Test);
        hInstance = AfxGetInstanceHandle();
        hAccTable =LoadAccelerators(hInstance, lpTableName);
...}




void CNewCalcDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
        // TODO: Add your message handler code here and/or call default
        hWnd = m_hWnd;
        TwoTest = GetMessage(lpMsg, hWnd, 0,32000);
        ASSERT(ThreeTest = TranslateAccelerator(hWnd, hAccTable,
lpMsg));
        
        CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}


Thank you in advance for any help.





David Lowndes -- David.Lowndes@bj.co.uk
Wednesday, February 12, 1997

>I'm creating a modal dialog application with CBitmapButton Controls. My
problem is that I want to be able to use the keyboard to enter data in
addition to clicking on the buttons with the mouse. Here is the code
that I have come up with so far. I'm basically trying to use the
LoadAccelerators() and TranslateAccelerators() functions. It compiles,
but the .exe doesn't do anything.
<

Do you need to write any code? I've used normal buttons on a dialog
that display icons (using the new Win32 button facilities - they're
easier than CBitmapButton), and simply giving them a caption text
with the '&' character prefix (as you would normally) is all that is
required to have keyboard accelerator operation.

>Dave



David Little -- dlittle@equinoxcorp.com
Wednesday, February 12, 1997

[Mini-digest: 3 responses]

Try PreTranslateMessage()...like this:

BOOL CRemittancePage::PreTranslateMessage(MSG* pMsg) 
{
    if(!(hAccel && ::TranslateAccelerator(m_hWnd, hAccel, pMsg)))
         return CDialog::PreTranslateMessage(pMsg);
      else
         return TRUE;
}

Your OnInitDialog() should be OK...


----------
From: 	puzz[SMTP:puzz@nconline.com]
Sent: 	Tuesday, February 11, 1997 12:21 PM
To: 	mfc-l@netcom.com
Subject: 	Keyboard data entry when using CBitmapButton controls

Environment: Visual C++ 4.0 Windows 95


I'm creating a modal dialog application with CBitmapButton Controls. My
problem is that I want to be able to use the keyboard to enter data in
addition to clicking on the buttons with the mouse. Here is the code
that I have come up with so far. I'm basically trying to use the
LoadAccelerators() and TranslateAccelerators() functions. It compiles,
but the .exe doesn't do anything.




Dialog.h
{...
protected:
LPCTSTR lpTableName;
HINSTANCE hInstance;
HACCEL hAccTable;
HWND hWnd;
LPMSG lpMsg;
int Test;
int TwoTest;
int ThreeTest;
...} 

Dialog.cpp
BOOL CNewCalcDlg::OnInitDialog()
{...
        Test = IDR_STANDCALCACCEL;
        lpTableName = MAKEINTRESOURCE(Test);
        hInstance = AfxGetInstanceHandle();
        hAccTable =LoadAccelerators(hInstance, lpTableName);
...}




void CNewCalcDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
        // TODO: Add your message handler code here and/or call default
        hWnd = m_hWnd;
        TwoTest = GetMessage(lpMsg, hWnd, 0,32000);
        ASSERT(ThreeTest = TranslateAccelerator(hWnd, hAccTable,
lpMsg));
        
        CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}


Thank you in advance for any help.
-----From: "Geoffrey C. Begen" 

I did this very simply in a 16-bit application using VC++ 1.5. This
method should work for 4.0 as well. CBitmapButton uses the caption of
the button to find the bitmap resources to display. If you include an
ampersand (&) in the caption of the button, the dialog window procedure
will handle the keyboard accelerator for you. The only trick is to also
use the ampersand in the resource ID of the bitmaps.

For example, I created a telephone dialer dialog using bitmap buttons.
The picture for the two button had the letters ABC above it and so on.
The caption on the two button was set to "&2Two" and I had two bitmaps
resources named &2TWOU and &2TWOD. MFC figured it all out and displayed
my bitmaps on the buttons and the dialog still responded to Alt+2 as
pressing the two button.

--- Geoff
>----------
>From: 	puzz[SMTP:puzz@nconline.com]
>Sent: 	Tuesday, February 11, 1997 10:21 AM
>To: 	mfc-l@netcom.com
>Subject: 	Keyboard data entry when using CBitmapButton controls
>
>Environment: Visual C++ 4.0 Windows 95
>
>
>I'm creating a modal dialog application with CBitmapButton Controls. My
>problem is that I want to be able to use the keyboard to enter data in
>addition to clicking on the buttons with the mouse. Here is the code
>that I have come up with so far. I'm basically trying to use the
>LoadAccelerators() and TranslateAccelerators() functions. It compiles,
>but the .exe doesn't do anything.
>
>
>
>
>Dialog.h
>{...
>protected:
>LPCTSTR lpTableName;
>HINSTANCE hInstance;
>HACCEL hAccTable;
>HWND hWnd;
>LPMSG lpMsg;
>int Test;
>int TwoTest;
>int ThreeTest;
>...} 
>
>Dialog.cpp
>BOOL CNewCalcDlg::OnInitDialog()
>{...
>        Test = IDR_STANDCALCACCEL;
>        lpTableName = MAKEINTRESOURCE(Test);
>        hInstance = AfxGetInstanceHandle();
>        hAccTable =LoadAccelerators(hInstance, lpTableName);
>...}
>
>
>
>
>void CNewCalcDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
>{
>        // TODO: Add your message handler code here and/or call default
>        hWnd = m_hWnd;
>        TwoTest = GetMessage(lpMsg, hWnd, 0,32000);
>        ASSERT(ThreeTest = TranslateAccelerator(hWnd, hAccTable,
>lpMsg));
>        
>        CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
>}
>
>
>Thank you in advance for any help.
>
>
>
-----From: puzz 

mfc-l@netcom.com wrote:
> 
> >I'm creating a modal dialog application with CBitmapButton Controls. My
> problem is that I want to be able to use the keyboard to enter data in
> addition to clicking on the buttons with the mouse. Here is the code
> that I have come up with so far. I'm basically trying to use the
> LoadAccelerators() and TranslateAccelerators() functions. It compiles,
> but the .exe doesn't do anything.
> <
> 
> Do you need to write any code? I've used normal buttons on a dialog
> that display icons (using the new Win32 button facilities - they're
> easier than CBitmapButton), and simply giving them a caption text
> with the '&' character prefix (as you would normally) is all that is
> required to have keyboard accelerator operation.
> 
> >Dave

  That is a good, simple solution to my problem. After perusing the
online help for two hours, I figured out how to get the handle to the
icon and load it on the button. Thank you.






Become an MFC-L member | Вернуться в корень Архива |