Você está na página 1de 3

#include <windows.

h>
#include"resource.h"

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

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR


szCmdLine, int iCmdShow)
{

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 = MAKEINTRESOURCE(IDR_MENU1) ;
wndclass.lpszClassName = TEXT("Hello Windows Programming") ;
if (!RegisterClass (&wndclass))
return 0 ;

hwnd = CreateWindow (TEXT("Hello Windows


Programming"),TEXT("Paint"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,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)
{

switch(message)
{
case WM_COMMAND:
switch(wParam)
{
case IDM_SHOW:
hdc=GetDC(hwnd);
TextOut(hdc,10,10,TEXT("Menu pressed"),lstrlen(TEXT("Menu
pressed")));
ReleaseDC(hwnd,hdc);

break;
case IDM_QUIT:
DestroyWindow(hwnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;

default:

return DefWindowProc (hwnd, message, wParam, lParam) ;


}
return 0;
}

Program 5

#include <windows.h>
#include"resource.h"

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

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR


szCmdLine, int iCmdShow)
{

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 = MAKEINTRESOURCE(IDR_MENU1) ;
wndclass.lpszClassName = TEXT("Hello Windows Programming") ;
if (!RegisterClass (&wndclass))
return 0 ;

hwnd = CreateWindow (TEXT("Hello Windows


Programming"),TEXT("Paint"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,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;

switch(message)
{
case WM_COMMAND:
switch(wParam)
{
case IDM_SHOW:
hdc=GetDC(hwnd);
TextOut(hdc,10,10,TEXT("Menu pressed"),lstrlen(TEXT("Menu
pressed")));
ReleaseDC(hwnd,hdc);

break;
case IDM_QUIT:
DestroyWindow(hwnd);
break;
}
break;
case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,10,40,TEXT("This text is output when WM_PAINT is received."),40);
EndPaint(hwnd,&ps);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default:

return DefWindowProc (hwnd, message, wParam, lParam) ;


}
return 0;
}