Windows Programming: Win32 / MFC - PowerPoint PPT Presentation

Loading...

PPT – Windows Programming: Win32 / MFC PowerPoint presentation | free to download - id: 5cb1cc-MTY1N



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Windows Programming: Win32 / MFC

Description:

Presentation Goals How to create a basic Windows App Hungarian Notation How to use the Win32 / MFC APIs Windows Programming Model Messages Examples Windows ... – PowerPoint PPT presentation

Number of Views:348
Avg rating:3.0/5.0
Slides: 34
Provided by: csUcfEdu9
Learn more at: http://www.cs.ucf.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Windows Programming: Win32 / MFC


1
Windows ProgrammingWin32 / MFC
  • James Adkison
  • 04/17/2008

2
Presentation Goals
  • How to create a basic Windows App
  • Hungarian Notation
  • How to use the Win32 / MFC APIs
  • Windows Programming Model
  • Messages
  • Examples

3
Windows Programming
  • Where do I start?
  • Use the Windows API (Win32 API)
  • How do I use it?
  • include ltwindows.hgt
  • What about documentation?
  • Google msdn win32 api

4
http//msdn2.microsoft.com/en-us/library/aa383749(
VS.85).aspx
5
What is MFC?
  • Microsoft Foundation Class
  • MFC is the C class library Microsoft provides
    to place an object-oriented wrapper around the
    Windows API.
  • How do I use it?
  • include ltafxwin.hgt
  • Do NOT include ltwindows.hgt afxwin.h already
    includes it

6
http//msdn2.microsoft.com/en-us/library/d06h2x6e(
VS.80).aspx
7
I Dont Speak Hungarian!
  • Hungarian Notation / Windows Data Types
  • What is it?
  • A variable naming convention
  • Examples
  • h handle
  • n integer
  • b boolean
  • p pointer

8
Hungarian Notation Continued...
  • Its important because Windows uses this notation
    thus most Windows/MFC programmers use it
  • Its also common to prefix member variables with
    m_ so that its obvious whether a variable is a
    member of a class.

9
Hungarian Notation Pop Quiz
  • What is nCount?
  • What is pnCount
  • What is bQuit
  • Whats the difference? m_bQuit vs bQuit

10
Hungarian Notation Pop Quiz
  • What is nCount?
  • Integer int Count
  • What is pnCount
  • Integer pointer int Count
  • What is bQuit
  • Boolean BOOL Quit
  • Whats the difference? m_bQuit vs bQuit
  • bQuit is local, m_bQuit is a member of a Class

11
Out With The Old
12
In With The New!
  • New Hello World! Win32 API
  • int MessageBoxA(
  • HWND hWnd,
  • LPCSTR lpText,
  • LPCSTR lpCaption,
  • UINT uType)

13
In With The New!
  • New Hello World! MFC API (Global)
  • int AfxMessageBoxA(
  • LPCTSTR lpszText,
  • UINT nType MB_OK,
  • UINT nIDHelp 0)

14
In With The New!
  • New Hello World! MFC API
  • int MessageBoxA(
  • LPCTSTR lpszText,
  • LPCTSTR lpszCaption 0,
  • UINT nType 0)
  • MessageBoxA(Hello World!)

15
A New Way (Win32 API)
16
In With The New (MFC API)
17
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

18
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

19
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

20
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

21
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

22
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

23
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

24
The WindowsProgrammingModel
  • Not Procedural
  • Event-Driven
  • Processes messages sent by the operating system

25
Messages, Messages, Messages
26
Console vs. Windows Application
  • Console applications entry point
  • int main(void)
  • Windows applications entry point
  • int WINAPI WinMain(
  • HINSTANCE hInstance,
  • HINSTANCE hPrevInstance,
  • LPSTR lpszCmdLine,
  • int nCmdShow)
  • int main(int argc, char argv)

27
No More Faking
  • To this point weve used int main()
  • Weve used the Win32/MFC APIs to display a
    message box but we have not created a Window
    nor a Windows application
  • Win32 App / Win32 Source
  • MFC App / MFC Source

28
Windows API or MFC API?
  • Essentially equivalent in functionality
  • Generally, MFC will allow the programmer to do
    the same tasks more easily
  • MFC is an OO wrapper of Win32 API
  • Maybe neither Win32 and MFC are being replaced
    by newer frameworks (e.g. .NET)
  • Still lots of Win32/MFC application around, use
    MFC if possible.

29
Now What Can I Do?
  • Make a Windows program
  • Take simple programs, like your early CS
    assignments and make it into a Windows app
  • This looks hard/complicated, why bother?
  • Cant I just use Visual Basic or use GUI tools to
    build my application (e.g. Windows Forms, VC)
  • Yes, but tools limit what you can do by hiding
    the details, limiting your understanding

30
The Road Less Traveled
  • Knowing the more tedious details can have its
    advantages and produce some more interesting
    results
  • Want to control a program that you didnt write?
  • Want to automate a process with program you
    didnt write?

31
A more interesting example
  • Final Example

32
Homework Questions
  • What do global MFC function calls begin with
    (i.e. what 3 letters)?
  • Where can you find Win32/MFC API documentation?
  • True or False, MFC applications should include
    ltwindows.hgt

33
Works Cited
  • Prosise, Jeff. Programming Windows with MFC
    Second Edition. Redmond, Washington Microsoft
    Press, 1999
  • Microsoft Developer Network http//msdn2.microsof
    t.com/en-us/library/default.aspx
About PowerShow.com