2009-11-22

Windows Console and True Type Fonts

In a previous article (Pimpin' Windows XP's cmd.exe) I've presented a way to change the font for the Windows Console - hacking a font and name it Lucida Console.

The above method is a hack, since Microsoft has presented with a dialog to change the font, surely they've thought on a method to add new true type fonts, and it turns out that they did.

The console font configuration is done by the means of Registry, the following registry key is responsible for that:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Console\TrueTypeFont

There you will find "Lucida Console" as number "0", if you will add the value "1" as "DejaVu Sans Mono" nothing will happen, you need to add the second font as "00", third as "000" and so on.

Microsoft has a KB on how to add a font to the console. A button in the
Windows Console property pages would have been far more useful than a KB page.

Here is a screenshot showing "DejaVu Sans Mono" in the console font property page:

2009-10-08

Silverlight for Windows Embedded^H...^H C++

Microsoft has released Silverlight for Windows Embedded. OK, Silverlight runs also on Embedded Devices, not a big deal, not for me anyways, but the first thing that came to my eye was "Silverlight for Windows Embedded is a native code (C++) UI framework".

Native code (C++) UI framework, awesome! Here is a more wide description from the Overview video:

Is a C++ backend instead of managed, for performance and for footprint, but, also we've taken the toolchain from the Silverlight development process so you still get all the benefits of having the two disciplines of the designer and the developer.

So with Expression Bend you are still able to design all of your UIs and all of the storyboards and animations and all the effects that encapsulate the UI are all still done by the designer and then the developer takes that XAML and instead of writing managed C# or VB they write C++ code.

Next I wanted to see how the code looks like, I've found this tutorial and a document on how to "Create a Custom User Control in Silverlight for Windows Embedded".

I don't see why this C++ Silverlight framework should not be available for Desktop, performance and small footprint are also important for Desktop applications.

This would be a great addition for Visual Studio 2010 for native developers, besides the new Intellisense based on the EDG C++ frontend. But I guess the feature list for Visual Studio 2010 is frozen, maybe for Visual Studio 2012.

If you think that having this technology brought to the Desktop is a good idea please sign this petition and spread the word.

2009-09-30

Batch change script for Visual C/C++ Projects

Visual C/C++ projects are XML files but they have a different file extension (*.vcproj).

Having to change an option to through tens of projects files each with more than one platform (Win32, Win64, Windows Mobile) and multiple configurations (Debug, Release) only by loading the projects in Visual Studio and clicking through the UI is not very appealing.

Since we already know that the project files are XML files one can write a program / script to change the desired option, in my case the change of the C runtime library - dynamic / static.

I have chosen WSH JScript, MSXML 3.0 and XPath to write a script to change Visual C/C++ projects. My decision was due two arguments: JScript is present on Windows XP, and the scripts can be debugged by Visual Studio 2005+ (//X command line parameter).

During the development I have stumbled on a XPath query problem, the function contains was not found in msxml3.dll. The problem was due to the fact that MSXML 3.0 was not instructed to use XPath as selection language (xmlDoc.setProperty("SelectionLanguage", "XPath");). Newer MSXML versions do not have this requirement though.

The message boxes displayed when issued from command line like change_runtime.js myproject.vcproj are due to the fact that JScript is not the default scripting language in WSH. One solution is to call the script like: cscript change_runtime.js myproject.vcproj, which requires some typing, the other solution is to change the default scripting language in WSH, which can be accomplished by running cscript //H:CScript.

The source code can be found here. Changing Visual C/C++ projects just become easier for me :-)

2009-09-19

Browsere moderne

Browserele web moderne (ultimile versiuni) știu să genereze caracterele lipsă din fonturi atunci când pagina web o cere.

Am decis să testez această funcționalitate pe un sistem Windows XP SP2, cu setările implicite (Engleză SUA), și fără actualizări. În special am urmărit cum se descurcă cu caracterele ș și ț cu virgulă, care lipsesc din fonturile cu care vine Windows XP SP2 (pentru mai multe informații a se vedea pagina lui Cristian Secară ș-uri și ț-uri). Ulterior am testat și sistemul de operare Windows 7.

Pagina de test conține o pangramă (Muzicologă în bej, vând whisky şi tequila, preţ fix.) scrisă cu familiile implicite de fonturi serif, fără serif și monospațiat în forma normală și cursivă. Setul de caractere setat a fost UTF-8.

Microsoft Internet Explorer 6


Microsoft Internet Explorer 7


Microsoft Internet Explorer 8


Mozilla Firefox 3.5.3


Google Chrome 3.0


Opera 10.0


Safari 4.0.3


Internet Explorer 6 a fost luat drept referință. Mozilla Firefox s-a descurcat cel mai bine la famillile de fonturi serif și fără serif în forma normală, forma cursivă și cea monospațiată a caracterelor ș și ț nu se integrează foarte bine cu restul caracterelor.

Pentru a repara problema caracterelor ș și ț în fonturile serif și fără serif Microsoft în luna Mai 2007 a scos un pachet de actualizare a unor fonturi din sistemele de operare Windows XP și Windows Vista.

Familia de fonturi monospațiate nu a beneficiat de o actualizare, a se vedea captura de ecran de mai jos:

Microsoft Internet Explorer 8 (cu pachetul de fonturi actualizate)



Windows 7 beneficiază de fonturi monspațiate care conțin caracterele ș și ț, a se vedea captura de ecran de mai jos:



Captura de ecran de mai sus arată o problemă în Internet Explorer 8 din Windows 7, problemă cu varianta implicită a fontului serif. Setarea "clear type" a fost activată, dar dintr-un motiv necunoscut textul este afișat foarte prost.

Mozilla Firefox 3.5.3 afișează corect caracterele ș și ț rulând pe Windows 7:



Google Chrome 3.0 afișează corect caracterele ș și ț rulând pe Windows 7:



Safari 4.0.3 afișează corect caracterele ș și ț rulând pe Windows 7:



Opera 10.0 afișează corect caracterele ș și ț rulând pe Windows 7:



Concluzie: în Windows 7 problema caracterelor ș și ț cu virgulă este deja rezolvată.

Hidden stream

If you wondered why does a security dialog pop up when you try to run the oggcodecs installer (or every executable for that matter) after downloading it from the Internet, this post is for you.

The security dialog looks like:



If you look at the file properties there is no checkbox like "this file came from the Internet" (CHM files have a check for this though), but this information is stored somewhere, in a NTFS Alternate Data Stream.

To check if a file has a NTFS Alternate Data Stream one can use the Streams utility made by By Mark Russinovich of Sysinternals fame.

Running streams oggcodecs_0.81.15562-win32.exe resulted: :Zone.Identifier:$DATA 46.

To view this "Zone.Identifier" stream I have used the more command like more < oggcodecs_0.81.15562-win32.exe:Zone.Identifier which resulted:

[ZoneTransfer]
ZoneId=3


Firefox is adding this extra information for every executable file downloaded. Does every web browser (I've tested only I few I know of) on Windows add this extra information?
  • Mozilla Firefox 3.5.3 - yes (:Zone.Identifier:$DATA 46)
  • Microsoft Internet Explorer 8.0 - yes (:Zone.Identifier:$DATA 26)
  • Google Chrome 3.0 - yes (:Zone.Identifier:$DATA 24)
  • Safari 4.0.3 - yes (:Zone.Identifier:$DATA 26)
  • Opera 10.0 - no

Interesting how the size of the stream varies with every browser. I have submitted a bug report to Opera, because they should also add this extra information to the downloaded files.

Adding the Zone.Identifier stream can be done easily with a batch file
(from_internet.cmd)

@echo off
if [%1] == [] (

  echo Usage: from_internet.cmd executable_name

) else (

  echo [ZoneTransfer]> %1:Zone.Identifier
  echo ZoneId=3 >> %1:Zone.Identifier

)


Deleting a stream can be done by using streams -d.

2009-05-23

Colorful Epiphany

I always thought that the RGB macro (Win32 GDI) which takes three arguments - red, green and blue - will create a 0xRRGGBB value.

I was wrong! Win32 GDI uses BGR colors! d'oh

Here is another assertion on the path of assertiveness (germ. Durchsetzungsvermögen)

#include <windows.h>
#include <assert.h>

int main()
{
     COLORREF color_rgb = 0xBBAADD;
    
     assert(color_rgb == RGB(0xBB, 0xAA, 0xDD));
}

Cheers!

2009-05-12

Visual Studio 2008 Donation

I would like to thank Opera Software for the retail package of Visual Studio 2008 Standard Edition I just received!


Thank you!

2009-03-11

DirectShow oggenc v0.1

I have created a DirectShow oggenc clone, mainly due to Ticket #1517 (How to calculate the OGG encoding complete percent correctly?). It is a Visual C++ console application which renders an audio file, removes the audio renderer and inserts a Vorbis encoder and an Ogg muxer filter.

The example also illustrates how to use the IVorbisEncodeSettings and IOggMuxProgress COM interfaces.

During the development of the tool I have found out a few quirks of the COM interfaces, all of which I will address in future oggcodecs releases.

The supported audio source file formats are: WAV, MP3, WMA. FLAC and OGG are not supported because I have used IMediaDet DirectShow interface, which is not supported by oggcodecs at this moment.

One can use another methods of determining the length of the audio source file (seeking at the end of the file and getting the position), which would enable support for FLAC and OGG.

Testing the tool showed that encoding a 4m50s audio wave file on Windows Vista 64bit took an average of 18.1 seconds for the 32bit version, while the 64bit version took on average 13.1 seconds, a speed improvement of ~27%.

Source code can be found here, binaries can be found here (32 bit) and here (64 bit).

2009-02-23

Windows 7

Today while doing a bit of research regarding https://trac.xiph.org/ticket/1498
I found out another limitation of the default audio renderer in DirectShow.

The DirectSound audio renderer cannot play 192KHz, 24 bit audio samples. This behaviour was present on Windows XP SP3 and Windows Vista SP1.

To my surprise Windows 7 (build 7000) doesn't have this limitation, Windows Media Player 12 was able to play the 192Khz 24bit sample FLAC file from Linn Records

Windows Media Player 12 also knows about Ogg Vorbis metadata, which came as a surprise as well.

If somebody will ask me why he/she should upgrade to Windows 7 now I now what to answer :)

2009-01-21

Mono 2.2

Recently Mono 2.2 was released. It has a bunch of new stuff, one of them is: SIMD (Single Instruction, Multiple Data) support in Mono.

Miguel de Icaza has a blog entry where he describes the new SIMD support in Mono. He has ported to C# a C++ application, to illustrate the new SIMD stuff, and then he compares the results, the C++ program was rather slow. I had a look at the source code an I've seen that the C++ program was compiled in debug mode.

I've decided to make a few tests for myself. I've used MinGW 4.3.2 and Visual Studio 2005, the tests where run on my Intel Mobile Core 2 Duo T7500.

Here are the results (in seconds):



The parameters for the above results were:



Mono is not quite there yet (at least on Windows).

I had to change the timing code for the C++ code, glib::GTimer is not a very good option on Windows. I've used the high-resolution performance counter, the code is presented below:


#ifndef PERFTIMER_H
#define PERFTIMER_H

#include <windows.h>
#include <string>

#include <iostream>
#include <iomanip>
#include <sstream>

class PerfTimer
{
     LARGE_INTEGER start_;

     LARGE_INTEGER stop_;
     LARGE_INTEGER freq_;
   public:
    
     PerfTimer()
     {
       QueryPerformanceFrequency(&freq_);
     }

    
     void Start()
     {
       QueryPerformanceCounter(&start_);
     }
    
     void Stop()

     {
       QueryPerformanceCounter(&stop_);
     }
    
     std::string ToString()
     {
       const int precision = 10000000;

       unsigned long time = static_cast<unsigned long>(
     (stop_.QuadPart - start_.QuadPart) * precision /
     freq_.QuadPart);
      
       std::ostringstream os;

       os << std::setfill('0');
       os << std::setw(2) << time / precision / 3600 << ":";
       os << std::setw(2) << time / precision % 3600 / 60 << ":";

       os << std::setw(2) << time / precision % 60 << ".";
       os << std::setw(7) << time % precision;
       os << std::setfill(' ');

      
       return os.str();
     }
};

#if 0
int main()
{
   PerfTimer timer;
   timer.Start();

   Sleep(1250);
   timer.Stop();
  
   std::cout << "Time: " << timer.ToString() << std::endl;
  
   return 0;
}

#endif

#endif // PERFTIMER_H




There are a few things I would like to point out about the Mono 2.2 Windows installer.

1. The executable is not digitally signed by Novell.



2. The graphics are hideous, 16 colors dithering? why? Is anybody in their right mind running Windows in 16 colors?


2009-01-18

Windows CE

I've been busy with the port to Windows CE of libogg, libvorbis, libflac. This is only the beginning, there is still allot of work remaining.

Also I've done a bit of restructuring, I've reduced the number of binaries from 30 to 20, by changing from dynamic link libraries to static libraries. I've changed the usage of the CRT, from dynamic to static linking, this has increased the size of the binaries but overall the installer has the same size, thanks to LZMA solid compression :-)

The above changes will ease the usage of the libraries, for example only dsfOggDemux2.dll dsfVorbisDecoder.dll are needed for Vorbis decoding.

I have created my first Windows CE "Hello World" program. I've wanted for a long time to do that. I've learned that Windows CE has only Unicode support, no more multi byte nightmare.

Because you don't have a console attached the classical "Hello World" is a bit different, a bit WIN32 APIsh:


#include <windows.h>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd )
{
    
wchar_t message[] = L"Goodbye cruel adventure world!";
    
wchar_t caption[] = L"Monkeys are listening";

    ::
MessageBox(0, message, caption, MB_OK | MB_ICONINFORMATION);
    
    
return 0;
}



If you try to run an executable which is not digitally signed, you are being prompted by the operating system telling you that it's dangerous to run "unknown" software.

Since I have a certificate from CERTUM I have signed the executable, but still the prompt was there. The problem was that my telephone doesn't have the root certificate from CERTUM installed. I've went to CERTUM's root certificate page and taken the "Public Key of Certum Level II", installed it and my program ran without any prompts from the operating system.

And now the mandatory "screen shot":

2009-01-15

Programming -- Principles and Practice Using C++

Is the name of Bjarne Stroustrup's latest book.

Here is a quote for the book's website:
It is designed for classroom use, but written with an eye on self study. Drafts have been used as the basis for first programming classes for electrical engineer, computer engineer, and computer science students at Texas A&M University for three years now.

The first thing that you notice when you open the book it's the color! The book is colored, and it has lots of pictures! You can notice that also in the sample chapters found on the book's website :)

My guess is that it was the author's intention to make it more appealing for the students, having to read more than 1000 black and white pages can have a devastating effect on a student's pathos!

This is the second colored programming book that I have, after "Windows Presentation Foundation Unleashed".

This is Bjarne's first book about graphical user interface (GUI) applications development. He had chosen FLKT as a GUI library, and there are four chapters allocated (~160 pages).

I can't say anything more because I haven't read it, but I can attach a picture:

2009-01-12

OptiPNG

When it comes to saving screen shots, PNG is the number one image format due to its lossless compression.

JPEG has artifacts around text and washed colors because of lossy compression, GIF has a limited color palette (only 256 distinct colors).

Normally PNG files a bit bigger than JPEG and GIF, but with OptiPNG you can decrease the size of a PNG file quite a bit.

I have taken a screen shot of vorbis.com and saved it under different file formats:
  • BMP - 2.956.854 bytes
  • PNG - 130.174 bytes (IrfanView level 9 compression)
  • PNG - 115.491 bytes (Microsoft Paint)
  • JPEG - 99.003 bytes (80% compression)
  • GIF - 90.024 bytes
  • PNG - 88.040 bytes (OptiPNG on Microsoft Paint's PNG file)
  • PNG - 87.967 bytes (OptiPNG on IrfanView's PNG file)

OptiPNG has been created by Cosmin Truţa, yet another famous Romanian computer science engineer star

2009-01-06

XAML in native C++

With the advent of WPF and XAML Microsoft has changed the way GUI Windows applications are developed, by introducing markup language into GUI development.

Unlike previous GUI APIs, the core of the WPF is written entirely in managed code, there is nothing for native C++ developers, there is not even support for C++/CLI (one can do some workarounds, but no support from the IDE and Blend)

Today I have found out that CodeJock has added support (see press release) for XAML scripts in their Xtreme ToolkitPro library. They do not support everything from WPF, they started adding markup properties for various GUI elements, in time the support will continue to grow.

The XAML section of their forums contains lots of information on the topic, which stuff is working, which is not. There I have found out sample applications, an early version of their MarkupPad (now an year old), which shows the capability of their XAML parser.

I have made a screenshot with MarkupPad and XAMLPad:



They both look the same, then I have had a look with Process Explorer and here is another picture with the results (see memory footprint):



I am aware that the comparison is not fair, CodeJock doesn't have a full XAML parser (no Timeline, no 3D, no...), but these are facts which can be seen at the moment.

Hats off for CodeJock for adding this functionality, I guess Microsoft could have done the same for MFC, but they don't care anymore about native GUI development, the latest new blood in MFC was bought from BCGSoftware, which doesn't have any support for XAML in their flagship products, namely BCGControlBar

It would be nice to have an open source, cross platform, native C++ XAML parser.

2009-01-04

Python has a bin

I mainly use Python on Windows as a calculator. I can use expressions, variables, and it can handle really big numbers.

When I need to transform decimals into hexadecimal I use hex(number) function. On many occasions I've tried bin(number) and failed because until Python 2.6 there was no bin function, it took me some time to realize why it worked :) then I've read Python 2.6 change log.

Python 2.6 is cooler now with the bin function!