Showing posts with label mfc interview questions. Show all posts
Showing posts with label mfc interview questions. Show all posts

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
);

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

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