Making a mouse hover button, API style

This is a discussion on Making a mouse hover button, API style within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a mouse hoverbutton, API style - - when mouse is NOT over the button, it ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    Talking Making a mouse hover button, API style

    I am trying to make a mouse hoverbutton, API style

    - - when mouse is NOT over the button, it stays as it's default image
    - when mouse is over the button, it changes to "mouse over image"
    - when mouse leaves the button, it changes back to it's default image

    here's what i have done so far:
    in my main window proc
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    		case WM_CREATE:
    			{
    					
    				dia_hwnd = CreateDialog(GetModuleHandle(0),MAKEINTRESOURCE(IDD_MENU) ,hwnd,MenuProc);
    				ShowWindow(dia_hwnd, SW_SHOWNORMAL);
    							
    			TRACKMOUSEEVENT mouse_event_struct;
    			mouse_event_struct.cbSize = sizeof(TRACKMOUSEEVENT);
    			mouse_event_struct.dwFlags = TME_HOVER 
    			mouse_event_struct.hwndTrack =dia_hwnd; 
    			mouse_event_struct.dwHoverTime = 400;
    			 _TrackMouseEvent(&mouse_event_struct);
    			
    			
    
    
    
    
    						
    				
    			}
    		break;
    
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{ ............
    In my MenuProc proc ( for the window dia_hwnd)
    Code:
    BOOL CALLBACK MenuProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    			{
    
    
    			}
    			break;
            return TRUE;
    		
    		case WM_MOUSEHOVER:
    			{
    				MessageBox(NULL, "mouse left in", "GOOD",
    			MB_ICONEXCLAMATION | MB_OK);
    			}
    			break;
    
    
    
    
    
            case WM_COMMAND:
                switch(LOWORD(wParam))
    			            {........
    "mouse left in" message never comes up after i moved my mouse into dia_hwnd window
    that means that the code doesnt detect that mouse went into the window. There's something wrong here, please help.


    using
    - win98se
    - vc++6.0
    - API style

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    From MSDN:
    The mouse hovered over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. Hover tracking stops when this message is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.
    You need to call TrackMouseEvent every time you want to recieve the WM_MOUSEHOVER message (if you have already recieved one). I am not actually sure why you don't get one after it has been called in WM_CREATE, although I am sure if I thought about long enough I could come up with something, but that is the same behaviour that I observe.

    I recently needed this to and I placed the call to TrackMouseEvent in a WM_LBUTTONDOWN message handler, so I could trigger the message by left clicking on the window. Worked fine, but that is probably not going to suffice for your purposes..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Win32 API , Windows XP Button styles
    By Rare177 in forum Windows Programming
    Replies: 12
    Last Post: 06-28-2006, 05:28 PM
  3. Disabling "X" button on Window
    By Boomba in forum Windows Programming
    Replies: 3
    Last Post: 06-14-2003, 01:53 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21