Windows
Download
1 / 15

Lecture 9 windows - PowerPoint PPT Presentation


  • 239 Views
  • Uploaded on

Windows The Fun Stuff! MSG BOOL HWND HANDLE WNDCLASS LRESULT WPARAM LPARAM CALLBACK UINT New Data Types New Files #include <windows.h> Resource Files *.rc Custom Header Files *.h New Classes WNDCLASS structure declaration (data type) in windows.h

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 9 windows' - Gabriel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Windows l.jpg

Windows

The Fun Stuff!


New data types l.jpg

MSG

BOOL

HWND

HANDLE

WNDCLASS

LRESULT

WPARAM

LPARAM

CALLBACK

UINT

New Data Types


New files l.jpg
New Files

  • #include <windows.h>

  • Resource Files *.rc

  • Custom Header Files *.h


New classes l.jpg
New Classes

  • WNDCLASS

  • structure declaration (data type) in windows.h

  • contains members and pointers to functions for a basic window.


Encapsulation l.jpg
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.



Step 1 l.jpg
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


Bool initapplication handle hinstance l.jpg
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 );

  • wc.lpszMenuName = NULL;

  • wc.lpszClassName = szAppName;

  • if ( !RegisterClass ( &wc ) )

  • return ( FALSE );

  • return ( TRUE );

  • }


Step 2 l.jpg
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 window’s 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.


Bool initinstance handle hinstance int ncmdshow l.jpg
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 */

  • }


Back in main l.jpg
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).


Step 3 l.jpg
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.


Lresult callback mainwndproc hwnd hwnd uint message wparam wparam lparam lparam l.jpg
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 ) );

  • }

  • }


Windows messages l.jpg
WINDOWS MESSAGES

  • WM_COMMAND - Sent as the result of a mouse click or key press.

    • Carries as part of its structure, ID’s 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.


Flags l.jpg
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


ad