Assignmnet No 3

download Assignmnet No 3

of 12

Transcript of Assignmnet No 3

  • 7/31/2019 Assignmnet No 3

    1/12

    Q1. What is event driven programming?

    Ans. Event Driven Programming:- In event-driven programming, code is executed upon activation of

    events.

    Event:-An eventcan 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

  • 7/31/2019 Assignmnet No 3

    2/12

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

    clicked.

    Main.cpp

    #include

    #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; /* This is the handle for our window */

    MSG messages; /* Here messages to the application are saved */

    WNDCLASSEX wincl; /* Data structure for the windowclass */

  • 7/31/2019 Assignmnet No 3

    3/12

    /* The Window structure */

    wincl.hInstance = hThisInstance;

    wincl.lpszClassName = szClassName;

    wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */

    wincl.style = CS_DBLCLKS; /* 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"; /* No menu */

    wincl.cbClsExtra = 0; /* No extra bytes after the window class */

    wincl.cbWndExtra = 0; /* 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 */

    szClassName, /* Classname */

    "Untitled-Notepad", /* Title Text */

    WS_OVERLAPPEDWINDOW, /* default window */

  • 7/31/2019 Assignmnet No 3

    4/12

    CW_USEDEFAULT, /* Windows decides the position */

    CW_USEDEFAULT, /* where the window ends up on the screen */

    544, /* The programs width */

    375, /* and height in pixels */

    HWND_DESKTOP, /* The window is a child-window to desktop */

    NULL, /* No menu */

    hThisInstance, /* Program Instance handler */

    NULL /* 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() */

  • 7/31/2019 Assignmnet No 3

    5/12

    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);

  • 7/31/2019 Assignmnet No 3

    6/12

    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); /* send a WM_QUIT to the message queue */

    break;

    default: /* for messages that we don't deal with */

    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

  • 7/31/2019 Assignmnet No 3

    7/12

    #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 Ctrl+N",IDM_NEW,CHECKED

    MENUITEM "&Open Ctrl+O",IDM_OPEN

    MENUITEM "&Save Ctrl+S",IDM_SAVE

    MENUITEM "&Save As.....",IDM_OPEN

    MENUITEM SEPARATOR

    MENUITEM "&Page Setup.....",IDM_OPEN

    MENUITEM "&Print Ctrl+P",IDM_OPEN

  • 7/31/2019 Assignmnet No 3

    8/12

    MENUITEM "&Exit",IDM_SMS

    END

    POPUP "&Edit"

    BEGIN

    MENUITEM "&Undo Ctrl+Z",IDM_PROJECT,GRAYED

    MENUITEM SEPARATOR

    MENUITEM "&Cut Ctrl+X",IDM_TOOLBAR,GRAYED

    MENUITEM "&Copy Ctrl+C",IDM_TOOLBAR,GRAYED

    MENUITEM "&Paste Ctrl+V",IDM_TOOLBAR,GRAYED

    MENUITEM "&Delete Del",IDM_TOOLBAR,GRAYED

    MENUITEM SEPARATOR

    MENUITEM "Find.... Ctrl+F",IDM_ALWSVISIBLE

    MENUITEM "Find Next F3",IDM_ONLY

    MENUITEM "Replace.... Ctrl+H",IDM_ONLY

    MENUITEM "Go To..... Ctrl+G ",IDM_ONLY

    MENUITEM SEPARATOR

    MENUITEM "&Select All Ctrl+A",IDM_ONLY

    MENUITEM "&Time/Date F5",IDM_ONLY

    END

    POPUP "Fo&rmat"

    BEGIN

    MENUITEM "&Word Wrap",IDM_PROJECT,CHECKED

    MENUITEM "&Font.... ",IDM_TOOLBAR

  • 7/31/2019 Assignmnet No 3

    9/12

  • 7/31/2019 Assignmnet No 3

    10/12

  • 7/31/2019 Assignmnet No 3

    11/12

    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 virtual-

    memory 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.

  • 7/31/2019 Assignmnet No 3

    12/12

    (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.