Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 06:24:38 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: GlassPrompt 1.1  (Read 9872 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
GlassPrompt 1.1
« on: July 19, 2010, 04:50:12 PM »
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.

You can download here:

http://www.favessoft.com/downloads.html

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. :)



« Last Edit: July 25, 2010, 02:16:34 PM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #1 on: July 25, 2010, 02:19:38 PM »
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.

parkint

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 119
  • It's bad luck to be superstitious
    • View Profile
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #2 on: July 25, 2010, 02:23:34 PM »
Sweet (little) application.
Thanks for sharing!

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #3 on: July 25, 2010, 02:33:06 PM »
That's kinda cute, how does it work? I assume it's some new Vista+ API that has to do with dwm? :)
- carpe noctem

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #4 on: July 25, 2010, 04:43:32 PM »
That's kinda cute, how does it work? I assume it's some new Vista+ API that has to do with dwm? :)

Yes, it's OSMajor 6.0 minimum.

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. :)


'' MilesAhead.bas - reusable function library for Windows
#include once "windows.bi"
#Include once "vbcompat.bi"
#include once "win/shellapi.bi"

'returns non 0 if Glass enabled on system
Function GlassEnabled() As Integer
  
  Dim As HMODULE hModule
  hModule = LoadLibrary( "dwmapi.dll" )
  If hModule = 0 Then Return 0
  
  Dim DwmIsCompositionEnabled As Function(pfEnabled As Integer Ptr) As HRESULT  
  Dim enabled As Integer = 0
  
  DwmIsCompositionEnabled = GetProcAddress(hModule,"DwmIsCompositionEnabled")
  If DwmIsCompositionEnabled = 0 Then
    FreeLibrary(hModule)
    Return 0
  End If
  
  DwmIsCompositionEnabled(@enabled)
  FreeLibrary(hModule)
  Return enabled
End Function

Function EnableBlurBehind( hw As hwnd ) As Integer
  If GlassEnabled() = 0 Then Return 0
  Type BlurStruct
    dwFlags As DWORD
    fEnable As BOOL
    hRgnBlur As HRGN
    fTransitionOnMaximized As BOOL
  End Type
  
  Dim bStruct As BlurStruct
  bStruct.dwFlags = 1
  bStruct.fEnable = 1
  bStruct.hRgnBlur = Cast(HRGN,hw)
  bStruct.fTransitionOnMaximized = Cast(BOOL,1)
  
  Dim As HMODULE hModule
  hModule = LoadLibrary( "dwmapi.dll" )
  If hModule = 0 Then Return 0
  Dim DwmEnableBlurBehindWindow As Function(hWnd As HWND, bs As BlurStruct Ptr) As HRESULT
  DwmEnableBlurBehindWindow = GetProcAddress(hModule,"DwmEnableBlurBehindWindow")
  If DwmEnableBlurBehindWindow = 0 Then
    FreeLibrary(hModule)
    Return 0
  End If
  Dim As HRESULT result = 0
  result = DwmEnableBlurBehindWindow(Cast(hwnd,hw),@bStruct)
  FreeLibrary(hModule)
  If result = 0 Then
    Return 1
  Else
    Return 0
  End If
End Function


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #5 on: July 28, 2010, 01:03:07 AM »
If anyone is tempted to play around with FreeBasic, I posted the v. 1.1 source code for GlassPrompt on the forum:

http://www.freebasic...iewtopic.php?t=16107

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. :)


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #6 on: September 04, 2010, 02:42:52 PM »
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.

#include "stdafx.h"
#include <windows.h>
#include <dwmapi.h>
#include <shellapi.h>

BOOL VistaOrHigher()
{
    return((LOBYTE(LOWORD(GetVersion()))) >= 6);
}


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    BOOL isEnabled = FALSE;

    if(! VistaOrHigher())
      return 1;
    DwmIsCompositionEnabled(&isEnabled);
    if(! isEnabled)
      return 1;
    if((int)ShellExecute(0,L"open",L"cmd.exe",0,0,SW_HIDE) < 33)
      return 1;
    Sleep(50);
    HWND h = FindWindow(L"ConsoleWindowClass",0);
    if(! h)
      return 1;
    DWM_BLURBEHIND bb = {0};
    bb.dwFlags = 1;
    bb.fEnable = TRUE;
    bb.hRgnBlur = (HRGN)h;
    bb.fTransitionOnMaximized = TRUE;
    DwmEnableBlurBehindWindow(h,&bb);
    SetWindowText(h,L"GlassPrompt");
    ShowWindow(h,SW_SHOWNORMAL);
    SetForegroundWindow(h);
    return 0;
}

edit: Suprised me a bit.  Compiled as stand-alone .exe with a low res icon and version info, only 17KB.

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #7 on: September 04, 2010, 03:16:03 PM »
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.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #8 on: September 04, 2010, 04:14:38 PM »
FreeBasic does the same program in about 9KB if you don't use resources, such as icon, version info etc..

This app should be stand-alone .exe and came in about the same, until I added an icon and version info. It's not managed code.

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #9 on: September 04, 2010, 04:37:25 PM »
Ah I see, kinda impressive for FreeBasic assuming that 9kb includes the interpreter.

If should you want small size and standalone-ness look into using a smaller custom CRT, for example Tiny C Runtime Library.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #10 on: September 04, 2010, 05:13:59 PM »
Ah I see, kinda impressive for FreeBasic assuming that 9kb includes the interpreter.

If should you want small size and standalone-ness look into using a smaller custom CRT, for example Tiny C Runtime Library.

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. :)


« Last Edit: September 04, 2010, 05:16:10 PM by MilesAhead »

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #11 on: September 04, 2010, 06:22:16 PM »
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.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #12 on: September 04, 2010, 07:42:55 PM »
Yeah, I was looking at that.  Didn't see the library that was supposed to be in the link list for automatic handling, on my system.  Are you sure the feature is in Express editions of vs2008?

edit: nevermind.  Got it.  Must have been looking at the page for 2005 where you had to add it manually.  Seems good. I'll know next time I boot XP and try it.
« Last Edit: September 04, 2010, 08:14:54 PM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #13 on: September 04, 2010, 07:45:42 PM »
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.


« Last Edit: September 04, 2010, 08:16:21 PM by MilesAhead »

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #14 on: September 05, 2010, 04:07:03 AM »
If you want small C++ exes, check out http://ibsensoftware.com/download.html - Jibz recently upgraded WCRT to have VS2010 support :)
- carpe noctem

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #15 on: September 05, 2010, 02:20:44 PM »
Thanks for the info. :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #16 on: September 09, 2010, 04:37:24 PM »
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.

Enjoy.


« Last Edit: September 09, 2010, 04:40:05 PM by MilesAhead »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #17 on: September 09, 2010, 06:28:20 PM »
A transparent Command Prompt - I have no idea what to do with it - But it's just to cool to not find a use for.

Now here's a question: can it launch a transparent administrator command prompt? Seems like I fought with something like that awhile back - I'll send you the code I ended up with if you like.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #18 on: September 09, 2010, 08:08:01 PM »
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().
« Last Edit: September 09, 2010, 08:32:07 PM by MilesAhead »

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #19 on: September 10, 2010, 10:13:20 AM »
If you start GlassPrompt elevated, won't it's automatically start the cmd.exe process with admin privs as well?
- carpe noctem

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #20 on: September 15, 2010, 04:35:33 PM »
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..


« Last Edit: September 15, 2010, 04:39:02 PM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #21 on: September 15, 2010, 04:37:14 PM »
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.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,285
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #22 on: September 17, 2010, 06:54:33 PM »
If you want small C++ exes, check out http://ibsensoftware.com/download.html - Jibz recently upgraded WCRT to have VS2010 support :)

btw, I tried => operator once in c# and was hooked. So I had to install vc++ 2010 Express. Works with the ResEdit freebie:

http://www.resedit.net/

I reimplemented an old error display utility to use an edit box for cut & paste of the error msg.
vc++ release using the produced .rc file and low res custom icon was less than 20 KB.

edit: looks like it's actually 58 KB if you compile without the msvcr100.dll dependency.  Still, that's not bad for a stand-alone exe.



I know you can do the same thing just in code but I enjoy lining stuff up with the editor.

« Last Edit: September 18, 2010, 11:14:11 PM by MilesAhead »

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #23 on: September 19, 2010, 08:55:02 AM »
I definitely prefer to use .rc files when doing simple-ish GUIs for ligthweight C++ apps. Once you need anything fancy (like auto-resizing), you're better off using some framework...

Thanks for the ResEdit link :)
- carpe noctem

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: GlassPrompt 1.1
« Reply #24 on: September 19, 2010, 10:59:10 AM »
In Windows Seven it shows up easily.  They must have improved the scrollbar draw when it's glass.

Indeed they did! This was why it didn't work pre Win7.