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

Post Message



Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
Syntax:
BOOL WINAPI PostMessage(

  opt_  HWND hWnd,

        UINT Msg,

        WPARAM wParam,

        LPARAM lParam

);


Parameters

hWnd [in, optional]
Type: HWND

A handle to the window whose window procedure is to receive the message. The following values have special meanings.
HWND_BROADCAST : The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows. The message is not posted to child windows.
NULL: The function behaves like a call to "PostThreadMessage" with the dwThreadId parameter set to the identifier of the current thread.

Msg [in]
Type: UINT
The message to be posted.

wParam [in]
Type: WPARAM
Additional message-specific information.
lParam [in]
Type: LPARAM
Additional message-specific information.




Source:MSDN

Send Message


Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

Syntax :
LRESULT WINAPI SendMessage(

    HWND hWnd,

    UINT Msg,

    WPARAM wParam,

    LPARAM lParam

);



Parameters:

hWnd [in]
Type: HWND
A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.

Msg [in]:
Type: UINT
The message to be sent.

wParam [in]
Type: WPARAM
Additional message-specific information.

lParam [in]
Type: LPARAM
Additional message-specific information.



Source:MSDN

Virtual table or vTable



The virtual table is a look-up table of functions used to resolve function calls in a dynamic/late binding manner. The virtual table sometimes called by other names, such as “vtable”, “virtual function table”, or “virtual method table”.


Every class that uses virtual functions is given its own virtual table. This table is simply a static array that the compiler sets up at compile time. A virtual table contains one entry for each virtual function that can be called by objects of the class. Each entry in this table is simply a function pointer that points to the most-derived function accessible by that class.


The compiler also adds a hidden pointer to the base class, which we will call *__vptr. *__vptr is set (automatically) when a class instance is created so that it points to the virtual table for that class. Unlike the *this pointer, which is actually a function parameter used by the compiler to resolve self-references, *__vptr is a real pointer. 




Ref:Learncpp.com

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...