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
- Download the powermini.zip file (Demo project above). This contains the VC6 project and some extra resources files. Then extract to desired folder.
- Locate the PowerMini.exe file in the Release subfolder and create a shortcut to the desktop (right-click > Send to > Desktop)
- 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"
#include <windows.h>
#include <windowsx.h>
#define M_MINIMIZE
#undef M_RESTORE
#undef M_CLOSE
HICON m_hIcon;
CString str_Browser;
CString GetRegKey(HKEY m_Folder,
CString str_Path, CString str_Name)
{
CString str_KeyOut;
extern const char *MyKeys;
#define MY_BUFSIZE2 120
HKEY hKey1;
TCHAR szData[MY_BUFSIZE2];
DWORD dwBufLen2 = MY_BUFSIZE2;
LONG lRet1;
RegOpenKeyEx(m_Folder,
TEXT(str_Path),
0,
KEY_QUERY_VALUE,
&hKey1);
lRet1 = RegQueryValueEx(hKey1,
TEXT(str_Name),
NULL,
NULL,
(LPBYTE)szData,
&dwBufLen2);
str_KeyOut = szData;
RegCloseKey(hKey1);
return str_KeyOut;
}
CString GetHomePage()
{
extern CString str_Browser;
CString str_BrowserName;
CString str_HomePageOut;
DWORD dwBufLen2 = MY_BUFSIZE2;
str_BrowserName =
GetRegKey(HKEY_CLASSES_ROOT,"htmlfile\\shell","");
if (str_BrowserName != "")
{
if(str_BrowserName == "CrazyBrowser")
{
str_Browser = GetRegKey(HKEY_CLASSES_ROOT,
"htmlfile\\shell\\CrazyBrowser\\Command","");
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","");
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);
int_length = str_Browser.GetLength();
int_flagstart = str_Browser.ReverseFind('\\');
int_chrtoDelete = int_length - int_flagstart;
int_chrtoDelete = int_length - int_chrtoDelete;
str_Browser.Delete(1, int_chrtoDelete);
RegCloseKey(hKey1);
if(str_Browser == "\"Netscp.exe\"")
{
str_HomePageOut = GetRegKey(HKEY_CURRENT_USER,
"Software\\Netscape\\Netscape Navigator\\Main",
"Home Page");
}
else if(str_Browser == "\"iexplore.exe\"" || "Crazy Browser.exe")
{
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");
}
}
return str_HomePageOut;
}
The 2nd function:
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;
}
The WinMain
:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
extern CString GetHomePage();
extern CString str_Browser;
extern HICON m_hIcon;
CWnd m_hWnd;
m_hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
ANIMATIONINFO anim;
anim.cbSize=sizeof(anim);
anim.iMinAnimate=false;
SystemParametersInfo(SPI_SETANIMATION,0,&anim,0);
EnumWindows(EnumWindowsProc,0);
anim.iMinAnimate=true;
SystemParametersInfo(SPI_SETANIMATION,0,&anim,0);
CString str_Homepage = GetHomePage();
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.