Thread: Scroll Bars and Focus

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Scroll Bars and Focus

    I have a seperate window (the map window from last thread) that I added scroll bars to. I would like that window to never have focus EXCEPT when the user uses the scroll bars. Before I added the scroll bars I just processed the WM_SETFOCUS command and used SetFocus to the window that I wanted the focus to be at. Well I quickly found out that using that code would block my scroll bars from working.

    I'm not really sure where to begin. I'm thinking of processing the WM_SETFOCUS, finding out where the mouse is, if its not over a scroll bar using SetFocus to go back to main window, if it is over a scroll bar processing the change and when SB_ENDSCROLL occurs using SetFocus to go back.

    Or am I just crazy?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok got it working. Here is the code I'm using if anyone is wondering.

    Global:
    Code:
    HWND hMainWin, hMapWin;
    Inside the WndProc for hMapWin:

    When window recieves focus:
    Code:
            case WM_SETFOCUS:
                    GetCursorPos (&pMouse);
                    ScreenToClient (hMapWin, &pMouse);
                    if ( pMouse.x < 585 && pMouse.y < 585)
                       SetFocus (hMainWin);
                    return 0;
    After user is done scrolling (processed in both WM_VSCROLL and WM_HSCROLL)

    Code:
                           case SB_ENDSCROLL:
                                SetFocus (hMainWin);
                                break;
    Only problem I see is when using the arrows at the end of the scroll bar the focus switches between windows quickly if the user clicks the arrow insteads of holding it down. Oh well small price to pay

Popular pages Recent additions subscribe to a feed