[Win32 API] Disable Everything

Hello,

how can I make my program (I'm using dialog as main window) to "block" everything (like when u are running some program that needs admin permissions) so u won't be able to do anything until u select "yes" or "no" except minimize and exit

+ what's the message for minimize process? like WM_INITDIALOG etc...
Last edited on
Well, User Account Control uses a secured desktop. You can create a desktop of your own and show your user interface in the new desktop. Note that the effect of dimming the screen(s) when the secured desktop appears is probably nothing else than a screenshot taken from each monitor and then alpha-blended with a semi-transparent black bitmap.

Message for minimizing a window? To INITIATE the action of minimizing a window you usually use ShowWindow(SW_MINIMIZE);. Does this generate a notification message? Probably. I'm not a GUI guy in C++ so I don't really know it. But a few Google searches might prove fruitful.
so there isn't any other way to block or disable everything?
While I consider my area of expertise to be Windows, the GUI part eludes me a bit because I intentionally elude it (I do my GUI's in .net :-O ). As far as I know this would be the only way.

But now that I recall, classic Visual Basic 5 and 6 had the message box. And I clearly recall that you could make this message box "system modal". Basically it would not let you do anything at all except interact with the system modal message box. So I guess there could be out there an obscure way of accomplishing what you need. Maybe.

If you want to learn about secured destkops, Google up "Windows stations and desktops". I think that was the title in MSDN.
closed account (DSLq5Di1)
If I understood your question correctly mekkatorqu, you just want a modal dialog to popup with yes/no buttons? http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505

webJose wrote:
(I do my GUI's in .net :-O )
Gasp! That's cheating!! though I'm not impartial to using a resource editor myself (te-he).
I know it is kindof cheating, but I can't help it. It is so neat and shiny. I therefore code complex stuff in C++ (usually COM) for performance and even ease, and then just interop. Plus, my colleagues don't know C++ so I am bound to at least write .net pluggable code when I use C++.
@sloppy9 no, I want application that will disable everything, like when windows need admin permissions to run application..
closed account (DSLq5Di1)
Hmm.. I guess you could just enumerate and disable all the top level windows,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <windows.h>

BOOL CALLBACK DisableWindows(HWND hWnd, LPARAM lParam)
{
    EnableWindow(hWnd, (BOOL)!lParam);
    return TRUE;
}

int main()
{
    EnumWindows(DisableWindows, TRUE);

    MessageBox(NULL, TEXT("Text"), TEXT("Caption"),
        MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL);

    EnumWindows(DisableWindows, FALSE);

    return 0;
}

There is also an interesting solution provided here:-
http://blog.developex.com/?p=930
That link from sloppy9 is an implementation of a desktop. The code in the article doesn't seem to cover multiple monitors, so take into account the use of EnumDisplayMonitors().
Sorry to be late to respond here...

I am expert in Win32, so before I write more let me come to the point:

Whatever it is that you are trying to do, it is a mistake.


There is no method to do what you want because it is antagonistic to the usage design philosophy of Windows (and all other multitasking UI systems). Sure, it is possible to simulate it to some degree, or hack Windows internal functions to do it for you, but this results in broken behaviors and worse.

Applications should not pretend to be the OS, or to control UI external to the application. Programs that do, frankly, are quickly removed from the system shortly after they were installed by their irate users. The basic design principle is that your program should not take control the user's environment away from the user.

There is nothing that justifies your application doing that. Such functionality belongs to the OS.


Perhaps if you describe what you are trying to accomplish with this we can suggest another way to consider it.

Hope this helps.
I beg to differ. In Windows Vista or Windows 7 (think it was Vista), there was an application that handled credit card information. A virtual wallet. This wallet operated in a separate, secured desktop to disallow any application from spying on the user interface while the user interacted with it.

Furthermore, the creation of windows desktops is publicly documented and contain no warnings that could indicate that their use should be forbidden.

So all in all, while I agree that actual valid reasons are scarce, I don't agree that there are NO valid reasons. The virtual wallet application seems to be like an excellent example of one good reason. Why? The desktop can be secured as any securable object using security descriptors. It is a great security tool, if I may say so. After all, this is the foundation of the security provided by the Ctrl-Alt-Del "window" (in quotation marks because we now know is not a window, it is an entire different desktop).

Oh and let's not forget elevation prompts. They appear in a different secured desktop to provide the exact same security as Ctrl-Alt-Del.
Last edited on
Perhaps I misunderstood something, but the OP is not asking about secure sessions; he is asking about making his program so important that the user must be forced to answer a close/terminate question in a secure manner. What kind of application really needs this? Is he writing software to operate a nuclear power plant?

There is a difference between user spaces. And the need to elevate privileges for specific user inputs has specific ramifications.

CardSpace is a nice example of an application needing said privileges.
I did mention security myself (not the OP), just to praise on what is probably the most prominent of features of the additional desktop. The OP may or may not require this particular feature; nothing has been said by him/her either way.

So I guess it is up to me to clarify this: I mentioned security as the most prominent feature of the desktop, but by no means this is the only feature this technology provides and is not the only reason why this would be used. I mentioned security as an example to back up a (small) set of possbile reasons. But there are other exploitable features. For example, I came across this feature when at the corporate level it was decided that maintaining a financial record of each PC was so important that productivity of the employee had to be stopped in order to get his/her attention into fixing the record by providing correct cost center codes for cost charging. The OP may have other reasons besides security to seek for such a thing.

Is the OP's reason valid enough? No idea. But I do give him/her the benefit of the doubt and just limit myself to say "hey, there is this thing called a desktop that you can use, just like UAC". Up to the OP to use it or not.

So summarizing: I mentioned security, not the OP. Did it just as an example. Not to be confused with the actual reasons driving the OP down this path.
Topic archived. No new replies allowed.