Vous êtes sur la page 1sur 12

Q1. What is event driven programming? Ans.

Event Driven Programming:- In event-driven programming, code is executed upon activation of events. Event:-An event can be defined as a type of signal to the program that something has happened. The event is generated by external user actions such as mouse movements, mouse clicks, and keystrokes, or by the operating system, such as a timer.

Key features Event Handlers Trigger Functions Events Event Loops Forms Flexibility Service oriented Suitability for GUIs Simplicity of programming Time Driven

Example:The example displays a button in the frame. A message is displayed on the console when a button is clicked.

Main.cpp #include <windows.h> #include "head.h" /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{ HWND hwnd; MSG messages; /* This is the handle for our window */ /* Here messages to the application are saved */ /* Data structure for the windowclass */

WNDCLASSEX wincl;

/* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; /* This function is called by windows */

/* Catch double-clicks */

wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (hThisInstance, "MyIcon"); wincl.hIconSm = LoadIcon (hThisInstance, "MyIcon"); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = "MyMenu"; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; /* No menu */

/* No extra bytes after the window class */ /* structure or the window instance */

/* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0;

/* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ /* Classname */ /* Title Text */

szClassName,

"Untitled-Notepad",

WS_OVERLAPPEDWINDOW, /* default window */

CW_USEDEFAULT, CW_USEDEFAULT, 544, 375,

/* Windows decides the position */ /* where the window ends up on the screen */

/* The programs width */ /* and height in pixels */ /* The window is a child-window to desktop */

HWND_DESKTOP, NULL, hThisInstance, NULL );

/* No menu */ /* Program Instance handler */ /* No Window Creation data */

/* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); }

/* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HMENU hmenu; static HWND hedit; HDC hdc; char cBuf[256]; static int i;

switch (message) {

/* handle the messages */

case WM_CREATE:

hedit=CreateWindow("EDIT","",WS_CHILD|ES_MULTILINE|WS_VSCROLL,0,0,1280,1200,hwnd,(HMENU)E DIT_ID,NULL,NULL); ShowWindow(hedit,SW_SHOWNORMAL);

break;

/* case WM_COMMAND: switch(wParam) { case IDM_PROJECT: hmenu=GetMenu(hwnd);

CheckMenuItem(hmenu,IDM_PROJECT,MF_BYCOMMAND|MF_GRAYED);

case IDM_TOOLBAR: hmenu=GetMenu(hwnd); EnableMenuItem(hmenu,IDM_TOOLBAR,MF_BYCOMMAND|MF_ENABLED);

break; } */ case WM_DESTROY: PostQuitMessage (0); break; default: /* for messages that we don't deal with */ /* send a WM_QUIT to the message queue */

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

return 0; }

Head.h #define IDM_FILE 1007 #define IDM_NEW 1000 #define IDM_EXIT 1001 #define IDM_SMS 1002

#define IDM_MAL 1003 #define IDM_SAVE 1005 #define IDM_VIEW 1009 #define IDM_PROJECT 1010 #define IDM_TOOLBAR 1015 #define IDM_ALWSVISIBLE 1012 #define IDM_ONLY 1020 #define EDIT_ID 1000 #define IDM_OPEN 1200

Resource.rc #include "head.h"

MyIcon ICON notepad.ico

MyMenu MENU BEGIN POPUP "&File" BEGIN

MENUITEM "&New MENUITEM "&Open MENUITEM "&Save

Ctrl+N",IDM_NEW,CHECKED Ctrl+O",IDM_OPEN Ctrl+S",IDM_SAVE

MENUITEM "&Save As.....",IDM_OPEN MENUITEM SEPARATOR MENUITEM "&Page Setup.....",IDM_OPEN MENUITEM "&Print Ctrl+P",IDM_OPEN

MENUITEM "&Exit",IDM_SMS END

POPUP "&Edit" BEGIN MENUITEM "&Undo MENUITEM SEPARATOR MENUITEM "&Cut MENUITEM "&Copy MENUITEM "&Paste MENUITEM "&Delete MENUITEM SEPARATOR Ctrl+X",IDM_TOOLBAR,GRAYED Ctrl+C",IDM_TOOLBAR,GRAYED Ctrl+V",IDM_TOOLBAR,GRAYED Del",IDM_TOOLBAR,GRAYED Ctrl+Z",IDM_PROJECT,GRAYED

MENUITEM "Find.... MENUITEM "Find Next MENUITEM "Replace.... MENUITEM "Go To..... MENUITEM SEPARATOR MENUITEM "&Select All MENUITEM "&Time/Date END

Ctrl+F",IDM_ALWSVISIBLE F3",IDM_ONLY Ctrl+H",IDM_ONLY Ctrl+G ",IDM_ONLY

Ctrl+A",IDM_ONLY F5",IDM_ONLY

POPUP "Fo&rmat" BEGIN MENUITEM "&Word Wrap",IDM_PROJECT,CHECKED MENUITEM "&Font.... ",IDM_TOOLBAR

MENUITEM SEPARATOR END

POPUP "&View" BEGIN MENUITEM "&Status",IDM_PROJECT,GRAYED END

POPUP "&Help" BEGIN MENUITEM "&View Help",IDM_PROJECT MENUITEM SEPARATOR MENUITEM "&About Notepad",IDM_PROJECT

END END

The kernel provides the base OS functionality for any Windows based device. This functionality includes process, thread, and memory management. The kernel also provides some file management functionality. Kernel services enable applications to use this core functionality.

Use the kernel process and thread functions to create, terminate, and synchronize processes and threads, and to schedule and suspend a thread. Processes, which represent single instances of running applications, enable users to work on more than one application at a time. Threads enable an application to perform more than one task at a time. Thread priority levels, priority inheritance, interrupt support, and timing and scheduling are all included in the Windows kernel architecture. Together, they provide real-time application capability for time-critical systems.

The Windows kernel uses a paged virtual-memory system to manage and allocate program memory. The virtualmemory system provides contiguous blocks of memory, in 1,024-byte or 4,096-byte pages along 64-kilobyte (KB) regions, so that applications do not have to manage the actual memory allocation. For memory requirements of less than 64 KB, an application can use the local heap provided for all Windows applications or create separate heaps. The kernel also allocates memory to the stack for each new process or thread.

Use the kernel memory functions to allocate and deallocate virtual memory, use memory on the local heap, create separate heaps, and allocate memory from the stack. Code can use the unused memory from the static data block that is allocated to load the application. Processes also can use memory-mapped objects to share data.

(a) Modal Dialog Boxes: When a Modal dialog box is visible, it takes control from application (i.e. the user can switch to other running applications, but unable to switch to another window in the same application that created the dialog box). Modal dialog boxes are mostly used for prompting the user to make a selection, or to input some data. Normal type of dialog boxes created with Dialog Box or Dialog Box Par an () are called modal dialog boxes.

(b) System Modal Dialog Boxes : If you want the user to prevent him from switching to another program or program window, you must use the System modal dialog box. System modal dialog boxes take control of the entire Windows environment and wont allow any other application to receive messages or gain the input focus until this dialog box vanishes. These type of dialog boxes should be used only for serious error message because these dialog boxes wont permit other applications to rim. If the DS_SYSMODAL style is added to the dialog box definition. The dialog box becomes system modal.

1. Modeless dialog boxes are quite similar to popup windows as they remain on the screen for extended period of time and can gain and lose the input focus based on the users action . 2. These dialog boxes are used to display small toolbars and other utility windows. 3. These dialog boxes are created by using the Create Dialog () and Create Dialog Param function in place of Dialog Box () and Dialog box Param () functions respectively. 4. While using a modeless dialog box, the main programs message loop must be altered to include the IsDialogMessage() function to route messages for the dialog box to the dialog box message processing function.

Vous aimerez peut-être aussi