Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

PowerMini v1.2 - add a new minimizing feature with your browser.

0.00/5 (No votes)
16 Jan 2003 2  
Opens your default browser while minimizing all other windows. A very simple Win32 application.

Sample Image - powermini.jpg

Introduction

This idea mainly came to me while working on my old Fujitsu 266 Mhz, running Windows 2000, with only 64MB of RAM. Internet browsing was painfully slow. When I had multiple windows open and maximized/restored down, it was most excruciating! Yes, I could just click on "Show Desktop", then click on my IE shortcut, but that's 2 clicks man!! Come on! I wanted an option on Internet Explorer to minimize all other windows, then open my new instance of IE. This should be an option, if you ask me, but is not. So forth was born PowerMini!

Introduction cont'd

This article does not have great coding content but has potential to become a great CP community application or at least, influence browser developers to include minimizing other windows when starting, as an option. Another motivating factor for me to make this article: I am tired of seeing "Articles Submitted 0" in my profile. I have published one article on CodeGuru though.

I would also like to disclaim, that none of the code was written by me. The meat of the app was by Tone Skoda and is noted in the source. It took me a long time to find a function to handle the minimizing of windows. Now I kind of threw the application together and have tried to comment it to the best I could. I know there are improvements that could be made to the code, that I am sure people will point out. This will be good. It will help me become a better programmer, since I am a stand alone, self-taught programmer, big thanks to CP! This function definitely needs improving! I tried searching around to see how I could get my hands on getting the default browser, but no luck, and scrapped investing anymore time into it. Feel free to improve this part! (Started improving in v1.1).

Vision

I think it would be great if others would add what they would like to see in this application, instead of asking me to write the code. For example, someone gets an idea, that someone writes the code, that person posts a discussion message with the added code, I will update the source and application version in the article.

Setting up PowerMini for Use

You have two options. Download the installation only file, above. This installs it for you, with no source code included.

OR

  1. Download the powermini.zip file (Demo project above). This contains the VC6 project and some extra resources files. Then extract to desired folder.
  2. Locate the PowerMini.exe file in the Release subfolder and create a shortcut to the desktop (right-click > Send to > Desktop)
  3. Drag and Drop the PowerMini shortcut to your QuickLaunch Toolbar. NOTE: You may change the shortcut icon to any of the 5 different icons included in the .exe. Feel free to design and add your own, they will probably be better than mine :)

I personally have the regular IE shortcut in my QuickLaunch toolbar with PowerMini right next to it.

The Code Version 1.2

This 1.2 update was needed after trying to add Crazy Browser to the list of supported browsers. I think Crazy Browser sets itself as the default browser correctly (or incorrectly), as mentioned I have not found any well documented information about how Windows finds the default web browser. Anyway, Crazy Browser when setting itself as the default browser, writes a registry key to HKEY_CLASSES_ROOT\htmlfile\shell in the registry and NOT to HKEY_CLASSES_ROOT\htmlfile\shell\open\command! Which kind of creates some problems, on my Windows 98se machine at work (not on my WinXP laptop though?!?). If Crazy Browser is your default browser and you use an internet shortcut, it opens whatever is in the HKEY_CLASSES_ROOT\htmlfile\shell\open\command path instead of Crazy Browser, maybe this is why it is called "Crazy", sorry couldn't resist. The PowerMini v1.2 now has 2 supporting functions instead of 1.

  • CString GetRegKey(HKEY m_Folder, CString str_Path, CString str_Name) returns any given registry REG_SZ data.
  • CString GetHomePage() returns the users' homepage URL.
#include "stdafx.h"

#include "resource.h"

////by Tone Skoda 

#include <windows.h>

#include <windowsx.h>


#define M_MINIMIZE  //minimize all desktop windows

#undef M_RESTORE   //restore all desktop windows

#undef M_CLOSE     //close all desktop windows

////End of code by Tone Skoda 


//Globals

HICON    m_hIcon;
CString str_Browser;
  //holds "iexplore.exe", "Netscp.exe", or 

  //"yourpath:\Crazy Browser\Crazy Browser.exe" for now

  //Must get filename so ShellExecute may 

  //open multiple instances.

//end of Globals


//Helper Function to return REG_SZ data

CString GetRegKey(HKEY m_Folder, 
      CString str_Path, CString str_Name)
{
    CString str_KeyOut;

extern const char *MyKeys;
    #define MY_BUFSIZE2 120 // Arbitrary initial value.

    HKEY hKey1;
    TCHAR szData[MY_BUFSIZE2];
    DWORD dwBufLen2 = MY_BUFSIZE2;
    LONG lRet1;

//Find Registry Data

    RegOpenKeyEx(m_Folder,
        TEXT(str_Path),
        0,
        KEY_QUERY_VALUE,
        &hKey1);
          lRet1 = RegQueryValueEx(hKey1,
                    TEXT(str_Name),
                    NULL,
                    NULL,
                    (LPBYTE)szData,
                    &dwBufLen2);
        //Turn TCHAR into CString

       str_KeyOut = szData;

       RegCloseKey(hKey1);

    return str_KeyOut;
}


CString GetHomePage()
{
    extern CString str_Browser;
    CString str_BrowserName;
    CString str_HomePageOut;
    DWORD dwBufLen2 = MY_BUFSIZE2;
    
    //See if Default Browser's Name is 

    //written and Assign to local var

    str_BrowserName = 
      GetRegKey(HKEY_CLASSES_ROOT,"htmlfile\\shell","");

    //if there is a value here navigate to corresponding regfolder

    if (str_BrowserName != "")
    {
        if(str_BrowserName == "CrazyBrowser")
        {
            str_Browser = GetRegKey(HKEY_CLASSES_ROOT,
              "htmlfile\\shell\\CrazyBrowser\\Command","");
            //Remove it's flag

            str_Browser.Replace(" \"%1\"", "");    
        }
        else if(str_Browser != "\"iexplore.exe\"" || "\"Netscp.exe\"")
        {
            AfxMessageBox("Sorry, Your default browser is 
                not IE or Netscape.\r\
                Please email me your browser's registry homepage 
                key so I may update this program and source.\r\
                powermini@savemall.net");
        }
    }
    else
    {
        str_Browser = GetRegKey(HKEY_CLASSES_ROOT,
            "htmlfile\\shell\\open\\command","");

        //Remove any flags on end

        int int_length, int_flagstart, int_chrtoDelete;
        int_length = str_Browser.GetLength();
        int_flagstart = str_Browser.Find(" -");
        int_chrtoDelete = int_length - int_flagstart;
        str_Browser.Delete(int_flagstart, int_chrtoDelete);

        //we need to get just the filename

        //recount length

        int_length = str_Browser.GetLength();
        //find pos of "\" before file name

        int_flagstart = str_Browser.ReverseFind('\\');
        //get length of filename

        int_chrtoDelete = int_length - int_flagstart;
        //get length of char to delete

        int_chrtoDelete = int_length - int_chrtoDelete;
        //start deleting after the first "

        str_Browser.Delete(1, int_chrtoDelete);
        RegCloseKey(hKey1);

        //Now we know the Default Browser, Lets get it's Homepage

        if(str_Browser == "\"Netscp.exe\"")
        {
            //Get Netscape's homepage reg entry

            str_HomePageOut = GetRegKey(HKEY_CURRENT_USER,
               "Software\\Netscape\\Netscape Navigator\\Main",
               "Home Page");
        }
        else if(str_Browser == "\"iexplore.exe\"" || "Crazy Browser.exe")
        {
            //Get IE's homepage reg entry

            str_HomePageOut = GetRegKey(HKEY_CURRENT_USER,
              "Software\\Microsoft\\Internet Explorer\\Main", 
              "Start Page");
        }
        else if(str_Browser != "\"iexplore.exe\"" || "\"Netscp.exe\"")
        {
            AfxMessageBox("Sorry, Your default browser 
                is not IE or Netscape.\r<br>Please email 
                me your browser's registry homepage key 
                so I may update this program and source.\r
                <br>powermini@savemall.net");
        }

        //I don't have any other the other Browser's 

        //installed on my system, so I need help getting

        //the Registry keys


    }//end of else

    return str_HomePageOut;
}

The 2nd function:

////by Tone Skoda 

BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam)
{
    long style;

    if(IsWindowVisible(hwnd))
    {
        style=GetWindowLong(hwnd,GWL_STYLE);
        if(style & WS_OVERLAPPEDWINDOW &&
            (style & WS_POPUP)== false)
        {
#ifdef M_MINIMIZE
            if( IsIconic(hwnd) == false )
            {
                ShowWindow(hwnd,SW_SHOWMINIMIZED);
            }
#endif
#ifdef M_RESTORE
            if( IsIconic(hwnd) == true )
            {
                ShowWindow(hwnd,SW_RESTORE);
            }
#endif
#ifdef M_CLOSE
            PostMessage(hwnd,WM_CLOSE,0,0);
#endif
        }
    }
    
    return true;
}
////End of code by Tone Skoda

The WinMain:

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    //call external var

    
    extern CString GetHomePage();
    extern CString str_Browser;
    extern HICON m_hIcon;
    
    //Assign Icon with the .exe

    CWnd m_hWnd;
    m_hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

////by Tone Skoda 

    ANIMATIONINFO anim;
    anim.cbSize=sizeof(anim);
    
    //turn off minimize/restore animations

    anim.iMinAnimate=false;
    SystemParametersInfo(SPI_SETANIMATION,0,&anim,0);
    EnumWindows(EnumWindowsProc,0);

    //turn on minimize/restore animations

    anim.iMinAnimate=true;
    SystemParametersInfo(SPI_SETANIMATION,0,&anim,0);
////End of code by Tone Skoda 


    //fill the url to local var

    CString str_Homepage = GetHomePage();

    //open the browser

    ShellExecute(m_hWnd, "open", str_Browser, 
         str_Homepage, NULL, SW_SHOWDEFAULT);

    return true;
}

Points of Interest

I was surprised not to find any existing code on the major coding sites about how to minimize and maximize open windows. Maybe because it is common knowledge, but not to this wanna-be programmer.

Known Issues/Limits

  • Only looks for Internet Explorer and Netscape homepages (only b/c they are the only ones I have installed). I will update as I receive more info on other browsers (this info might be good/useful to have documented in one place anyway. I tried searching the net for a page that has info on the registry keys for browsers and their homepages, but no such site exists).
  • Does not fully minimize restored windows (it mini's them, but not fully).
  • "It's bad for people trying to learn from your code." see .S.Rod. 15:16 4 Jan '03 post. Sorry you "Professionals", I'm still learning
  • 2 unresolved externals error - Debug ONLY.
  • VC7 build errors, better off just creating a new project and pasting code, and importing icons.

Desired Add-ons

  • An Options popup menu if user right-clicks on shortcut or PowerMini.exe (like IE's) (I tried doing this feature myself but found myself investing too much time and not getting answers to my stumbling).
  • Cooler icons in the build, so you have plenty of options to choose from.
  • Anything else you can think of.

History

Article posted 1/4/03 12:10am PT

  • 1/4/03 11:35am PT: Removed the setup.exe from powermini_src.zip. Oops, wonder why it was so big.
  • 1/4/03 1:20pm PT: Improved GetHomePage() by getting actual default browser instead of guessing.
  • 1/4/03 1:20pm PT: Posted v1.1 src and install.
  • 1/17/03 8:31pm PT: Posted v1.2 src and install. Added support for Crazy Browser. Improved some functions.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here