Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 554637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:43:52+00:00 2026-05-13T11:43:52+00:00

1.I want to find a window and set focus on it , but window

  • 0

1.I want to find a window and set focus on it , but window is not taking the focus.

2.If i use HWND_TOP then it does not make the window active and if i use HWND_TOPMOST then it make window always on top.

Can anyone help me ??

HWND hwndAppDlg = ::FindWindowEx(hwndDesktop,NULL,lpszClass,lpszWindow);

    if(hwndAppDlg && IsWindow(hwndAppDlg))
    {
        CRect rcAppDlg;
        if( 0 == ::GetWindowRect(hwndAppDlg,rcAppDlg))
        {
            OutputDebugString(L"\n GetWindowRect failed...");           
            return FALSE;
        }
        if(0 == ::SetWindowPos(hwndAppDlg,HWND_TOPMOST,rcAppDlg.left,rcAppDlg.top,rcAppDlg.Width(),rcAppDlg.Height(),SWP_SHOWWINDOW))
        {
            OutputDebugString(L"\n SetWindowPos failed...");            
            return FALSE;
        }
        if(0 == ::PostMessage(hwndAppDlg,WM_SETFOCUS,0,0))
        {
            OutputDebugString(L"\n WM_SETFOCUS failed");        
            return FALSE;
        }

        return TRUE;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:43:52+00:00Added an answer on May 13, 2026 at 11:43 am

    You’re sending WM_SETFOCUS, but that does not set the focus. That message is sent to a control if it gained or lost the focus, but when that message is sent/received, the focus change has already happened.

    To actually set the focus (you don’t need to send the WM_SETFOCUS message), use SetFocus() if you know which control in the dialog should get the focus, or SetForegroundWindow() to set the focus to the dialog itself and let the dialog determine which subcontrol actually will get the focus.
    Both of these APIs will send WM_SETFOCUS automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find a struct in a vector, but I'm having some troubles.
I want to use Vim's soft wrap capability ( :set wrap ) to wrap
I use Qt.4.6 in Nokia phone. My window, derived from QWidget, has set nontiled
What I am trying to do is show a window, that does not explicitly
i want to display text on my window and a next button ,but when
I want to make a javascript popup whit an advertisement, and then close down
I want to make a universal soundboard. But it won't run, that is strange
I just want to find out how to run two WPF windows (one in
I want find all Saturdays and Sundays in A given month. How can I
I want to find the sum and count of specific values in my table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.