VS 2010 [RESOLVED] Allow no "activity" outside of a form.-VBForums
Results 1 to 24 of 24

Thread: [RESOLVED] Allow no "activity" outside of a form.

  1. #1

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Resolved [RESOLVED] Allow no "activity" outside of a form.

    I was wondering how you would go about making it so that, whenever you have a form open, or showing, that it won't allow any other clicks outside of the form content. Kind of like when a critical windows error shows up, and you can't do anything on your computer, until you press the "Ok" button to get rid of that popup message first.

    How would you do that with a form?

    Let's call it Form 1 and form 2 for example. I have form 1 as a default for when the application starts, but when I want form 2 to show, I want the user to have to deal with that form first before they can do anything else on their computer.

  2. #2
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Allow no "activity" outside of a form.

    what do you mean "have to deal with that form" ?

  3. #3
    New Member
    Join Date
    Jun 2011
    Posts
    6

    Re: Allow no "activity" outside of a form.

    you can set the form to always on top Me.TopMost = True then make your form the whole screen

  4. #4

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Allow no "activity" outside of a form.

    No, that seems a bit silly to me...


    I already have the topmost code on, but I want it so that the user can't take any other actions with the keyboard or mouse until that form is gone.

    Pretend I have a form with a button for example, which closes that form. When the form is showing, I want it so that the user can't do anything on the computer until that button is clicked to get rid of the form.

    Have you never gotten a critical error messagebox on your computer before? It's the exact same way. You try clicking anywhere outside of that messagebox, and you hear the ding as a windows sound, and you are unable to do anything until you get rid of that messagebox by pressing either Ok, or Cancel, or whatever else buttons there are for that messagebox. I want my form to be like that to ensure that data doesn't get changed while it's open. I'm not looking for any other suggestions.

  5. #5

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Allow no "activity" outside of a form.

    If I have to i'll just use something like this if no one else can answer, but i'm looking for the way of doing it without disabling or enabling things.

    vb Code:
    1. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Me.TopMost = True
    3.         FormMain.Enabled = False
    4.     End Sub
    5.  
    6.     Private Sub Form2_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
    7.         FormMain.Enabled = True

  6. #6
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Allow no "activity" outside of a form.

    your question is a bit confusing, i asked what did you mean "Deal with the Form" ?
    The you seem to answer your own question in post #4

    just place a message box and have the uiser make whatever corrections or action to the form you want

  7. #7

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Allow no "activity" outside of a form.

    what do you mean? I'm not using a message box at all for this form, i'm trying to get that same effect that I explained with the message box, only with a form instead. I don't know how much clearer I can make it, but I've tried my best at trying to go into detail about what I want.

    It happens when you get this error:


    I want my form itself to behave like an annoying critical error that doesn't let you do anything on your computer before you click "Ok"..

    And surely there's another method besides enabling and disabling the form.
    Last edited by AceInfinity; Jun 16th, 2011 at 07:21 PM.

  8. #8
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Allow no "activity" outside of a form.

    I know you dont have a message box anywhere, I suggested using a message box

    The way you are explaining it is you just want your form to freeze and user not be able to do anything until they "Deal with your form"

    You still havent explained what "deal with" means, how is the user going to know what to do if you dont provide feedback and if you want your whole form to beave like a mesaage box and just a beeping sound how are they going to do anything??

    Think about it

    User has form opened in project, now they need to do something before going onto anything else, how are they supposed to do anything else if they dont know what to do and the form is frozen

    Thats how I am understanding what you are asking, sorry if I am not getting you

    You should consider what does the user need to do?? you can easily prevent them from leaving the form until a certain thing or things are completed

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,268

    Re: Allow no "activity" outside of a form.

    I think you're misunderstanding billboy....

    the op is asking how to display a form that will BLOCK access to anything OUTSIDE THE FORM ... widnows, other apps, the taskbar, etc... UNTIL they deal with the form... whether it's enter some info, click a button, doesn't matter.

    Question I have is... why would you want to do this?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,545

    Re: Allow no "activity" outside of a form.

    Yes, just so i have it straight as well, you want your program to annoy the crap out of the user?

    The closest thing i can think of is showing a prompt the same way UAC does, which is creating a 2nd desktop environment, copying the background from the first desktop and displaying it on the 2nd then putting your form on the 2nd one. The background is unresponsive to clicks because it's fake.

    However, this is stupid and it's why everyone hates vista. If you want your 2nd form to have priority over the first form, that's easy. You show it modal with the first form as parent.

    optionally, you can run the mouse api to set a clipping region the same size as your window but if your program errors or something while all this is going on, you've essentially forced the user to reboot.

  11. #11

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Allow no "activity" outside of a form.

    never thought about that aspect of it, i'm fine with disabling the secondary form, just thought it would be nice to have something up there that would make them sure that they know the settings form is open. Otherwise you'll be running it in the background and not even notice it if you have lots of windows open. My application would be better if the settings weren't changes on the application itself while the settings form was open, but I can deal with that through the topmost property and a few enabled/disabled tweaks.

    Thanks guess the thread is solved now.

  12. #12
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Allow no "activity" outside of a form.

    Quote Originally Posted by techgnome View Post
    I think you're misunderstanding billboy....

    the op is asking how to display a form that will BLOCK access to anything OUTSIDE THE FORM ... widnows, other apps, the taskbar, etc... UNTIL they deal with the form... whether it's enter some info, click a button, doesn't matter.

    Question I have is... why would you want to do this?

    -tg
    Ya i kind of got that, but what i still dont get is what the heck is the user supposed to do if they dont know what needs to be done, its like they are locked in there not knowing what to do possibly??? unless i am still missing something

    And ditto on why do you want to do that to begin with....

  13. #13

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: [RESOLVED] Allow no "activity" outside of a form.

    You're still not getting it......

    I don't know how they would not know what to do if they have one window visible in the middle of the screen that stays topmost to all other windows, and is the only window that you can actually do anything in. The form itself should be straightforward enough as well, for what you're supposed to do. I'm not having a form that requires a puzzle to be solved for it to go away.

  14. #14
    New Member
    Join Date
    Apr 2017
    Posts
    1

    Talking Re: [RESOLVED] Allow no "activity" outside of a form.

    Quote Originally Posted by AceInfinity View Post
    You're still not getting it......

    I don't know how they would not know what to do if they have one window visible in the middle of the screen that stays topmost to all other windows, and is the only window that you can actually do anything in. The form itself should be straightforward enough as well, for what you're supposed to do. I'm not having a form that requires a puzzle to be solved for it to go away.
    Hi, I was looking for some code to do the same as you. Then, reading other websites I found this. The way you decide to show your form will mean different possibilities for the user:

    FormName.ShowDialog() 'It shows the form but doesn't allow the user to click outside the form

    FormName.Show() 'It shows the form but still allows the user to click outside the form and maybe click other forms which may still be visible.

    https://msdn.microsoft.com/es-es/lib...v=vs.110).aspx

  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,268

    Re: [RESOLVED] Allow no "activity" outside of a form.

    1) This is a 6 year-old thread.
    2) ShowDialog still wasn't the answer. What they wanted was to block ALL clicks.... IE, their dialog is the only thing active. No start menu, no desktop, etc...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,545

    Re: [RESOLVED] Allow no "activity" outside of a form.

    Quote Originally Posted by techgnome View Post
    1) This is a 6 year-old thread.
    2) ShowDialog still wasn't the answer. What they wanted was to block ALL clicks.... IE, their dialog is the only thing active. No start menu, no desktop, etc...


    -tg
    that's true but the OP wanted that because he was afraid the dialog he was creating would be lost behind another window. ShowDialog wouldn't allow that normally but if it did happen, the icon would blink in the task bar.

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,268

    Re: [RESOLVED] Allow no "activity" outside of a form.

    Quote Originally Posted by Lord Orwell View Post
    that's true but the OP wanted that because he was afraid the dialog he was creating would be lost behind another window. ShowDialog wouldn't allow that normally but if it did happen, the icon would blink in the task bar.
    Not quite:
    I want the user to have to deal with that form first before they can do anything else on their computer.
    and is the only window that you can actually do anything in.
    ShowDialog still won't block other clicks like the start menu... or opening a webbrowser. It would only affect the application.

    But, it is a 6-year old thread, so there's problably no point in beating it further. If they haven't gotten their answer by now, odds are, they aren't. Or don't care.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18
    Addicted Member Slabs1960's Avatar
    Join Date
    Mar 2017
    Location
    Oranjemund, Namibia
    Posts
    148

    Re: [RESOLVED] Allow no "activity" outside of a form.

    I think he wants to show the form in Modal mode.
    Program design today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
    -- Rich Cook

  19. #19
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,021

    Re: [RESOLVED] Allow no "activity" outside of a form.

    You can make a form a Fixed Dialog, by choose the border style as such then chnaging it when you are ready. I see this is marked as resolved but thought I would pitch in anyways.

    When you make it a fixed dialog it won't let you click anything but that form to complete a operation. Except of course unless you hit the "X"

    I have never had it do anything but what I describe using the(I think its the) Form.Borderstyle property.
    Last edited by jdc20181; Apr 10th, 2017 at 11:16 AM.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  20. #20
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,112

    Re: [RESOLVED] Allow no "activity" outside of a form.

    The thread is six years old. Let it die already.
    My usual boring signature: Nothing

  21. #21
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,161

    Re: [RESOLVED] Allow no "activity" outside of a form.

    It's just not a good idea. In this case "it's" refers to both what this thread wants to accomplish and replying further.

    Imagine if this is possible, that you can create a dialog such that all input must go specifically to it. Now imagine if two applications decide to do it at the same time. Who wins? This is why I think you can't do this except via some methods you really shouldn't pursue.

    In Vista onwards, we do see Windows doing it for things like the UAC prompts. But that's very special: what's really happening is you get switched to a super-secure desktop for the Admin user, and technically that desktop has its own message loop. Only the OS is allowed to talk to that message loop, so you can't SendKeys() to it or do something else nefarious. The way Vista/7 made it look like a dialog was to take a screenshot, alpha blend a screen over it, then set that screenshot to be the background of the special desktop. This was particularly noticeable on a system with slower graphics cards, on one of my work machines a UAC prompt could take 10+ seconds to render!

    So you could sort of accomplish the same thing via similar means: first display a topmost full-screen window that has an image to simulate an overlay, then have it display the dialog. This is a pain in the butt for the user, especially when it starts to fight with other windows that think they should be topmost. I wouldn't do it.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  22. #22
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,545

    Re: [RESOLVED] Allow no "activity" outside of a form.

    Quote Originally Posted by Shaggy Hiker View Post
    The thread is six years old. Let it die already.
    the point of these threads is to be there for the next person to get their answer. I don't see how the age of it matters. And yes i know he said "prevent all use of computer but my app" but he clarified what was necessary in post 11.

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,112

    Re: [RESOLVED] Allow no "activity" outside of a form.

    That's a reasonable point, except that I'm not sure that most of these posts really add anything, with the exception of what jdc posted. It's mostly a discussion about what the OP wanted, and the OP isn't around to talk about it. I suppose that the post that resurrected the thread does add a suggested solution, but it's really a discussion of modal vs non-modal, which isn't just really basic, but doesn't seem to address the question by the OP, who wanted a much greater restriction. However, if people want to discuss what the OP wanted, that's fine, they just have to know what the OP wanted, and the OP has moved on. Perhaps they are still subscribed to the thread, in which case they're now getting hammered by emails, which they may not even be able to deal with if they didn't get their password changed right in the forced change of a year, or so, back. That would be a hoot. We'd have turned VBF into an inadvertent spam-bot.
    My usual boring signature: Nothing

  24. #24
    New Member
    Join Date
    Apr 2017
    Posts
    10

    Wink Re: [RESOLVED] Allow no "activity" outside of a form.

    I know this thread is old, I did read the recent replies to it... Seems like no one has been able to provide a real solution for the original poster, so for anyone who may be reading this thread and needing a solution, I can give you one. Whether the solution is "ethical" or not is another matter, and unless you know what you are doing it is probably not a good idea for you to bother taking the path to using the method I am about to suggest, although it will do what was originally asked (prevent access to using other running programs until content has been dealt with on your own).

    There is a DLL in Windows called ntdll.dll (some prefer it in capitals as NTDLL.DLL), and there are Native API functions exported by this DLL. The DLL is very important since it exports incredibly important (and also critical) functions used throughout the Windows OS; these Native API functions are called when their Win32 equivalents are called - of course if you know what you are doing then you can call the NTAPI functions yourself to re-create the functionality you need and avoid using the actual Win32 API functions in the first place. NTDLL.DLL is essentially a system-call wrapper, and while it is difficult for me to explain what a system call is to .NET developers, let's just say that it allows code execution to be taken over to the Windows Kernel (where the heart of the Operating System is executed) where the real functions are called (there is something called the System Service Dispatch Table which contains pointer addresses to the NTAPI functions which are exported by ntoskrnl.exe - some functions are not exported and therefore their addresses have to be manually found - when code execution is moved to the kernel via SYSENTER then the Windows Kernel will obtain the pointer address for the targeted function and will move execution to the function at that address (this is also how rootkits subvert the Windows Kernel on 32-bit systems where PatchGuard and Kernel Patch Protection are not present, they manipulate the pointer address in the SSDT to the pointer address of their own function so when the NTAPI function's are called, the malicious functions are actually called first instead)).

    There is an undocumented function which ntoskrnl.exe does not actually export (therefore you cannot call this function from kernel-mode without manually finding the address) called NtSuspendProcess. The function takes in one parameter which is a handle to the target process you wish to suspend, what you will need to do is simply enumerate through all the processes which are currently running, open a handle to them, and then call NtSuspendProcess while passing in the handle of the current process in the list (do it in a loop for example, but make sure to filter out your own process and also other critical Windows processes such as csrss.exe, winlogon.exe, explorer.exe (actually you can suspend that one but it's not necessarily the best idea to do so), lsass.exe, etc.

    The truth is that you cannot actually "suspend" a process, but you suspend the threads within the process. A process is like the the human skull, it's a container which is holding other components together (such as the process' threads), in the same sense that the human skull is protecting the brain (or the outside of our body is protecting our internal organs such as our heart and lungs). The threads within the process are responsible for code execution, and every process has a main thread which is started before all the other ones which may be then created and started. When you "suspend" a process, you have suspended the threads within the process so they are unable to execute any more code, the threads will be suspended from performing any actions in the same sense that a lake is blocking off the water beneath it from rising above the ice it is frozen by. Therefore, alternatively you can enumerate through all the threads within the target process and then just call SuspendThread (which will call NtSuspendThread - another undocumented function, but there is no need to use this function unless you wish to suspend specific threads within a target process and not all of them, since using this function to suspend all the threads would just be re-implementing functionality that NtSuspendProcess will already perform for you).

    Once you are ready you can resume the processes you suspended with another undocumented function (also exported by ntdll.dll) called NtResumeProcess.

    Hopefully this post will be found educational to someone out there, and of course anyone may feel free to send me a PM to ask questions on something related to the Windows Internals (just as long as it is for good and not bad - I can even code a basic example of using NtSuspendProcess/NtResumeProcess via Platform Invokation for this forum if anyone is interested, could be useful for a number of things including a lock-down secondary password system or even a home anti-malware project).

    Good luck!

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.