How can i make a window always ontop so the user can just click out of the window area to minimize the program? .
How can i make a window always ontop so the user can just click out of the window area to minimize the program? .
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.
Are you using a framework such as MFC?
Kuphryn
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...
in the regular API you can do something very similar, hopefully thats what you were looking for.Code:AfxGetMainWnd()->SetWindowPos( &wndTopMost, xstart, ystart, xwidth, ywidth, SWP_NOZORDER);
Last edited by dpro; 12-13-2004 at 01:00 PM.
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.if this is MFC, the easiest I found was to use...Code:AfxGetMainWnd()->SetWindowPos( &wndTopMost, xstart, ystart, xwidth, ywidth, SWP_NOZORDER);
To make your window the top-most window use: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:SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);Code:if (nState == WA_INACTIVE) ShowWindow(SW_MINIMIZE);
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!
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; }
>>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
At first glance it looks like you are looking for a top most window...
im trying to make it so the user cant do anything until the password is entered