Monday, November 10, 2014

String Table



A string table is a Windows resource that contains a list of IDs, values, and captions for all the strings of your application. For example, the status-bar prompts are located in the string table.
While developing an application, you can have several string tables — one for each language or condition. However, an executable module has only one string table. A running application can reference several string tables if you put the tables into different DLLs.
String tables make it easy to localize your application into different languages. If all strings are in a string table, you can localize the application by translating the strings (and other resources) without changing source code. This is usually more desirable than manually finding and replacing various strings in source files.

Using the String editor, you can: 


  •  Search for one or more strings.
  • Quickly insert new entries into the string table.
  • Move a string from one resource file to another
  • Use in-place editing for the ID, Value, and Caption properties and view changes immediately.
  • Change the caption property of multiple strings
  • Add formatting or special characters to a string

Difference between a GetDC() and GetWindowDC()



GetDC: The GetDC() function retrieves a handle to a display device context for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the device context.
HDC GetDC(
  HWND hWnd   // handle to a window
);

GetWindowDC: The GetWindowDC() function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area. GetWindowDC assigns default attributes to the window device context each time it retrieves the device context. Previous attributes are lost.
 
HDC GetWindowDC(
  HWND hWnd   // handle of window
);

Monday, October 20, 2014

Inline Functions

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. Instead of transferring control to and from the function code segment, a modified copy of the function body may be substituted directly for the function call. In this way, the performance overhead of a function call is avoided.
A function is declared inline by using the inline function specifier or by defining a member function within a class or structure definition. 

The inline specifier is only a suggestion to the compiler that an inline expansion can be performed; the compiler is free to ignore the suggestion. 

The following code fragment shows an inline function definition. 

inline int add(int i, int j) { return i + j; }
 
The use of the inline specifier does not change the meaning of the function. However, the inline expansion of a function may not preserve the order of evaluation of the actual arguments. Inline expansion also does not change the linkage of a function: the linkage is external by default.

Wednesday, October 1, 2014

Difference between shallow copy and deep copy

When you do a shallow copy, all the fields of the source object is copied to target object as it is. That means, if there is a dynamically created field in the source object, shallow copy will copy the same pointer to target object. So you will have two objects with fields that are pointing to same memory location which is not what you usually want.
In case of deep copy, instead of copying the pointer, the object itself is copied to target. In this case if you modify the target object, it will not affect the source. By default copy constructors and assignment operators do shallow copy. To make it as deep copy, you need to create a custom copy constructor and override assignment operator.

C++ Storage Classes



Storage classes are used to specify the visibility/scope and life time of symbols (functions and variables). That means, storage classes specify where all a variable or function can be accessed and till what time those variables will be available during the execution of program.
Following storage classes are available in C++,

  • Auto:
Auto is the default storage class for local variables. They can be accessed only from within the declaration scope. auto variables are allocated at the beginning of enclosing block and deallocated at the end of enclosing block. 

  • Register:
Register storage class is similar to auto variables. Difference is that register variables might be stored on the processor register instead of RAM, that means the maximum size of register variable should be the size of CPU register ( like 16bit, 32bit or 64bit). This is normally used for frequently accessed variables like counters, to improve performance. But note that, declaring a variable as register does not mean that they will be stored in the register. It depends on the hardware and implementation. 

  • Static:
A static variable will be kept in existence till the end of the program unlike creating and destroying each time they move into and out of the scope. This helps to maintain their value even if control goes out of the scope. When static is used with global variables, they will have internal linkage, which means it cannot be accessed by other source files. When static is used in case of a class member, it will be shared by all the objects of a class instead of creating separate copies for each object. 

  • Extern:
extern is used to tell compiler that the symbol is defined in another translation unit (or in a way, source files) and not in the current one. Which means the symbol is linked externally. Extern symbols have static storage duration, which is accessible throughout the life of program. Since no storage is allocated for extern variable as part of declaration, they cannot be initialized while declaring.



  • Mutable:

mutable storage class can be used only on non static non const data a member of a class. Mutable data member of a class can be modified even if it's part of an object which is declared as const.
 





Wednesday, September 17, 2014

Message Maps

Since Windows is a message-oriented operating system, a large portion of programming for the Windows environment involves message handling. Each time an event such as a keystroke or mouse click occurs, a message is sent to the application, which must then handle the event.

The Microsoft Foundation Class Library offers a programming model optimized for message-based programming. In this model, "message maps" are used to designate which functions will handle various messages for a particular class. Message maps contain one or more macros that specify which messages will be handled by which functions. For example, a message map containing an ON_COMMAND.


BEGIN_MESSAGE_MAP(CMyDoc, CDocument)

   ON_COMMAND(ID_MYCMD, &CMyDoc::OnMyCommand)

END_MESSAGE_MAP().

The ON_COMMAND macro is used to handle command messages generated by menus, buttons, and accelerator keys.





Source:MSDN

String Table

A string table is a Windows resource that contains a list of IDs, values, and captions for all the strings of your application. For exa...