Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Want that Chrome Gone?
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HRI




PostPosted: Fri May 06, 2011 2:59 pm   Post subject: Want that Chrome Gone?

This is just something I wrote up quickly for my own use (which is why it's tailored to Google Chrome). What it does is hide the Google Chrome window, as well as the console window. Once hidden, you can look for a text file called "check.txt" in the folder with the application. Delete that to bring Google Chrome back and end the program.
Note: Unless you change this code, you must have whichever window of Google Chrome you want closed on a new tab page, because this finds it via the window title. Like I said before, I didn't put much time at all into it, but it still has its uses. Also, please note that this is Windows-oriented.

c++:

#define _WIN32_WINNT 0x0500 // allows use of GetConsoleWindow()
#include <windows.h> // windows functions
#include <cstdio> // used for freopen and fclose

HWND hwnd; // handle to console window
HWND chrome; // handle to a window with title "New Tab - Google Chrome", the default new tab text for GC

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) // program begins execution
{
    freopen ("check.txt", "w", stdout); // create text file in same directory
    fclose (stdout); // close output stream so you can delete it

    hwnd = GetConsoleWindow(); // get handle to console window
    ShowWindow (hwnd, SW_HIDE); // hide console window

    chrome = FindWindow (NULL, "New Tab - Google Chrome"); // get handle to chrome window
    ShowWindow (chrome, SW_HIDE); // hide chrome window

    while (1) // infinite loop
    {
        if (!(freopen ("check.txt", "r", stdin))) // if it can't open the text file (it's deleted)
        {
            ShowWindow (hwnd, SW_SHOW); // show console window
            ShowWindow (chrome, SW_SHOW); // show chrome window
            PostMessage (hwnd, WM_CLOSE, 0, 0); // quit program
        } // end if

        else // if it can read file
        {
            fclose (stdin); // close input stream
        } // end else
    } // end while
} // end main


Pretty self-explanatory with the comments. All of the stuff you've probably never seen before is Windows API stuff. There's a good starting tutorial on the Windows API at winprog.org/tutorial.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri May 06, 2011 3:02 pm   Post subject: RE:Want that Chrome Gone?

what exactly is the purpose of this? You say you created it for your own use, which implies that you're going to use it, which in turn implies that there is some reason to have a function like this. I don't see the purpose (hide a window until a text file is deleted?) so would you mind enlightening me?
Zren




PostPosted: Fri May 06, 2011 7:49 pm   Post subject: RE:Want that Chrome Gone?

It's probably a Get back to work! reminder. Methinks someone has a problem keeping on task.
ProgrammingFun




PostPosted: Sat May 07, 2011 8:24 am   Post subject: RE:Want that Chrome Gone?

http://download.cnet.com/Mr-Hyde/3000-2094_4-10521351.html
mirhagk




PostPosted: Sat May 07, 2011 1:21 pm   Post subject: RE:Want that Chrome Gone?

I used to have an awesome program that split up all your windows into two sections, and only one section would appear on the screen, or in the taskbar at a time, so you can switch between school/work related ones and your just for fun sites.
Zren




PostPosted: Sat May 07, 2011 7:15 pm   Post subject: RE:Want that Chrome Gone?

@Mirhagk: Dexpotp? It's a window's equivalent for virtual desktops.

Eg: http://imgur.com/xg951l&9AHnN&6rqqC
HRI




PostPosted: Sat May 07, 2011 7:45 pm   Post subject: RE:Want that Chrome Gone?

Actually, I know there is good software to have multiple desktops and whatnot, but being a programmer I like making things like this for fun. The actual point was actually not for that purpose exactly, but to make it look like I was working on my summative when I was home sick >.> To be honest, I couldn't find the handle again in a separate program if the first ended with the browser hidden.
train850




PostPosted: Tue Oct 11, 2011 9:27 am   Post subject: Re: RE:Want that Chrome Gone?

Insectoid @ May 6th 2011, 2:02 pm wrote:
what exactly is the purpose of this? You say you created it for your own use, which implies that you're going to use it, which in turn implies that there is some reason to have a function like this. I don't see the purpose (hide a window until a text file is deleted?) so would you mind enlightening me?


Seems like a safeguard against peepers at work. It would be nice to not have the boss interrupt your two girls and a cup while your out for coffee.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: