[Help][C++]Freeze doesn't work! menu

User Tag List

Results 1 to 7 of 7
  1. #1
    Timzorize's Avatar Member
    Reputation
    9
    Join Date
    May 2008
    Posts
    206
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    [Help][C++]Freeze doesn't work!

    Hi, I just tested how to block the computer by doing this:


    Code:
    #include <windows.h>
    
    int main(){
        FreeConsole();
        while(1){
                 BlockInput(true);
                 }
    }
    But why doesn't it work?




    One more thing, why does the cmd box disappear when I've entered for example 3 and 7?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() 
    
    {   
        int tal1;
        int tal2;
        int summa;
        
        cout << "Skriv in ett tal: ";
        cin >> tal1;
        cout << "Skriv in ett tal till: ";
        cin >> tal2;
        
        summa = tal1 + tal2;
        
        cout << "Det blir: " << summa;
        
    
        return 0;
        system("PAUSE");
     
    }
    When its going to write out the summa then the window just disappear. (Poping down)

    Last edited by Timzorize; 02-03-2009 at 02:42 PM.

    [Help][C++]Freeze doesn't work!
  2. #2
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any code after the return statement can't get executed. Also, BlockInput works fine, didn't try it with the FreeConsole( ) function though.

  3. #3
    Timzorize's Avatar Member
    Reputation
    9
    Join Date
    May 2008
    Posts
    206
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So, will you help me to find out the problem on the first code?

  4. #4
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My knowledge is kind of limited about such functions.

    #include <iostream>
    #include <windows.h>
    using namespace std;

    int main()
    {
    FreeConsole( );
    cin.get();
    return 0;
    }

    The FreeConsole() exits the application in this case, so your BlockInput function is never reached. Guess you'll need another way to hide your console.

  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your first example, I have no idea what you're trying to achieve.

    First off, don't use "while(1)", it's considered poor form. A better approach for 'infinite' loops is "for(;". Second, that loop will saturate the CPU because it never gives up any CPU time (google "Sleep"). Third, why the **** are you repeatedly calling BlockInput? That's just so terrible I don't even know how to put it into words. I assume your FreeConsole call is to hide the console? I guess you think it makes you "leet" to call BlockInput and hide the console, right? Well, you're obivously a retard but I'll point you in the right direction anyway. Google ShowWindow, you can use it to hide your console.

    Second example. You're calling 'return 0' before "system("PAUSE")". Think about that for a second. If you return from a function any code past that point will NEVER be reached. Also, never never never use 'system("pause")', EVER! Okay? Seriously. The console disappears because the system destroys windows automatically when a process terminates, you need to do something to keep the window open. Just request some dummy input that gets discarded.

    Lastly. Don't declare all your variables at the top of a function, declare as close as you can to the point of initialization. And if at all possible declare and initialize in the same statement.


  6. #6
    Timzorize's Avatar Member
    Reputation
    9
    Join Date
    May 2008
    Posts
    206
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    In your first example, I have no idea what you're trying to achieve.

    First off, don't use "while(1)", it's considered poor form. A better approach for 'infinite' loops is "for(;". Second, that loop will saturate the CPU because it never gives up any CPU time (google "Sleep"). Third, why the **** are you repeatedly calling BlockInput? That's just so terrible I don't even know how to put it into words. I assume your FreeConsole call is to hide the console? I guess you think it makes you "leet" to call BlockInput and hide the console, right? Well, you're obivously a retard but I'll point you in the right direction anyway. Google ShowWindow, you can use it to hide your console.

    Second example. You're calling 'return 0' before "system("PAUSE")". Think about that for a second. If you return from a function any code past that point will NEVER be reached. Also, never never never use 'system("pause")', EVER! Okay? Seriously. The console disappears because the system destroys windows automatically when a process terminates, you need to do something to keep the window open. Just request some dummy input that gets discarded.

    Lastly. Don't declare all your variables at the top of a function, declare as close as you can to the point of initialization. And if at all possible declare and initialize in the same statement.


    In the first I'm trying to freeze the computer, to lock it.

    Okay, what should I use instead of system("PAUSE") if I want the cmd box to stay and not disappear after 0.1 seconds?

  7. #7
    camicio's Avatar Banned
    Reputation
    6
    Join Date
    Feb 2009
    Posts
    98
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He's saying to use a getchar(); or something.

    Here's why you shouldn't use system("pause");
    system("Pause") - Google Search
    Last edited by camicio; 02-04-2009 at 10:13 PM.

Similar Threads

  1. [Lua Script] Can you help me why this doesn't work?
    By LlamaFridge in forum WoW EMU Questions & Requests
    Replies: 1
    Last Post: 08-24-2010, 03:18 PM
  2. [Help] One part of my lua script doesn't work correctly
    By dude891 in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 06-07-2008, 09:17 AM
  3. [Help] Trainer's doesn't work..
    By chanceless in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 04-24-2008, 01:45 PM
  4. Gold to Karazhan doesn't work,help please
    By Raijin in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 10-10-2006, 07:40 PM
All times are GMT -5. The time now is 03:54 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search