How to Change Print Orientation in MFC

There is no big science to it, but thanks to a “bad choice of title”, the appropriate MSDN-KB-HOWTO article is not easy to find. So, here’s a link:

MSDN KB 126897: How to Change Default Printer Settings in an MFC Application

The above link takes you directly to the code snippet that sets print orientation to landscape; to change the orientation to portrait, you only need to change the DMORIENT_LANDSCAPE to DMORIENT_PORTRAIT; of course, the easiest way is to change the function to allow user to choose the orientation.

Note: The presented code, of course, also changes the orientation of the print preview.

To use the above code, simply surround your printing (or print preview) code with (provided you changed the function to accept bool to choose orientation, and to return previous setting):

CMyApp* app = (CMyApp*) ::AfxGetApp();
bool old_po = app->SetPrintOrientation(*your choice of orientation*);
// printing (or print preview) code comes here

Note: So far, I didn’t manage to find a way to change the print orientation for individual pages; seems like you have to print portrait and landscape oriented pages in separate print jobs (?).

How to Find Shell (System) Folders in Win32 from C/C++

It’s possible to refer to e.g. My Documents folder on your own computer by the path you know, and it’ll work. But if you want to distribute your program among users, you cannot expect the fixed path to work. E.g. Windows allow you to save user’s profile folders anywhere on the disk you want; it’s not a rule that all are saved under Documents and Settings; e.g. mine are saved under folder called Profiles, since I wanted to preserve the original Documents and Settings from my previous Windows installation. Also, Windows need not to be installed under C:\Windows; mine are under C:\Windows.1.

But, there is a (quite) simple way to find all the necessary system folders in Windows. All you have to do is be a bit careful.

Continue reading

Music for the Day – some MP3’s

Here are few of my favourite music compositions for (do I have to emphasize, free?) download.

Johann Pachelbel – Canon – ca 1680, simply amazing!

Vladimir Cosma – Le Professionnel – 1981, amazing music score for an amazing movie.

Inlantic – Character and Inlantic – Landmass – instrumental math-rock; anyone by any chance having the full album? It’s just impossible to get (order or download) it anywhere!…