You are on page 1of 8

MULTILINE MESSAGE

EX NO :1
DATE :

AIM:
To display multiline message inside the window.

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. Type the coding.

6. Build and test the application.

MESSAGES:

 WM_PAINT
 WM_DESTROY

FUNCTIONS:

LoadIcon: Loads an icon for use by a program.

Syntax: HICON LoadIcon (HINSTANCE hInstance, LPCTSTR lpIconName);

Return Value:
If the function succeeds, the return value is a handle to the newly loaded icon.If the
function fails, the return value is NULL.

LoadCursor: Loads a mouse cursor for use by a program.

Syntax: HCURSOR LoadCursor (HINSTANCE hInstance, LPCTSTR lpCursorName);

Return Value:
If the function succeeds, the return value is the handle to the newly loaded cursor. If the
function fails, the return value is NULL.

GetStockObject: Obtains a graphic object, in this case a brush used for painting the window’s
background.

Syntax: HGDIOBJ GetStockObject (int fnObject );

Return Values:
If the function succeeds, the return value is a handle to the requested logical object. If
the function fails, the return value is NULL.

RegisterClass: Registers a window class for the program’s window.


Syntax: ATOM RegisterClass( CONST WNDCLASS *lpWndClass);

Return Value:
If the function succeeds, the return value is a class atom that uniquely identifies the
class being registered. If the function fails, the return value is zero.

CreateWindow: Creates a window based on a window class.

Syntax: HWND CreateWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName,


DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU
hMenu, HINSTANCE hInstance, LPVOID lpParam);

Return Value:
If the function succeeds, the return value is a handle to the new window. If the function
fails, the return value is NULL.

ShowWindow: Shows the window on the screen.

Syntax: BOOL ShowWindow ( HWND hwnd , int nCmdShow);


Return Value:
If the window was previously visible, the return value is nonzero. If the window was
previously hidden, the return value is zero.

UpdateWindow: Directs the window to paint itself.

Syntax: BOOL UpdateWindow( HWND hwnd);

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

GetMessage: Obtains a message from the message queue.

Syntax: BOOL GetMessage ( LPMSG lpMsg, HWND hwnd, UINT wMsgFilterMin , UINT
wMsgFilterMax);
Return Value: If the function retrieves a message other than WM_QUIT, the return value
is nonzero. If the function retrieves the WM_QUIT message, the return value is zero. If
there is an error, the return value is -1.

TranslateMessage: Translates some keyboard messages.

Syntax: BOOL TranslateMessage( const MSG *lpmsg );


Return Value:
If the message is translated (that is, a character message is posted to the thread's
message queue), the return value is nonzero. If the message is WM_KEYDOWN,
WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is nonzero,
regardless of the translation. If the message is not translated (that is, a character
message is not posted to the thread's message queue), the return value is zero.
DispatchMessage: Sends a message to a window procedure.

Syntax: LRESULT DispatchMessage( const MSG *lpmsg);


Return Value:
The return value specifies the value returned by the window procedure. Although its
meaning depends on the message being dispatched, the return value generally is
ignored.

PlaySound: Plays a sound file.

Syntax: BOOL PlaySound( LPCSTR pszSound, HMODULE hmod , DWORD fdwSound);

Return Values:

Returns TRUE if successful or FALSE otherwise.

BeginPaint: Initiates the beginning of window painting.

Syntax: HDC BeginPaint (HWND hwnd, LPPAINTSTRUCT lpPaint);

Return Values:
If the function succeeds, the return value is the handle to a display device context for the
specified window. If the function fails, the return value is NULL, indicating that no display
device context is available.
GetClientRect: Obtains the dimensions of the window’s client area.

Syntax: BOOL GetClientRect (HWND hWnd, LPRECT lpRect);

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

DrawText: Displays a text string.

Syntax: int DrawText (HDC hdc, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT
uFormat);

Return Values:
If the function succeeds, the return value is the height of the text in logical units. If
DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from lpRect-
>top to the bottom of the drawn text. If the function fails, the return value is zero.

EndPaint: Ends window painting.

Syntax: BOOL EndPaint (HWND hWnd, CONST PAINTSTRUCT *lpPaint);

Return Values:
The return value is always nonzero.

PostQuitMessage: Inserts a “quit” message into the message queue.

Syntax: void PostQuitMessage (int nExitCode);

Return Value: No return value.

DefWindowProc: Performs default processing of messages.

Syntax: LRESULT DefWindowProc (HWND hWnd, UINT Msg, WPARAM wParam,


LPARAM lParam);

Return Value:

The return value is the result of the message processing and depends on the message
EXPT NO : 1
NAME :
REG. NO. :

PROGRAM: To display multiline message

#include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,


PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;


wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName,
TEXT ("Multiline Message"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
350,
NULL,
NULL,
hInstance,
NULL) ;

ShowWindow (hwnd, iCmdShow) ;


UpdateWindow (hwnd) ;

while (GetMessage (&msg, NULL, 0, 0))


{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows XP!This is a multiline message.\nThis
is my first program in windows programming"), -1, &rect,
DT_CENTER | DT_WORDBREAK) ;
EndPaint (hwnd, &ps) ;
return 0 ;

case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
********************************OUTPUT*******************************

You might also like