Set Focus When Mouse Over Button (MFC)
Hello.
made a bitmap button (3 states up down and focus)
default is up.
using tab I can focus on the button.
disabled TAB,
I want to focus on mouse over or on mouse hover.
why does the following not work?
Code:
void C_MAINMENU_DIALOG::OnMouseHover(UINT nFlags, CPoint point)
{
btnBmpCOD1.SetBitmap(::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_COD1_FOCUS)));
// TODO: Add your message handler code here and/or call default
// CDialog::OnMouseHover(nFlags, point);
}
regards
gerwin
Re: Set Focus On Mouse Hover (MFC)
Is the OnMouseHover handler getting called?
What does ::LoadBitmap return?
Re: Set Focus On Mouse Hover (MFC)
I used the wizard to call the WM_ message.
I will check anyway.
the statement calls the bitmap for focus.
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
Quote:
Originally Posted by
TBBW
I used the wizard to call the WM_ message.
I will check anyway.
That's fine, but it doesn't mean that an error didn't occur when the wizard generated the code (and the message map entry didn't get inserted properly).
Just put a breakpoint in the handler and run under a debugger.
Also check the return value of LoadBitmap. There could be a problem loading the bitmap.
Re: Set Focus On Mouse Hover (MFC)
To Arjay,
I think was not clear enough on my problem.
What I want is, when the mouse pointer enters the button area, the button should change
to a different color or picture. so basically it is not the hover message I have to use.
I can't find a message like 'mouse_over' should it should be done else.
I saw examples using mouse_move, but they are not bullit proof.
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
You need to handle the BCN_HOTITEMCHANGE message.
If you are using VC2005 or VC2008, you can add this message handler by opening the dialog in the resource editor, right clicking on the button and choose, "Add Event handler". When the Event Handler Wizard opens, select BCN_HOTITEMCHANGE under message types and choose "Add and Edit".
When the code is generated, put a break point inside the new handler, run the app in debug mode, and put the mouse over the button. The new button handler should be hit. This handler gets called when the mouse enters the button rect and also leaves it. You can determine which state by checking the dwFlags param. See NMBCHOTITEM in msdn. When you add the handler you can see how this is wired up from the generated handler.
Re: Set Focus On Mouse Hover (MFC)
Hi Arjay,
did as told!!
and did some add. searching.
but i'm stuck ...
this is the code:
Code:
void C_MAINMENU_DIALOG::OnBnHotItemChangeButton1(NMHDR *pNMHDR, LRESULT *pResult)
{
// This feature requires Internet Explorer 6 or greater.
// The symbol _WIN32_IE must be >= 0x0600.
LPNMBCHOTITEM pHotItem = reinterpret_cast<LPNMBCHOTITEM>(pNMHDR);
MessageBox(0,L"in",0);
if( pHotItem->dwFlags & HICF_ENTERING )
MessageBox(0,L"if",0);
else
MessageBox(0,L"else",0);
// TODO: Add your control notification handler code here
*pResult = 0;
}
the most important problem the above copied code segment is never called.
(message map is avail; ON_BN_CLICKED handler is working fine)
I'm using msvc 2008 in a win 7 environment.
do I need to include some extra parts (manifest)?
because the feature must use IE 6.0 or higher etc. ...
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
Please post the code of the MESSAGE_MAP entries.
Re: Set Focus On Mouse Hover (MFC)
In the .h file:
Code:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
afx_msg void OnBnHotItemChangeButton1(NMHDR *pNMHDR, LRESULT *pResult);
and in the .cpp file:
Code:
BEGIN_MESSAGE_MAP(C_MAINMENU_DIALOG, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, &C_MAINMENU_DIALOG::OnBnClickedButton1)
ON_NOTIFY(BCN_HOTITEMCHANGE, IDC_BUTTON1, &C_MAINMENU_DIALOG::OnBnHotItemChangeButton1)
END_MESSAGE_MAP()
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
Arjay,
this is the 'ghost';
Code:
BOOL C_CODMENU::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
I do not understand the line Set this to include all the common ......
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
Quote:
Originally Posted by
TBBW
Arjay,
this is the 'ghost';
Code:
BOOL C_CODMENU::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
I do not understand the line Set this to include all the common ......
regards,
ger
I don't know either. Have you looked in Msdn for InitCommonControlsEx? I'll bet the documentation will explain the settings.
Re: Set Focus On Mouse Hover (MFC)
did some additional search work and
The lines
Code:
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
should be as it is.
I also found out, you have to check the option 'common control manifest' when the project
is created (using the MFC wizard gives you a linker add. in the stdafx.h).
as I do not get any erros (compile and link) I think I included everything (Libs/headers).
Apart from a working button the ON_NOTIFY routine is still not called.
regards,
ger
1 Attachment(s)
Re: Set Focus On Mouse Hover (MFC)
Start over. Create a new MFC dialog application in Visual Studio 2008. Use all the defaults (other than the application type).
Open the resource editor, drag a button on the dialog.
Right click on the button, and choose "Add event handler..."
Select "BCN_HOTITEMCHANGED".
Click "Add and edit"
When it takes you to the method, put the mouse cursor on the line that begins with LPNMBCHOITEM and press F9 (to set a breakpoint).
Build the project and press F5 to run the app in debug mode.
Run the mouse over the button. The breakpoint should be hit.
IMPORTANT: do this by creating a brand new VC++ 2008 MFC dialog application project as I've outlined above.
Attached is a working VS2008 MFC dialog project, all you have to do is put a breakpoint inthe hotitemchanged handler, build the project, and run it with F5.
Once you get it working in a new project, compare with your project to find out why your project doesn't work.
Re: Set Focus On Mouse Hover (MFC)
Arjay,
Thanks for the reply, will have a go.
but first I have to update, to include afxcontrolbar.h
keep you informed
regards,
ger
Re: Set Focus On Mouse Hover (MFC)
Quote:
Originally Posted by
TBBW
but first I have to update, to include afxcontrolbar.h
Why?
Look, if you hope to figure this out, then why don't you try to create a new project or run the existing sample that I provided?
The reason being is that you need to determine if the functionality that I provided (or is default in a new project) works for you.
If you modify the program by adding afxcontrolbar.h first, you won't know what's causing the issue (i.e the project is broken on your system, or YOU broke the project by modifying it).