Author
Topic: GlassPrompt 1.1 (Read 12080 times)

GlassPrompt 1.0 This should be the first and last version as it's pretty simple.

The effect is the same as my PromptHere utility, which is to open a command prompt with a "blur behind" effect. The difference is this just opens to the current directory. To have it open to a directory other than where the program is located, make a shortcut and use the "Start in" field.

The reason I wrote this is because I started playing around with FreeBASIC compiler. I noticed the compiled executables were tiny. Even with an icon and file version resources in the .exe it comes in at only 23 KB. It's just a toy.

To get the blur effect the system must be either Vista or Windows Seven with Glass enabled. On XP you'll just get an ordinary command prompt but with "GlassPrompt" in the caption.

edit: I fixed a bug which caused orphaned hidden command prompts. The current download on my site has the fixed version. To be certain, right click GlassPrompt.exe and look in Properties, Details. The fixed version will show file version 1.0.0.1.

Or you can just look in task manager. If 2 cmd.exe instances are added in TM every time you run it, instead of one, it's the broken version.

GlassPrompt 1.1 Smoothed the application of the blur effect. Now sets prompt caption directly instead of using Windows Start command.

Now when the window becomes visible the blur is already applied. No more starting with black background, then changing color. Also by setting the caption directly using a WinAPI call, there's no longer a prompt launched just to use Windows Start command. Looks a lot nice coming up now.

Of course if you have XP it will just show the ordinary prompt. No sense running it unless you have Vista or later OS with Glass enabled.

Some guys have been messing with Blur Behind effect on a prompt for awhile on AutoIt3 forum. It uses DwmIsCompositionEnabled to check if Glass is enabled and DwmEnableBlurBehindWindow to enable the blur effect. Unfortunately it only looks good when the background is black. Which makes it work well with prompts as most people don't bother to change the background color and the text reverts to white.

If you just enable Glass or blur on a program window, all the controls are zapped and you can't read the text in buttons. That's why in my programs like Selector and ReOpen I just use the thick glass border. There's some stuff on Code Project how to draw text and stuff on glass but it's a royal pain.

Here's the functions in FreeBASIC. There may be neater ways to do it. I did these functions before I found all the WinAPI stuff included with the compiler. But it works.

It's pretty flexible and interesting. It has classes but I believe inheritance is not implemented. The libraries include lots of WinAPI stuff like ShellExecute, FindWindow etc..

It also has user defined types so creating a struct to make a WinAPI call that's not in the library is not difficult. Also some sort of operator overloading. I'm still new to it so resort to the online site for accurate info.

I had vs2008 Express with SP1 kicking around so I put vc++ on. It's been years so I thought time to scrape some of the rust off.

Starting with something wicked easy, doing Glass in vc++. It uses the same "trick" FreeBasic programmers use of compiling a console app as Win32 to avoid the command prompt flashing up when the program runs.

Is it the low size that surprises you? One thing that's happening there is you're dynamically linking against the VC runtime, so technically anyone using you're application needs to have, in this case, the Microsoft Visual C++ 2008 SP1 Redistributable Package (x86) installed. Of course I tend to believe that's a good thing and that everyone should dynamically link against the VC runtime, it would cut down on physical memory usage when running lots of apps all using the same runtime.

Or are you surprised at the large size? After all, with just a few API calls, there's no reason such an app need be over 4kb which is generally the minimum unless you do some fancy manual linking.

No, the FreeBasic is a front end for gcc. Actually is uses gas assembler, which is why the stuff comes out so small. I'm not fixated on small. I just wanted to produce some stand-alone exe and brush back up on c++. ahk and AutoIt3 are fine, but sometimes I just want to spit out some real machine code.

I haven't really messed around with vc++ since 6.0. So the vs2008 is new to me. Just for grins I changed the min platform setting to 5 and made a Hello World! messagebox app, just to see if it would run on xp. The glass program craps out as soon as it doesn't see dwmapi.dll since I didn't do the LoadLibrary bit as in the FreeBasic version. But the glass thing is useless on XP anyway.

I definitely didn't put any .NET 3.0 stuff on XP, so the fact that it did the messagebox bit tells me it's stand-alone .exe. I was just surprised MS compiler spit out something so small. Granted it just calls functions in dlls, but even so, I expected more bloat.

I hadn't realised FreeBasic compiled to native code, should have checked that up.

On an aside, a more elegant solution to LoadLibrary is Delay-Loaded DLLs. So once you've confirmed you're on Vista+ you can use the Dwm* functions freely. On XP the app will still run, so long as you don't call the unsupported functions.

btw the FreeBasic is a fun compiler for that reason. Small, tight exes. I just wish it had an out and out RAD gui tool instead of message loop and window proc code. The gui designers are all user-supplied volunteer efforts. Still, it is great for small utilities. A nice example of what can be done with gcc on Windows. It has a lot of header files similar to C type languages, to make API calls easier. Also has classes. Unfortunately does not implement inheritance though.

Updated GlassPrompt download. I reimplemented it using vc++. The executable is Glass.exe. Now it accepts a /c command line switch to force the prompt window to the center of the desktop work area. I just got tired of the thing opening at a random position.

There's no command line switch to change the starting directory but you can accomplish the same thing using a shortcut's Start In field as noted in the Readme.

My user account is in admin group anyway. So launching cmd.exe for me is an administrator command prompt. In fact if I don't change the caption to GlassPrompt, on my machine it says "Administrator: C:\Windows\system32\cmd.exe - cmd"

Feel free to post a snippet though. I'll post the latest c++ source I used if anyone wants to put them together. Guess I'm old school. I don't mess with all that UAC and sub user accounts. If I need to use a prophylactic I run whatever Sandboxed.

I've mentioned it before but the set up I liked in Windows was NT Server 4.0. If you made a user account in the System Operator's group, you could install programs, register .ocx etc.. but not delete system files. It was a happy medium I thought. A regular user account on Windows I don't consider worth the effort of creating. Windows Seven may have improved on it but I haven't bothered to check it out. One thing I hate is having to remember what flavor of Windows I'm booted into. That's why I use little utilities. To work the same on everything as much as possible.

btw the command prompt only comes out looking cool if the default black background is used. Unfortunately the Blur Behind effect looks like crap otherwise. I'm hoping Windows8 comes out with easy ways to draw on glass. Right now it's more complex than the rest of the program, at least for my small utils. I'm hoping it gets back to sanity soon. In c# at least the buttons will draw correctly if you do Application.SetCompatibleTextRenderingDefault(true);in Program.cs. That's the main reason I did IniEdit in c#. At least I wouldn't have to owner draw the buttons in the Glass.

edit: btw I also have a PromptHere utility that optionally uses a blurred prompt if Glass is enabled. It has a bit more utility as you can highlight one or more folders in Explorer, then hit the hotkey to open a prompt with each as current directory. But it has to sit in the tray. This app just launches the prompt and dies.

edit2: according to UAC entry in Wiki, there's now a "runas" verb for ShellExecute().

You could try it. I run with UAC off. I have no desire to change my settings for an experiment. Just running ShellExecute cmd.exe gest an admin prompt on my system. I haven't had any other feedback about people not being able to do what they want to do so... if it ain't broke..

btw it looks a lot better in Windows Seven than in Vista. Evidently there are some things in the composition engine 7 has that Vista doesn't. If you look carefully in Vista it's difficult to see the vertical scroll thumb. In Windows Seven it shows up easily. They must have improved the scrollbar draw when it's glass.