Function Prototypes - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Function Prototypes

Description:

Register Class. if (!RegisterClass (&wndclass)) { MessageBox ... hwnd = CreateWindow(szAppName, //set above. TEXT('The Hello Program'), //caption ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 14
Provided by: phi140
Category:

less

Transcript and Presenter's Notes

Title: Function Prototypes


1
Function Prototypes
  • include ltwindows.hgt
  • LRESULT CALLBACK WndProc (HWND, UINT, WPARAM,

    LPARAM)
  • Int WinAPI WinMain(HINSTANCE hInstance,
  • HINSTANCE hPrevInstance,
  • PSTR szCmdLine,
  • int iCmdShow)

2
Variable Declarations
  • static TCHAR szAppName TEXT(HelloWin)
  • HWND hwnd
  • MSG msg
  • WNDCLASS wndclass

3
Fill in Class Characteristics
  • wndclass.style CS_HREDRAW CS_VREDRAW
  • wndclass.lpfnWndProc WndProc
  • .
  • wndclass.hInstance hInstance
  • wndclass.hIcon LoadIcon(NULL,
    IDI_APPLICATION)
  • wndclass.hCursor LoadCursor(NULL, ID_ARROW)
  • wndclass.hbrBackground (HBRUSH)
  • GetStockObject(WHITE_BRUSH)
  • wndclass.lpszClassName szAppName //class name

4
Register Class
  • if (!RegisterClass (wndclass))
  • MessageBox (..)
  • return 0

5
Create Window
  • hwnd CreateWindow(szAppName, //set above
  • TEXT(The Hello Program), //caption
  • WS_OVERLAPPEDWINDOW, //style
  • CW_USEDEFAULT, // initial x
  • CW_USEDEFAULT, // initial y
  • CW_USEDEFAULT, // initial x size
  • CW_USEDEFAULT, // initial y size
  • NULL, //parent window handle
  • NULL, // window menu handle
  • hInstance, // program instance
    handle
  • NULL // creation parameters)

6
Display Window on Screen
  • ShowWindow(hwnd, icmdShow) // normal,
    min, max
  • UpdateWindow(hwnd) //Paint yourself.

7
Message Loop
  • while (GetMessage (msg, NULL, 0, 0,)
  • TranslateMessage(msg)
  • DispatchMessage(msg)
  • return (msg.wParam)
  • // end of WinMain

8
Message Data Structure
typedef struct tagMSG HWND hwnd UINT
message WPARAM wParam LPARAM
lParam DWORD time POINT pt
MSG
9
Message Processing Function
  • //Associated with window class.
  • LRESULT CALLBACK WndProc(
  • HWND hwnd,
  • UINT message,
  • WPARAM wParam,
  • LPARAM lParam)

10
Variables in WndProc
  • HDC hdc // window to receive msg.
  • PAINTSTRUCT ps // Used by OS
  • RECT rect // top, bottom, right, left
  • // Determine if care about msg.

11
Message Handlers
  • switch(message)
  • case WM_CREATE
  • PlaySound(TEXT(hellowin.wav),
  • NULL, SND_FILENAME SND_ASYNC)
  • return 0

12
WM_PAINT
  • case WM_PAINT
  • hdc BeginPaint(hwnd, ps)
  • GetClientRect(hwnd, rect)
  • DrawText(hdc, TEXT(Hello), -1, rect,
  • DT_SINGLELINE DT_CENTER DT_VCENTER)
  • EndPaint(hwnd, ps)
  • return 0

13
Default Processing
  • case WM_DESTROY //generated when user exits
  • PostQuitMessage (0)
  • return 0
  • // END OF SWITCH
  • return DefWindowProc(hwnd, message, wParam,
    lParam) // catches all messages not //
    processed in WndProc.
Write a Comment
User Comments (0)
About PowerShow.com