Main Menu

setfocus

Started by James Fuller, June 23, 2016, 12:18:03 PM

Previous topic - Next topic

James Fuller

Jose,
  How and or where to setfocus to a control ?

James

Paul Squires

If you mean where to set the initial focus then I am doing it immediately before that form's message pump (pWindow->DoEvents())
Paul Squires
PlanetSquires Software

James Fuller

Ok the button I want with the focus does have it and if I press the space bar the coded action happens.
But there is no visual clue as which control has the actual focus until one presses the tab key.
Then we have the blue border (Win10) around the command button with the focus.
Is there a way to induce the visual clue?
James


Paul Squires

On my system when I set focus to a regular command button, I get the dotted rectangular outline showing on the button.
Paul Squires
PlanetSquires Software

Paul Squires

As an off-topic aside, in order to prevent visual issues such as a form moving into position after creation, I do not set the WS_VISIBLE style of the form when I create it. Just before the message pump I will issue a ShowWindow call to show the form. This works especially well in cases where you create the form, center it on screen, and then final add controls to the form.
Paul Squires
PlanetSquires Software

James Fuller

Looking at the CWindow help file I do not see where WS_VISIBLE is even used for the default in the Create Method??

James

Paul Squires

You are probably right. I never use the default styles. I always explicitly set the standard and extended styles just so I am always 100% sure of how the control was created.
Paul Squires
PlanetSquires Software

José Roca

#7
Sorry, I have been one day without internet conexion because of a little problem activating the new router. Now I have 300 MB.

> Looking at the CWindow help file I do not see where WS_VISIBLE is even used for the default in the Create Method??

Contrarily to controls, it is not used at all. You decide what to do with the value passed as nCmdShow pWindow.DoEvents(nCmdShow).


   ' // Show the window and update its client area
   IF nCmdShow = 0 THEN .ShowWindow m_hwnd, SW_SHOW ELSE .ShowWindow m_hwnd, nCmdShow
   .UpdateWindow m_hwnd


If the value is 0 (the default), DoEvents will call ShowWindow m_hwnd, SW_SHOW and UpdateWindow m_hwnd. This follows what Paul does. I don't like to see a window and its controls moving and resizing.

You can replace DoEvents with your own message pump and do the ShowWindow/UpdateWindow when you like.