WINDOWS PROGRAMMING - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

WINDOWS PROGRAMMING

Description:

Combining data and the functions that process the data into a single entity. 'Data' refers to the members of a structure or CLASS that hold data. ... – PowerPoint PPT presentation

Number of Views:146
Avg rating:3.0/5.0
Slides: 19
Provided by: hermangr
Category:

less

Transcript and Presenter's Notes

Title: WINDOWS PROGRAMMING


1
WINDOWS PROGRAMMING
  • Where
  • the fun
  • starts

2
WINDOWS PROGRAMMING LANGUAGES
  • C C
  • BASIC VISUAL BASIC

3
Encapsulation
  • Combining data and the functions that process the
    data into a single entity.
  • Data refers to the members of a structure or
    CLASS that hold data.
  • Functions refer to pointers to functions
    included as members of a structure or CLASS
  • Window and Dialog Classes Provided by C are
    Actually Structures Set up this Way.

4
Writing a Windows Program
5
STEP BY STEP APPROACH
6
STEP 1
  • Initialize the Application . . .
  • Write a function that does the following
  • declare a variable of the WNDCLASS type
  • fill the members of that variable with values
    that customize your window
  • call the RegisterClass function, passing your
    class
  • return TRUE or FALSE (BOOL) to the main function,
    based upon whether RegisterClass was successful
    or not

7
BOOL InitApplication ( HANDLE hInstance )
WNDCLASS wc wc.style
CS_HREDRAW CS_VREDRAW wc.lpfnWndProc
MainWndProc wc.cbClsExtra
0 wc.cbWndExtra 0 wc.hInstance
hInstance wc.hIcon LoadIcon (
hInstance, IDI_APPLICATION ) wc.hCursor
LoadCursor ( NULL, IDC_ARROW
) wc.hbrBackground GetStockObject (
WHITE_BRUSH
8
BOOL InitApplication ( HANDLE hInstance )
  • wc.lpszMenuName NULL
  • wc.lpszClassName szAppName
  • if ( !RegisterClass ( wc ) )
  • return ( FALSE )
  • return ( TRUE )

9
STEP 2
  • Initialize an Instance of the Application
  • Write a function to do the following
  • Assign the current instance to a global variable
    for use by other windows and dialog boxes in the
    program.
  • Call the CreateWindow function, passing the App
    Name as specified in your class, the windows
    position and size, handles to parent and child
    windows and the handle to the current instance.
  • If the window could not be created, return FALSE,
    otherwise call the ShowWindow function to display
    the window.

10
BOOL InitInstance ( HANDLE hInstance, int
nCmdShow )
  • hInst hInstance / assign instance to
    global variable /
  • hWnd CreateWindow ( szAppName, / ClassName
    /
  • My Window", / window title /
  • WS_OVERLAPPEDWINDOW, / window style flag/
  • 70, / horizontal position
    /
  • 70, / vertical position
    /
  • 500, / window width /
  • 350, / window height /
  • NULL, / handle of parent
    window /
  • NULL, / handle of child or
    menu /
  • hInstance, / handle of app
    instance /
  • NULL ) / window creation
    data /
  • if ( !hWnd ) / If window could not be created,
    return "failure /
  • return ( FALSE )
  • ShowWindow ( hWnd, nCmdShow ) / Show the
    window /
  • return ( TRUE ) / Returns the
    value from PostQuitMessage /

11
BACK IN MAIN
  • Make Calls to Your InitApplication and
    InitInstance Functions.
  • Write a Windows Message Loop that Continuously
    Checks for New Messages (such as the click of a
    mouse button or press of a key on the keyboard)
  • When a Message is Received, the WNDCLASS Window
    you Created will Call the Window Procedure it
    points to (MainWndProc).

12
STEP 3
  • Handle the Windows Messages Received
  • Write MainWndProc, which does the following
  • Use nested switch constructs to handle valid
    windows messages expected by the main window.
  • Makes calls to other procedures such as Dialog
    Box procedures, when necessary for handling
    messages to other resources.

13
LRESULT CALLBACK MainWndProc ( HWND hWnd,
UINT message,WPARAM wParam, LPARAM
lParam )
  • switch ( message )
  • case WM_COMMAND / Menu Selection or Dialog
    Box Control /
  • switch (wParam)
  • case CM_EXIT / ID of the EXIT
    menu item /
  • DestroyWindow ( hWnd )
  • case CM_MESSAGE_TO_SCREEN / another menu
    item /
  • MessageBox( hWnd, "Message Text",
    Message Title", MB_OK)
  • default
  • return ( DefWindowProc ( hWnd, message,
    wParam, lParam ) )
  • default
  • return ( DefWindowProc ( hWnd, message, wParam,
    lParam ) )

14
WINDOWS MESSAGES
  • WM_COMMAND - Sent as the result of a mouse click
    or key press.
  • Carries as part of its structure, IDs of Menu
    Items, Buttons or Dialog Box Controls selected by
    the mouse or keyboard.
  • Other messages can be sent to a window or dialog
    box by a call to a function inside the program
    telling the object to behave a certain way.

15
FLAGS
  • Determine Window Style or Behavior
  • Can Be Grouped in a Single Call to a Creation
    Function in Order to Add Functionality to a
    Window
  • hWnd CreateWindow ( szAppName, / ClassName
    /
  • My Window", / window title /
  • WS_OVERLAPPEDWINDOW, / window style flag/
  • 70, / horizontal position
    /
  • 70, / vertical position
    /
  • 500, / window width /
    etc...
  • Flags are Names for an Underlying Number
    Created with define in windows.h

16
New Data Types
  • MSG
  • BOOL
  • HWND
  • HANDLE
  • WNDCLASS
  • LRESULT
  • WPARAM
  • LPARAM
  • CALLBACK
  • UINT

17
New Files
  • include ltwindows.hgt
  • Resource Files .rc
  • Custom Header Files .h

18
New Classes
  • WNDCLASS
  • structure declaration (data type) in windows.h
  • contains members and pointers to functions for a
    basic window.
Write a Comment
User Comments (0)
About PowerShow.com