0% found this document useful (0 votes)
53 views

Menus Ex - No:7 Date: Aim

The document describes steps to develop menus in a Windows program using resource scripts. It includes steps to start a Visual C++ project, create menu resources, include header files, load menus, and respond to menu messages. It also defines functions like PostMessage(), Polygon(), RedrawWindow(), MAKEINTRESOURCE(), and LoadMenu() that are relevant for working with menus.

Uploaded by

Geetha Krishniah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Menus Ex - No:7 Date: Aim

The document describes steps to develop menus in a Windows program using resource scripts. It includes steps to start a Visual C++ project, create menu resources, include header files, load menus, and respond to menu messages. It also defines functions like PostMessage(), Polygon(), RedrawWindow(), MAKEINTRESOURCE(), and LoadMenu() that are relevant for working with menus.

Uploaded by

Geetha Krishniah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

MENUS

Ex.No:7
Date:

AIM:
To develop menus using resource script in windows program.

STEPS AND ALGORITHM:

1. Start →programs Microsoft Visual Studio6.0→Microsoft Visual C++6.0.


2. Visual C++ Window will be opened.
3. Select File→New→Win32 Application, then give the project name and then choose
empty project button and finally give Finish → OK.
4. Again go to File → New → C++ Source File → File Name → OK.
5. Again go to File →New →Resource script→File Name.

6. Go to Insert →Resource → Menu →New.


7. Create either the simple Menu or Pop up Menu with unique menu ID.
8. Type the coding.
9. Include the resource header file.
10. In the WinMain part change the lpszMenuName Property as either one as follows:
MAKEINTRESOURCE(IDR_MENU1);
LoadMenu(HINSTANCE hInstance,LPCTSTR lpMenuName);
11. Build and test the application.
MESSAGES:
 WM_COMMAND
 WM_DESTROY

FUNCTIONS:

PostMessage: This Function 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(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.

Value Meaning
HWND_BROADCAST The message is posted to all top-level windows in the system,
((HWND)0xffff) 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.

 
Starting with Windows Vista, message posting is subject to UIPI. The thread of a
process can post messages only to message queues of threads in processes of
lesser or equal integrity level.
Msg [in]
Type: UINT
The message to be posted.
For lists of the system-provided messages, see System-Defined Messages.
wParam [in]
Type: WPARAM
Additional message-specific information.
lParam [in]
Type: LPARAM
Additional message-specific information.
Return Value
If the function succeeds, the return value is nonzero.If the function fails, the return value
is zero.

Polygon: The function draws a polygon consisting of two or more vertices connected by straight
lines. The polygon is outlined by using the current pen and filled by using the current brush and
polygon fill mode.

Syntax:

BOOL Polygon( HDC hdc, const POINT *lpPoints,  int nCount);

Parameters:

hdc [in]
A handle to the device context.
lpPoints [in]
A pointer to an array of POINT structures that specify the vertices of the
polygon, in logical coordinates.
nCount [in]
The number of vertices in the array. This value must be greater than or equal to 2.

Return Value:
If the function succeeds, the return value is nonzero.If the function fails, the return
value is zero.

RedrawWindow: The  function updates the specified rectangle or region in a window's client


area.

Syntax:

BOOL RedrawWindow(HWND hWnd,const RECT *lprcUpdate,HRGN


hrgnUpdate,UINT flags);

Parameters:
hWnd [in]
A handle to the window to be redrawn. If this parameter is NULL, the desktop
window is updated.
lprcUpdate [in]
A pointer to a RECT structure containing the coordinates, in device units, of the
update rectangle. This parameter is ignored if thehrgnUpdate parameter identifies
a region.
hrgnUpdate [in]
A handle to the update region. If both the hrgnUpdate and lprcUpdate parameters
are NULL, the entire client area is added to the update region.
flags [in]
One or more redraw flags. This parameter can be used to invalidate or validate a
window, control repainting, and control which windows are affected
by RedrawWindow.
The following flags are used to invalidate the window.

Flag (invalidation) Description


RDW_ERASE Causes the window to receive a WM_ERASEBKGND message
when the window is repainted. The RDW_INVALIDATE flag
must also be specified; otherwise, RDW_ERASE has no effect.
RDW_FRAME Causes any part of the nonclient area of the window that intersects
the update region to receive a WM_NCPAINTmessage. The
RDW_INVALIDATE flag must also be specified; otherwise,
RDW_FRAME has no effect. TheWM_NCPAINT message is
typically not sent during the execution of RedrawWindow unless
either RDW_UPDATENOW or RDW_ERASENOW is specified.
RDW_INTERNALPAINT Causes a WM_PAINT message to be posted to the window
regardless of whether any portion of the window is invalid.
RDW_INVALIDATE Invalidates lprcUpdate or hrgnUpdate (only one may be non-
NULL). If both are NULL, the entire window is invalidated.

 
The following flags are used to validate the window.

Flag (validation) Description


RDW_NOERASE Suppresses any pending WM_ERASEBKGND messages.
RDW_NOFRAME Suppresses any pending WM_NCPAINT messages. This flag
must be used with RDW_VALIDATE and is typically used
with RDW_NOCHILDREN. RDW_NOFRAME should be
used with care, as it could cause parts of a window to be
painted improperly.
RDW_NOINTERNALPAINT Suppresses any pending internal WM_PAINT messages. This
flag does not affect WM_PAINT messages resulting from a
non-NULL update area.
RDW_VALIDATE Validates lprcUpdate or hrgnUpdate (only one may be non-
NULL). If both are NULL, the entire window is validated. This
flag does not affect internal WM_PAINT messages.

 
The following flags control when repainting occurs. RedrawWindow will not
repaint unless one of these flags is specified.

Flag Description
RDW_ERASENOW Causes the affected windows (as specified by the
RDW_ALLCHILDREN and RDW_NOCHILDREN flags) to
receiveWM_NCPAINT and WM_ERASEBKGND messages, if
necessary, before the function returns. WM_PAINT messages are
received at the ordinary time.
RDW_UPDATENOW Causes the affected windows (as specified by the
RDW_ALLCHILDREN and RDW_NOCHILDREN flags) to
receiveWM_NCPAINT, WM_ERASEBKGND,
and WM_PAINT messages, if necessary, before the function returns.

 
By default, the windows affected by RedrawWindow depend on whether the
specified window has the WS_CLIPCHILDREN style. Child windows that are
not the WS_CLIPCHILDREN style are unaffected; non-WS_CLIPCHILDREN
windows are recursively validated or invalidated until a WS_CLIPCHILDREN
window is encountered. The following flags control which windows are affected
by the RedrawWindow function.
Flag Description
RDW_ALLCHILDREN Includes child windows, if any, in the repainting operation.
RDW_NOCHILDREN Excludes child windows, if any, from the repainting
operation.

 
Return Value:
If the function succeeds, the return value is nonzero.If the function fails, the return value
is zero.

MAKEINTRESOURCE: Converts an integer value to a resource type compatible with the


resource-management functions. This macro is used in place of a string containing the name of
the resource.

Syntax: LPTSTR MAKEINTRESOURCE( WORD wInteger);

Parameters:

wInteger

The integer value to be converted.

Return Value:

The return value is the specified value in the low-order word and zero in the high-order
word.

LoadMenu: Loads the specified menu resource from the executable (.exe) file associated with
an application instance.

Syntax: HMENU WINAPI LoadMenu( HINSTANCE hInstance,PCTSTR


lpMenuName);

Parameters:

hInstance [in, optional]
HINSTANCE

A handle to the module containing the menu resource to be loaded.

lpMenuName [in]
LPCTSTR
The name of the menu resource. Alternatively, this parameter can consist of the
resource identifier in the low-order word and zero in the high-order word. To
create this value, use the MAKEINTRESOURCE macro.

Return Value:

If the function succeeds, the return value is a handle to the menu resource.If the function
fails, the return value is NULL

You might also like