Powerbasic Museum 2020-B

IT-Consultant: Patrice Terrier => C++ programming (SDK style) => Topic started by: Patrice Terrier on February 23, 2011, 03:33:54 PM

Title: VS2010 - HUDplusC++
Post by: Patrice Terrier on February 23, 2011, 03:33:54 PM
Here is the final version of the VS2010 C++ HUDplus project.


What is new:



Screen shot

(http://www.zapsolution.com/pictures/Attractor.jpg)


How to use the project:



Note:
This project is meant to be used on VISTA/Seven running in AERO mode.
Because the size of the ZIP has increased to 9060 Kb, i was not able to post it here as an attachment.
You will have to download it from this link: HUDplusC++.zip (http://www.zapsolution.com/preview/HUDplusC++.zip)

Note:
The extended window class WS_EX_ACCEPTFILES has been used with the main window to ease the handling of drag and drop (no need to use DragAcceptFiles first).

...
Title: Re: VS2010 - HUDplusC++
Post by: Florent Heyworth on February 24, 2011, 07:47:31 AM
Hi Patrice

I downloaded the new HUDPlius project - just one comment and this is connected to UAC in Windows 7 (and probably in Vista):

The ShellExecute() function can result in Windows prompting the user whether he/she wants to allow the shelled program to run - since you use ShellExecute with no parent window and before ShowWindow(g_hMain) the prompt for allowing ZWP.exe may not be displayed blocking Hudplus.exe.

I'd move the ShellExecuteA after the ShowWindow(g_hMain) call - something like:


          string sRunProg = ExePath(); sRunProg += "ZWP.exe";
          char szRunProg[MAX_PATH]; strncpy_s(szRunProg, sRunProg.c_str(), sRunProg.size() ); sRunProg = "";
          string sPlaythis = g_sPluginPath; sPlaythis += szFullpathToFile;
          char szPlaythis[MAX_PATH]; strncpy_s(szPlaythis, sPlaythis.c_str(), sPlaythis.size() ); sPlaythis = "";
          char szExePath[MAX_PATH]; strncpy_s(szExePath, sExePath.c_str(), sExePath.size() );
          // Start the background plugin player.
 

          ShowWindow(g_hMain, SW_SHOW);
          if (hZWP == 0) {
                ShellExecuteA(g_hMain, "open", szRunProg, szPlaythis, szExePath, SW_SHOWNOACTIVATE);
          }


By the way - nice work, Patrice ;)

Cheers, Florent
Title: Re: VS2010 - HUDplusC++
Post by: Patrice Terrier on February 24, 2011, 08:46:45 AM
Florent,

Thank you for the feedback.

Have you encountered any UAC problem yourself when ZWP.exe is being fired?
I, for myself, never got any prompt from the UAC.

About the location of the code that starts zwp.exe, it should not be moved, in order to preserve the fluidity of the fall down effect.

Also it is important that zwp.exe should not be associated to any specific window, thus using "ShellExecuteA(0, "open"...", because ZWP.exe could be already running (it could be used by another process as well).

And this is the reason why its presence is checked very early in the code:
   // Check if ZWP is already running.
   char zClass[] = "ZWALLPAPER"; HWND hZWP = FindWindowA(zClass, zClass);


...
Title: Re: VS2010 - HUDplusC++
Post by: Florent Heyworth on February 24, 2011, 09:24:07 AM
Hi Patrice

good point about zwp.exe already running however:

I usually flag trusted downloads as trusted (no prompting on run) -butI did test this with HUDPLUS (indicating that UAC should prompt on running zwp) - when this is set HUDPLUS appears to hang because it is waiting for the user to address the UAC prompt but no prompt window is displayed. You can still start ShellExecute with a NULL window but I'd recommend moving the ShellExecute call to bypass this potential problem.

Cheers, Florent
Title: Re: VS2010 - HUDplusC++
Post by: Patrice Terrier on February 24, 2011, 10:00:19 AM
Florent,

I always run UAC in quiet mode ;)

Perhaps you could try to use "runas" lpVerb instead of "open" to prompt the user.

I could add a specific manifest into ZWP to elevate its privilege?
for example:

   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
     <security>
       <requestedPrivileges>
         <requestedExecutionLevel level="highestAvailable"/>
       </requestedPrivileges>
     </security>
   </trustInfo>




Note:
Before you download a ZIP file from this forum, you must add this web site to your Internet Explorer security zone, to avoid problems with UAC.

Another solution is to unlock downloaded ZIP file, using a right click to popup the contextual menu, and select "properties" to unlock the ZIP before to extract the embedded files. 

...
Title: Re: VS2010 - HUDplusC++
Post by: Patrice Terrier on February 24, 2011, 03:21:06 PM
Point of interest in HUD window.

Everything is rendered onto the DirectDraw surface with a 60 hertz/fps frequency.
It means, there is no latency when moving the main popup and the underlaying window.
There is no flickering, and the animation keeps playing while moving the application around.
No need to use a timer or to hog the CPU with an intensive graphic loop animation.
You can mix 2D and 3D animation altogether running at full speed, because of the use of the GPU features.

Using a slave underlaying window produces better time slicing, without the drawback of using threads.
The two applications are working together through one single private message using the standard SendMessage/PostMessage mechanism (kind of DDE).

HUD window is able to display opaque and/or translucent child controls, something not possible with a standard Layered window.
For example, it is possible to draw a halo or a true shadow around the frame of the window.

HUD window illustrates the amazing capabilities of WinLIFT and GDImage working together, using the latest technology available in VISTA/Seven DWM Aero.

...