Thread: Setting active window

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Setting active window

    I want to make my window the active window as soon as the mouse passes over it. I tried using SetActiveWindow() and SetForegroundWindow() but those functions didn't do it, they just made the taskbar entry flash. I then did this:

    Code:
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	case WM_MOUSEMOVE:
    		if (hwnd!=GetActiveWindow())
    		{
    			mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,NULL, NULL);
    			mouse_event(MOUSEEVENTF_LEFTUP,0,0,NULL, NULL);
    		}
    		break;
    
    	default:
    		break;
    	}
    
    	return DefWindowProc(hwnd,msg,wParam,lParam);
    }
    And it works fine. Is there a more efficient way to do it? Maybe I'm not using SetActiveWindow() correctly?
    Last edited by bennyandthejets; 10-14-2003 at 01:04 AM.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    When i use multiple forms, i set focus like this(ws is a WinStack that keeps the HWND's):
    Window that receives focus:
    Code:
    case WM_SETFOCUS:
      BringWindowToTop(ws->GetTop());
      SetFocus(ws->GetTop());
      break;
    Window that loses focus:
    Code:
    SetFocus(ws->GetTop());

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM