0

I am trying to make a simple game in Win32 C++ and I made a settings window that gets called when the user presser the 'P' button or 'Esc'.

Now my question is how can I give that settings window the focus as long as the window is not destroyed, I tried using the SetFocus(); function and also I tried to send a WM_SETFOCUS and WM_KILLFOCUS Messages by using the SendMessage(); function and they worked fine but when I press on the main window with the mouse the focus goes to the main window again.

I don't know if my problem had something with the focus but what I am trying to do is to make my settings window like a message box that once it appear you cant click outside it unless you closed it.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
  • 3
    When your application opens a new window, it automatically gets the focus. Don't mess with it, and you'll be fine. There is hardly ever a reason to call `SetFocus`, and you *certainly* should never send `WM_SETFOCUS`/`WM_KILLFOCUS` messages yourself by calling `SendMessage`! – Cody Gray - on strike Aug 27 '16 at 15:36
  • OK i get it but i want to keep it focused even if the user presses outside this window. is it possible?and how? – Abdullah O.r. Aug 27 '16 at 15:41
  • 1
    You want a modal dialog. Simple solution is to call `DialogBox` to create and display the dialog. Alternatively, you could disable the main window. – Cody Gray - on strike Aug 27 '16 at 15:45
  • Also keep in mind that on Windows, "focus" just means "can receive keyboard messages". A control in your dialog window will have the focus at any given time. It will be indicated with a dotted rectangle around it or inside it. – andlabs Aug 27 '16 at 18:10
  • Dialog box should fix your problem. If you are creating a window then show the code, including the creation flags for the new window. – Barmak Shemirani Aug 27 '16 at 21:45
  • ok thanks it worked well now with me – Abdullah O.r. Aug 28 '16 at 10:39
  • You should use the `@` character, as in @UserName if you want to get the attention of a specific user who commented on your post. Not everybody revisits the same question. Anyway, your question was headed in the wrong direction... – Barmak Shemirani Aug 28 '16 at 16:20

0 Answers0