CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Posts
    69

    a window that stays topmost

    How can i create a window that stays topmost and don't loose focus with ALT+TAB or by any other process lunch like Task Manager?

    I can create a fullscreen topmost window but unable to keep it topmost. For example, ALT+TAB brings up the taskbar and if I start Task Manager, the Task Manager window becomes the topmost window. I want to prevent loosing focus of my fullscreen window and don't want any other window to pop up.

    Thanks.
    ~Donotalo()

  2. #2
    Join Date
    Apr 2008
    Posts
    111

    Re: a window that stays topmost

    You can try using the WS_EX_TOPMOST style in the CreateWindowEx function.

    More info here http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx .

  3. #3
    Join Date
    Aug 2005
    Posts
    69

    Re: a window that stays topmost

    My window is using this style. But then if I press ALT+TAB, the task bar is shown which is not desirable. From the task bar I can activate Task Manager. In my computer, the option Always on top is activated for Task Manager. So activating Task Manager brings it on my window. This is also undesirable. Any solution to prevent them?
    ~Donotalo()

  4. #4
    Join Date
    Apr 2008
    Posts
    111

    Re: a window that stays topmost

    Try using SetWindowPos API with HWND_TOPMOST.

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: a window that stays topmost

    Why are you trying to do this?
    Please explain the usecase.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  6. #6
    Join Date
    Aug 2005
    Posts
    69

    Re: a window that stays topmost

    Code:
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
    
       hInst = hInstance; // Store instance handle in our global variable
    
       hWnd = CreateWindowEx(	WS_EX_TOPMOST,
    							szWindowClass,
    							szTitle,
    							WS_MAXIMIZE | WS_POPUP,
    							0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
    							NULL,
    							NULL,
    							hInstance,
    							NULL);
    //   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
    //      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       if (!hWnd)
       {
          return FALSE;
       }
    
       SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 100, 100, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    //   ShowWindow(hWnd, nCmdShow);
    //   UpdateWindow(hWnd);
    
       return TRUE;
    }
    doesn't work as i wanted. pressing windows key brings up the taskbar and start menu. from there task manager can be opened. pressing Ctrl+Alt+Delete also brings up the task manager on the top of my window. i think i need to handle those keys such that they will be consumed by my program. i didn't program, but i know one way - hooking a dll. is there any other way?

    usecase:
    my program will be one of the startup process. so after logging in, it will not allow any other program to be foreground program. it will ask for a password. a valid password will close the window. believe it or not, sometimes i feel that i need such a software. there may be such software available freely to use, but i want to build my own. i'm a basic win32 programmer. i want to learn such advanced features of the api.

    thanks for your time.
    ~Donotalo()

  7. #7
    Join Date
    Nov 2007
    Posts
    613

    Re: a window that stays topmost

    Quote Originally Posted by Donotalo
    usecase:
    my program will be one of the startup process. so after logging in, it will not allow any other program to be foreground program. it will ask for a password. a valid password will close the window.
    If your window imitates the appearance of the login dialog box that's the perfect tool to steal passwords. This is not a hacker forum.

  8. #8
    Join Date
    Aug 2005
    Posts
    69

    Re: a window that stays topmost

    Quote Originally Posted by srelu
    If your window imitates the appearance of the login dialog box that's the perfect tool to steal passwords. This is not a hacker forum.
    The password will be set by the user and it doesn't have to be windows password. Besides, this the program I need for my personal use. I've no intention to distribute it right now.

    I said before that I've learnt the basics of windows programming. I'm trying to learn some advanced features. Whenever I got stuck I post it in a forum. Whenever I ask something advanced to learn, I got stuck with this kind of reply. I wonder what is the way to learn advanced features of something like this.
    ~Donotalo()

  9. #9
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: a window that stays topmost

    So you are trying to implement a login window. In that case checkout GINA.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured