Beruflich Dokumente
Kultur Dokumente
11.01.08
PROBLEM DEFINITION:
To Write a VC ++ program by using Win32 application for creating a Simple Message Box and a Simple Window.
The most important and most basic of these header files are:
WINDEF.H Basic type definitions. WINNT.H Type definitions for Unicode support. WINBASE.H Kernel functions. WINUSER.H User interface functions. WINGDI.H Graphics device interface functions.
The MessageBox Function : The MessageBox function is designed to display short messages. MessageBox (NULL, TEXT("Hello, Windows 98!"),TEXT ("HelloMsg"), 0); The first argument to MessageBox is normally a window handle. The second argument is the text string in the body of the message box The third argument is the text string in the caption bar of the message box. The fourth argument to MessageBox can be a combination of constants beginning with the prefix MB_ that are defined in WINUSER.H. Program Entry Point Just as the entry point to a C program is the function main, the entry point to a Windows program is WinMain, which always appears like this: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 1. 2. 3. 4. hInstance ->instance handle. hPrevInstance -> previous instance handle. szCmdLine -> command line iCmdShow ->display style of the window.
PROCEDURAL ALGORITHM :
1.Select Start-> Programs-> Visual studio 6.0-> Visual C++ Developer Studio. 2.Select New from the File menu. 3.To begin, select New from the File menu. 4.In the New dialog box, pick the Projects tab. Select Win32 Application. 5.In the Location field, select a subdirectory. 6.In the Project Name field, type the name of the project. 7.The Create New Workspace button should be checked. 8.The Platforms section should indicate Win32. Choose OK. 9.A dialog box labeled Win32 Application - Step 1 Of 1 will appear. 10. Indicate that you want to create an Empty Project, and press the Finish button. 11. Select New from the File menu again. 12. In the New dialog box, pick the Files tab. 13. Select C++ Source File. The Add To Project box should be checked, and name of the project should be indicated. 15. Type the name of the file name in the File Name field and Choose OK. 16. Now start to type the source code in .C extention file. 17. To compile the file, select Build .exe from the Build menu, or press F7. Select Execute .exe from the Build menu or press ctrl+F5 or click Execute program icon from the Build tool bar to execute the program.
14.
18.
OUTPUT:
Simple Window :
#include<windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, PSTR szCmdLine,int iCmdShow) { static TCHAR szName[]=TEXT("Sample Window"); 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=szName; if(!RegisterClass(&wndclass)) { t MessageBox(NULL,TEXT("This requires to register all the parameter of the window class"),szName,MB_ICONERROR); return 0;} hwnd=CreateWindow(szName,TEXT("SampleWindowprogram") , WS_OVERLA PPEDWINDOW, 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 wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(message) { case WM_CREATE: return 0; case WM_PAINT:
WndProc(HWND
hwnd,UINT
message,WPARAM
OUTPUT:
RESULT:
Thus the program for creating a simple message Box and simple window program was executed successfully.