Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

C++

Articles on C++ programming language.

MFC – Keyboard Hook Filter Functions

Keyboard Hook and Filter Functions

The SDI sample, under the file menu, has two menu items called Hook CAPS Lock, Unhook CAPS Lock. When the user clicks the Hook Caps Lock menu item, the Keyboard hook is attached to the application and hooks the keyboard event. The UnHook CAPS Lock event removes installed hook from the application.

Our example SDI contains two menu items called First Dialog and Second Dialog under view menu. These menu items will bring up two dialogs with text boxes in it. When a hook is installed, you can type only the capital letters in the dialogs. After opting for the Un-Hook action, you will not have upper case constraint on the dialogs. Let us jump into the explanation-based walk-through.

Continue Reading →

Custom Mapping Mode in VC++ Via MM_ISOTROPIC

Window and Viewport Extends vs Pixels

In the previous MFC Article, we examined how the Mapping Modes works while performing the drawing operation. In this example, we will see how we set the custom mapping modes. Our goal is below:

1) Set mapping mode so that the horizontal logical unit is 1 Centimeter (cm). Simply, 1 Unit = 1 cm in X axis.
2) Also, 1 Unit = 1 cm in Y Axis.
3) Positive X is towards left.
4) Positive Y is going Upwards.
5) The Drawing origin should be in screen center.

We can achieve the above goal by using the Custom Mapping mode MM_ISOTROPIC.

Continue Reading →

MFC Mapping Modes & Drawing Coordinate

MFC View-Port Origin and Window Origin

MFC supports two kinds of coordinate systems. One is Device Coordinate and the other one is Logical Coordinate. In device coordinate, we point out all in terms of pixels. In logical coordinate, we measure each unit in terms of Metric Standard or British Standard. How each unit maps to the logical measure is called the mapping. We can mention the mapping using the Mapping Modes. In MFC, having the knowledge of Drawing Origin is the key to draw in the Client Area the way you want.

In this Example, we will walk through the examples and demo videos, which will help us in learning the Mapping Modes and doing the MFC drawing using the device contexts. We will also try the ViewPort Origin and Window Origin and how to use them while drawing using MFC GDI APIs.

Continue Reading →