100% found this document useful (1 vote)
65 views21 pages

Is INDIA /: 1) / This Program Displays The Static Window Whose Caption

The document contains code for 5 different Windows programs that demonstrate various Windows API functions: 1) Creates a static window with caption "INDIA" and displays it. 2) Dynamically creates a window with class "RJ", registers the window class, and displays a message box on window creation. 3) Demonstrates use of accelerators, pens, brushes, and drawing lines and rectangles. Menu and resource files are included. 4) Displays typed characters and demonstrates non-printable keys like backspace, space, and home. 5) Demonstrates using mouse buttons by displaying click coordinates on left and right button down.

Uploaded by

Gurteg Singh
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 DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
65 views21 pages

Is INDIA /: 1) / This Program Displays The Static Window Whose Caption

The document contains code for 5 different Windows programs that demonstrate various Windows API functions: 1) Creates a static window with caption "INDIA" and displays it. 2) Dynamically creates a window with class "RJ", registers the window class, and displays a message box on window creation. 3) Demonstrates use of accelerators, pens, brushes, and drawing lines and rectangles. Menu and resource files are included. 4) Displays typed characters and demonstrates non-printable keys like backspace, space, and home. 5) Demonstrates using mouse buttons by displaying click coordinates on left and right button down.

Uploaded by

Gurteg Singh
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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

1)/*This Program displays the static Window Whose caption is INDIA*/

#include<windows.h> int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow) { WNDCLASS wnd; MSG msg; HWND hWnd; int i; hWnd=CreateWindow("BUTTON","INDIA",WS_OVERLAPPEDWINDOW,200,200,200,200,NULL,N ULL,hInstance,NULL); for(i=0;i<10000000;i++) { ShowWindow(hWnd,SW_NORMAL); } return 0; }

2)/* This Program illustrates the dynamic creation of the Window and the diaplay of the Message Box */
#include<windows.h> long FAR PASCAL WndProc(HWND,WORD,WORD,LONG); int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow) { WNDCLASS wnd; MSG msg; HWND hWnd;

if(!hPrevInstance) { wnd.style=CS_HREDRAW|CS_VREDRAW; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hInstance=hInstance; wnd.lpfnWndProc=(WNDPROC)WndProc; wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION); wnd.hCursor=LoadCursor(NULL,IDC_ARROW); wnd.hbrBackground=GetStockObject(WHITE_BRUSH); wnd.lpszClassName="RJ"; wnd.lpszMenuName=NULL; if(!RegisterClass(&wnd)) { MessageBox(hWnd,"error","ERDCI",MB_OKCANCEL); return 0; } }

hWnd=CreateWindow("RJ","hello",WS_OVERLAPPEDWINDOW,100,100,200,200,NULL,NULL,hInstance,N ULL); ShowWindow(hWnd,SW_SHOWNORMAL); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg);

} return 0; } long FAR PASCAL WndProc(HWND hWnd,WORD wMessage,WORD wParam,long lParam) { HDC hdc; char str[]="Hello"; HPEN hPen; switch(wMessage) { case WM_CREATE: MessageBox(hWnd,"Create Window","ERDCI",MB_OKCANCEL); break; case WM_DESTROY: PostQuitMessage(0); break; default:return DefWindowProc(hWnd,wMessage,wParam,lParam);

3) /*This Program illustrates the usage of : 1)Accelerator Key 2)Creation of Pens and Brushes 3)Creation/Display of Line and Rectangle*/

#include<windows.h> #include<stdio.h> #include "Lab3.h" long FAR PASCAL WndProc(HWND,WORD,WORD,LONG); int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow) { WNDCLASS wnd; MSG msg; HWND hWnd; HMENU hmenu; HACCEL haccel; int i; if(!hPrevInstance) { wnd.style=CS_HREDRAW|CS_VREDRAW; wnd.lpfnWndProc=(WNDPROC)WndProc; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hInstance=hInstance; wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION); wnd.hCursor=LoadCursor(NULL,IDC_ARROW); wnd.hbrBackground=GetStockObject(WHITE_BRUSH); wnd.lpszMenuName="ERDCI"; wnd.lpszClassName="PPC";

if(!RegisterClass(&wnd)) return 0; } hmenu=LoadMenu(hInstance,"ERDCI"); hWnd=CreateWindow("PPC","ERDCI",WS_OVERLAPPEDWINDOW,200,200,200,200,NULL,NULL, hInstance,NULL); SetMenu(hWnd,hmenu); haccel=LoadAccelerators(hInstance,"ERDCI"); ShowWindow(hWnd,SW_SHOWMAXIMIZED);

while(GetMessage(&msg,0,0,0)) { if(!TranslateAccelerator(hWnd,haccel,&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return(msg.wParam); } long FAR PASCAL WndProc(HWND hWnd,WORD wMessage,WORD wParam,LONG lparam) { HDC hdc; PAINTSTRUCT ps; HPEN hpen; HBRUSH hBrush;

HFONT hfont; UINT num11; UINT num22; UINT num33; int num1; char str[255]=" "; hpen=CreatePen(PS_SOLID,4,RGB(255,0,0)); hBrush=CreateSolidBrush(RGB(0,255,0)); switch(wMessage) { case WM_COMMAND: switch(wParam) { case ID_DISP:hdc=GetDC(hWnd); TextOut(hdc,0,0,"hello",5); ReleaseDC(hWnd,hdc); break; case ID_MSG:MessageBox(hWnd,"Thank you for using Windows","rahul", MB_OK); break; case ID_QUIT:DestroyWindow(hWnd); break; case ID_LINE:hdc=GetDC(hWnd); SelectObject(hdc,hpen); LineTo(hdc,0,100);//Draws Vertical line LineTo(hdc,100,0);//if above line is not there then this line draws Horizontal Line

break; case ID_RECT:hdc=GetDC(hWnd); SelectObject(hdc,hpen); SelectObject(hdc,hBrush); Rectangle(hdc,10,100,100,200); break; } break; case WM_PAINT:hdc=BeginPaint(hWnd,&ps); TextOut(hdc,0,0,"World",5); EndPaint(hWnd,&ps); break;

case WM_DESTROY:PostQuitMessage(0); break; default:return DefWindowProc(hWnd,wMessage,wParam,lparam); } return(0L); }

/* CODE FOR .h FILE :#define ID_DISP 1 #define ID_MSG 2

#define ID_LINE 3 #define ID_RECT #define ID_QUIT 4 5

long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);*/

/*CODE FOR .RC FILE #include "Lab3.h" ERDCI MENU BEGIN MENUITEM "&DISPLAY",ID_DISP MENUITEM "&MESSAGE",ID_MSG POPUP "&IMAGES" BEGIN MENUITEM "&LINE",ID_LINE MENUITEM "&RECTANGLE",ID_RECT END MENUITEM "&QUIT",ID_QUIT END ERDCI ACCELERATORS BEGIN "a",ID_LINE,SHIFT "^b",ID_RECT,CONTROL END*/

4)/*This Program displays illustrates the usage of Keyboard to demonstrate the functioning of Printable Character Keys to display the

Alphabets/Numbers typed by the user on the WAP and it also illustrates the functioning of Non-printable character key such as Backspace Key.Spacebar Key,CANCEL(Ctrl+Break) and HOME Key*/
#include<windows.h> static char arr9[100]; PAINTSTRUCT ps; HDC hdc; static char str[26]; static int num1; int arr1; long FAR PASCAL WndProc(HWND,UINT,WPARAM,LPARAM); int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow) { WNDCLASS wnd; HWND hWnd; int i; MSG msg;

if(!hPrevInstance) { wnd.style=CS_HREDRAW|CS_VREDRAW; wnd.lpfnWndProc=(WNDPROC)WndProc; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hInstance=hInstance;

wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION); wnd.hCursor=LoadCursor(NULL,IDC_ARROW); wnd.hbrBackground=GetStockObject(BLACK_BRUSH); wnd.lpszMenuName=NULL; wnd.lpszClassName="RJ";

if(!RegisterClass(&wnd)) { MessageBox(hWnd,"Errrrrrrr","Rahul",MB_OKCANCEL); return 0; } }

hWnd=CreateWindow("RJ","ERDCI",WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL|W S_SYSMENU,200,200,200,200,NULL,NULL,hInstance,NULL); ShowWindow(hWnd,SW_SHOWMAXIMIZED); while(GetMessage(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } long FAR PASCAL WndProc(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) { hdc=GetDC(hWnd);

switch(msg) { case WM_CHAR : if(num1<26 &&IsCharAlphaNumeric((char)wparam)) { str[num1++]=(char)wparam; str[num1]=0; InvalidateRect(hWnd,NULL,TRUE); } break; case WM_PAINT: hdc=BeginPaint(hWnd,&ps); SetTextColor(hdc,RGB(255,0,0)); TextOut(hdc,0,0,str,strlen(str)); EndPaint(hWnd,&ps); break; case WM_KEYDOWN: { switch(wparam) { case VK_BACK: if(num1>0) { num1--; str[num1]=0;

InvalidateRect(hWnd,NULL,TRUE); } break; case VK_SPACE: if(num1>0) { str[num1++]=' '; InvalidateRect(hWnd,NULL,TRUE); } break; case VK_HOME: if(num1>0) { num1=0; InvalidateRect(hWnd,NULL,TRUE); } break; case VK_CANCEL: { DestroyWindow(hWnd); } break; case VK_TAB: if(num1>0) {

arr1=num1+4; str[arr1]=' '; InvalidateRect(hWnd,NULL,TRUE); } /*case VK_RETURN:

if(num1>0) { for(int j=0;str[j]!='\0';j++) { num1=j

}*/ }

break; } case WM_DESTROY: PostQuitMessage(0); break;

default:return DefWindowProc(hWnd,msg,wparam,lparam); }

5) /*This Program illustrates the usage of :Mouse Buttons as it displays the HOTSPOT i.e the x and y position where the user has clicked has Left or Right Mouse Button */
#include<windows.h> #include<stdio.h> #include "Lab5.h" long FAR PASCAL WndProc(HWND,WORD,WORD,LONG); int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow) { WNDCLASS wnd; MSG msg; HWND hWnd; HMENU hmenu; HACCEL haccel; int i; if(!hPrevInstance) { wnd.style=CS_HREDRAW|CS_VREDRAW; wnd.lpfnWndProc=(WNDPROC)WndProc; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hInstance=hInstance; wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION); wnd.hCursor=LoadCursor(NULL,IDC_ARROW); wnd.hbrBackground=GetStockObject(WHITE_BRUSH);

wnd.lpszMenuName="ERDCI"; wnd.lpszClassName="PPC"; if(!RegisterClass(&wnd)) return 0; } hmenu=LoadMenu(hInstance,"ERDCI"); hWnd=CreateWindow("PPC","ERDCI",WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, 200,200,200,200,NULL,NULL,hInstance,NULL); SetMenu(hWnd,hmenu); haccel=LoadAccelerators(hInstance,"ERDCI"); ShowWindow(hWnd,SW_SHOWMAXIMIZED);

while(GetMessage(&msg,0,0,0)) { if(!TranslateAccelerator(hWnd,haccel,&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return(msg.wParam); } long FAR PASCAL WndProc(HWND hWnd,WORD wMessage,WORD wParam,LONG lparam) { HDC hdc; PAINTSTRUCT ps;

HPEN hpen; HBRUSH hBrush; HFONT hfont; UINT num11; UINT num22; UINT num33; int num1; char str[255]=" "; hpen=CreatePen(PS_SOLID,4,RGB(255,0,0)); hBrush=CreateSolidBrush(RGB(0,255,0)); switch(wMessage) { case WM_COMMAND: switch(wParam) { case ID_DISP:hdc=GetDC(hWnd); TextOut(hdc,0,0,"hello",5); ReleaseDC(hWnd,hdc); break; case ID_MSG:MessageBox(hWnd,"Thank you for using Windows","rahul", MB_OK); break; case ID_QUIT:DestroyWindow(hWnd); break; case ID_LINE:hdc=GetDC(hWnd); SelectObject(hdc,hpen);

LineTo(hdc,0,100);//Draws Vertical line LineTo(hdc,100,0);//if above line is not there then this line draws Horizontal Line break; case ID_RECT:hdc=GetDC(hWnd); SelectObject(hdc,hpen); SelectObject(hdc,hBrush); Rectangle(hdc,10,100,100,200); break; } break; case WM_VSCROLL: { switch(LOWORD(wParam)) { case SB_LINEUP:MessageBox(hWnd,"Scroll Bar is at the top","SCROLLBAR",MB_OK); break; case SB_LINEDOWN:MessageBox(hWnd,"Scroll Bar is at the bottom","SCROLLBAR",MB_OK); break; case SB_PAGEUP:MessageBox(hWnd,"Scroll Bar is B/W Top & Middle","SCROLLBAR",MB_OK); break; case SB_PAGEDOWN:MessageBox(hWnd,"Scroll Bar is B/W Middle & Bottom","SCROLLBAR",MB_OK); break; } }

break; case WM_HSCROLL: switch(LOWORD(wParam)) { case SB_LINEUP:MessageBox(hWnd,"Scroll Bar is on the Left","SCROLLBAR",MB_OK); break; case SB_LINEDOWN:MessageBox(hWnd,"Scroll Bar is on the right","SCROLLBAR",MB_OK); break; case SB_PAGEUP:MessageBox(hWnd,"Scroll Bar is B/W Left & Middle","SCROLLBAR",MB_OK); break; case SB_PAGEDOWN:MessageBox(hWnd,"Scroll Bar is B/W Center & Right","SCROLLBAR",MB_OK); break; } break; case WM_PAINT:hdc=BeginPaint(hWnd,&ps); TextOut(hdc,0,0,"World",5); EndPaint(hWnd,&ps); break; case WM_LBUTTONDOWN: num11=LOWORD(lparam); num22=HIWORD(lparam); hdc=GetDC(hWnd); sprintf(str,"Left button is down at %d,%d",num11,num22); TextOut(hdc,num11,num22,str,strlen(str)); ReleaseDC(hWnd,hdc);

break; case WM_RBUTTONDOWN: num11=LOWORD(lparam); num22=HIWORD(lparam); hdc=GetDC(hWnd); sprintf(str,"Right button is down at %d,%d",num11,num22); TextOut(hdc,num11,num22,str,strlen(str)); ReleaseDC(hWnd,hdc); break; case WM_LBUTTONDBLCLK: num11=LOWORD(lparam); num22=HIWORD(lparam); num33=GetDoubleClickTime(); sprintf(str,"The Double click Time is %d",num33); TextOut(hdc,0,0,str,strlen(str)); hdc=GetDC(hWnd); sprintf(str,"The Left Button Double click occurred at %d,%d",num11,num22); TextOut(hdc,num11,num22,str,strlen(str)); ReleaseDC(hWnd,hdc); break; case WM_RBUTTONDBLCLK: num11=LOWORD(lparam); num22=HIWORD(lparam); num33=GetDoubleClickTime(); sprintf(str,"The Double click Time is %d",num33);

hdc=GetDC(hWnd); sprintf(str,"The Right Button Double click occurred at %d,%d",num11,num22); TextOut(hdc,num11,num22,str,strlen(str)); ReleaseDC(hWnd,hdc); break;

case WM_DESTROY:PostQuitMessage(0); break; default:return DefWindowProc(hWnd,wMessage,wParam,lparam); } return(0L); }

/* CODE FOR .h FILE :#define ID_DISP 1 #define ID_MSG #define ID_LINE 3 #define ID_RECT #define ID_QUIT 4 5 2

long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);*/

/*CODE FOR .RC FILE #include "Lab3.h"

ERDCI MENU BEGIN MENUITEM "&DISPLAY",ID_DISP MENUITEM "&MESSAGE",ID_MSG POPUP "&IMAGES" BEGIN MENUITEM "&LINE",ID_LINE MENUITEM "&RECTANGLE",ID_RECT END MENUITEM "&QUIT",ID_QUIT END ERDCI ACCELERATORS BEGIN "a",ID_LINE,SHIFT "^b",ID_RECT,CONTROL END*/

You might also like