Always on top

This is a discussion on Always on top within the Windows Programming forums, part of the Platform Specific Boards category; How can i make a window always ontop so the user can just click out of the window area to ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Always on top

    How can i make a window always ontop so the user can just click out of the window area to minimize the program? .

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Can you explain this in detail ? It doesn't seem to make sense having a window always on top, but vanishing when another application get the focus ( when clicked ).
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Are you using a framework such as MFC?

    Kuphryn

  4. #4
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    I assume you mean so it can't be minimized, simply when the window is initialized... or whenever you want to set it to be topmost you can do it one of two ways.

    If this is a dialog window then set the System Modal property(if you want it to stay on top no matter what).

    If this is a regular window you can call

    if this is MFC, the easiest I found was to use...

    Code:
    AfxGetMainWnd()->SetWindowPos( &wndTopMost, xstart, ystart, xwidth, ywidth, SWP_NOZORDER);
    in the regular API you can do something very similar, hopefully thats what you were looking for.
    Last edited by dpro; 12-13-2004 at 01:00 PM.

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    if this is MFC, the easiest I found was to use...
    Code:
    AfxGetMainWnd()->SetWindowPos( &wndTopMost, xstart, ystart, xwidth, ywidth, SWP_NOZORDER);
    Actually, you are specifying that you do not want the Z order of the app to change which is quite the opposite of the desired effect.

    To make your window the top-most window use:
    Code:
    SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    And in order to make your application minimize when it loses focus, process the WM_ACTIVATE message (or use OnActivate() with MFC) and minimize yourself if you're becoming inactive like this:
    Code:
      if (nState == WA_INACTIVE)
        ShowWindow(SW_MINIMIZE);

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Oops my bad, I was reading the msdn, and saw something about using SWP_NOZORDER, but I must've misread it, too tired. Anyway, yeah thats a good way to do that. Keeps the window up top. Thanks for the correction, and sorry for the misinformation!

  7. #7
    Banned
    Join Date
    Oct 2004
    Posts
    250
    how would i make this window stay on top no matter what i tried these ways they dont work could someone help me
    Code:
    #include <windows.h>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    #define EDIT1 5001
    #define EDIT2 5002
    #define BUTTON3 5003         // source code copyright 2004 www.cyclone337.uni.cc
    #define GROUP4 5004
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	HWND hWnd = FindWindow(NULL, "Windows Task Manager");
    
    	if (hWnd)
    	{
    		SendMessage(hWnd,WM_CLOSE,0,0);
    	}
    
        switch(msg)
        {
    	case WM_CREATE:
    		CreateWindowEx(0,
    			TEXT("STATIC"),
    			TEXT("Password Protector 1.0\nPlease enter your password."),
    			WS_CHILD|WS_VISIBLE,
    			30,
    			100,
    			200,
    			30,
    			hwnd,
    			(HMENU)EDIT1,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("EDIT"),
    			NULL,
    			WS_CHILD|WS_VISIBLE|WS_BORDER|ES_PASSWORD,
    			30,
    			60,
    			100,
    			30,
    			hwnd,
    			(HMENU)EDIT2,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Enter"),
    			WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    			150,
    			60,
    			90,
    			40,
    			hwnd,
    			(HMENU)BUTTON3,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Main"),
    			WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
    			10,
    			10,
    			270,
    			140,
    			hwnd,
    			(HMENU)GROUP4,
    			NULL,
    			NULL);
    		break;
    		return 0;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case BUTTON3:
    			char pass[256];
    			GetDlgItemText(hwnd,EDIT2,pass,256);  // gets text from edit box containing the password the user entered
    			
    			if (strcmp(pass, "thepass")==0)  // if the user entered the right password give close the program
    			{
    				PostQuitMessage(0); // closes the window
    			}
    			else
    			{
    				
    			}
    			break;
    		}
    		break;
    
    			
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "WindowClass";
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            "WindowClass",
            "PassPro 1.0",
            WS_OVERLAPPED|WS_MINIMIZEBOX|WS_CAPTION,
            CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
            NULL, NULL, hInstance, NULL);
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
    		HWND hWND = FindWindow(NULL, "Windows Task Manager");   // makes sure the user cant close the program with windows task manager 
    
    		if (hWND)
    		{
    			SendMessage(hWND,WM_CLOSE,0,0);
    		}
    
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>how would i make this window stay on top no matter what i tried these ways they dont work could someone help me

    >>HWND hWND = FindWindow(NULL, "Windows Task Manager"); // makes sure the user cant close the program with windows task manager


    >>// source code copyright 2004 www.cyclone337.uni.cc


    Not something I will help with.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    At first glance it looks like you are looking for a top most window...

  10. #10
    Banned
    Join Date
    Oct 2004
    Posts
    250
    im trying to make it so the user cant do anything until the password is entered

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make opengl draw in lighter colors ?
    By jabka in forum Game Programming
    Replies: 2
    Last Post: 12-17-2007, 06:12 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  4. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 07:01 PM
  5. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21