Windows 7: Create New Folder Keyboard Shortcut


My favorite keyboard shortcut introduced in Windows 7 has to be Shift + Ctrl + N to create a new folder. I am constantly organizing files into folders and this shortcut is very useful! Now, I am actually wishing there was a keyboard shortcut to create a new text file too! 🙂

Advertisements

C++: Initialize STL Vector with Array

A STL vector does not have any constructor that looks like it accepts an array. So, the straightforward way to initialize a vector with an array looks like:

#include <vector>

int arr[ARR_LEN] = { /* Array elements */ };
std::vector iVec;
for (int i = 0; i < ARR_LEN; ++i)
    iVec.push_back( arr[i] );

That is too much code for a simple initialization! Thankfully, there is another way do it with less code.

The constructor vector(InputIterator begin, InputIterator end) which initializes a vector with the elements of the range [begin, end) can be used with arrays too. This is because array pointers have all the properties required of an (input) iterator:

#include <vector>

int arr[ARR_LEN] = { /* Array elements */ };
std::vector<int> iVec(arr, arr + ARR_LEN);

Note that the second argument arr + ARR_LEN is beyond the last element of the array and thus behaves as the correct end().

Windows 7: Shared Folders Management

In Windows 7, shared folders do not have an overlay icon on them indicating they are being shared. The reason for this change is explained by Raymond Chen here:

Given the changes in how people use computers, sharing information is becoming more and more of the default state. When you set up a HomeGroup, pretty much everything is going to be shared. To remove the visual clutter, the information was moved to the Details pane. What’s more, a single overlay cannot express the different ways an item can be shared, so in order to figure out what the deal is, you have to go to the Details pane anyway.

So, the best place to view your shared folders and to stop sharing them (after the sharing love is over) is the Shared Folders MMC. It can be invoked by typing fsmgmt.msc at the Start menu.

Adobe Acrobat: Embedded Font Error

Cannot extract the embedded font 'Foobar'. Some characters may not
display or print correctly.

You may see this error with Adobe Acrobat 8 when you open certain PDF documents. If the Foobar font has been used all over the PDF, all you see of the document will be gibberish!

Adobe says they have fixed this error in their Acrobat 8.1.1 update:

#1572280 Type 3 fonts with missing operators. PDF documents that contain Type 3 fonts with missing operators are non-compliant with the PDF specification. These non-compliant PDF documents are typically generated by third party products. When trying to opening the document, users see an error message, “Cannot extract the embedded font ‘F0’. Some characters may not be displayed or printed correctly.” PDF documents open correctly in Reader/Acrobat 7.x, but not 8.0 or 8.1. The root cause is Type 3 fonts that do not comply with the PDF specification, which requires either the ‘d0’ or ‘d1’ operator in every Type 3 character procedure. In version 7.x, if the offending character was not displayed, the PDF document opened normally. Version 8.0 catches this error even if the character is not displayed. The updated behavior will ignore the missing operator when the character procedure is empty.
Root: fixes an issue in versions 8.0 and 8.1, not present in earlier versions.

However, installing the 8.1.1 update does not really fix this error! In fact, even though I incrementally updated all the way up to 8.2, the error is not solved. 8.2 is the last Acrobat 8.x update available for the 8 series.

There does not seem to be any solution to this error by Adobe. It does not seem to be fixed even in the 9.x series of Adobe Acrobat (see Mark Kostka’s comment below). The solution seems to be the latest versions of Adobe Acrobat Reader or Foxit Reader. The PDF documents display and print without any problem in these readers!

How to disable Group By in Windows 7

Windows Explorer on Windows 7 tries to be intelligent and offers to group the contents of a directory according to certain parameters. A lot of times when it cannot do this, it lumps them in a group named Unspecified. I find this grouping affair very irritating, especially when selecting files using the keyboard.

To turn off Group By completely:

  1. Open any directory in Windows Explorer.
  2. Right-click and choose Group by > (None)
  3. Press the Alt key, so that the Explorer menu bar appears and choose ToolsFolder Options.
  4. Go to the View tab and click Apply to Folders. This will apply the Group By setting to all folders.

Firefox: Mozilla Weave

Mozilla Weave, the synchronization tool for Firefox has finally launched! I am currently using it to synchronize bookmarks and preferences between my work PC and my home laptop. (I am not putting sensitive information like passwords on the Weave servers, thank you!)

Installing and using Weave is pretty straightforward if you have used Xmarks, which is what I currently use for bookmark synchronization. Download the Weave Sync addon for Firefox and install it on the computers where you need synchronization. In addition to a Weave login and password, you will also be asked to create a passphrase, that is used to encrypt your content stored on the Weave servers. If Weave works out well for a couple of weeks, I will be saying goodbye to Xmarks.

PS: I know Google Chrome has bookmark synchronization that stores the information in the user’s Google Docs account. As of now, I am sticking to Firefox as I see no killer feature in Chrome that is worth the switch.

C++: Assertion with Information

I find it useful to include the comment or information about an assertion in the assert() expression itself.

Code like:

// Check for invalid oxygen level
assert(oxyLevel < OXYGEN_MAX);

can easily be rewritten as:

assert((oxyLevel < OXYGEN_MAX) && "Invalid oxygen levels!!!");

This works because a C string constant is always true (non-zero).

I like the second version since it folds the comment information into the assert() expression. Also, when the assertion fails, Visual Studio pops up a dialog where you can see the entire assert() expression (which includes your informative string):

Visual C++: Read and Write INI Files

I find it useful to keep the settings for my application separated from the code in a initialization (INI) file. The application code reads these settings at runtime and uses them for initialization of its objects. This separation means that I can try the application with different settings without having to recompile the code. (C++ code takes ages to compile!) And the INI file is human readable and writable easily using any text editor.

A simple INI file:

;------------------------------------------------
; Foobar Settings (foobar.ini)
;------------------------------------------------

; Database settings
[DB_SETTINGS]
USER_NUM_MAX = 256  ; Maximum number of users

; Operation settings
[OP_SETTINGS]
CRITICAL_SIZE = 100000  ; Maximum memory
;------------------------------------------------

The Initialization (INI) file format is simple. Anything to the right of a semicolon ; is a comment. Sections are named within a pair of square brackets []. Key-value pairs are written as key=value.

To read an integer or string value use GetPrivateProfileInt() or GetPrivateProfileString(). To write a string value back to a key use WritePrivateProfileString(). (There is no function to write back an integer, convert it to a string.)

#include <Windows.h>

int userNumMax = GetPrivateProfileInt("DB_SETTINGS", "USER_NUM_MAX", 0, "foobar.ini");
WritePrivateProfileString("DB_SETTINGS", "USER_NUM_MAX", "99", "foobar.ini");

For other functions related to INI files look for those with the prefix GetPrivateProfile and WritePrivateProfile in Registry Functions. The functions with prefix GetProfile are meant for win.ini, which should be not be useful to anyone!

Windows 7: Hide Desktop Icons

In older versions of Windows I had to remove all the icons and folders from the desktop to keep it clean (which is how I like it). But, with Windows 7 you can keep your icons and folders on the desktop, but just hide them so they are not visible. You can always access them by going to the Desktop folder inside Windows Explorer.

To turn off the desktop icons: Right-click on the desktop and de-select ViewShow desktop icons.