Windows Programming: Win32 / MFCPresentation GoalsWindows Programminghttp://msdn2.microsoft.com/en-us/library/aa383749(VS.85).aspxWhat is MFC?http://msdn2.microsoft.com/en-us/library/d06h2x6e(VS.80).aspxI Don’t Speak Hungarian!Hungarian Notation Continued...Hungarian Notation Pop QuizSlide 10Out With The Old…In With The New!Slide 13Slide 14A New Way (Win32 API)In With The New (MFC API)The Windows Programming ModelSlide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Messages, Messages, Messages…Console vs. Windows ApplicationNo More FakingWindows API or MFC API?Now What Can I Do?The Road Less Traveled…A more interesting example…Homework QuestionsWorks CitedWindows Programming:Win32 / MFCJames Adkison04/17/2008Presentation GoalsHow to create a basic Windows AppHungarian NotationHow to use the Win32 / MFC APIsWindows Programming ModelMessagesExamplesWindows ProgrammingWhere do I start?Use the Windows API (Win32 API)How do I use it?#include <windows.h>What about documentation?Google: msdn win32 apihttp://msdn2.microsoft.com/en-us/library/aa383749(VS.85).aspxWhat 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 <afxwin.h>Do NOT #include <windows.h> afxwin.h already includes ithttp://msdn2.microsoft.com/en-us/library/d06h2x6e(VS.80).aspxI Don’t Speak Hungarian!Hungarian Notation / Windows Data TypesWhat is it?A variable naming conventionExamplesh: handlen: integerb: booleanp: pointerHungarian Notation Continued...It’s important because Windows uses this notation thus most Windows/MFC programmers use it“It’s also common to prefix member variables with m_ so that it’s obvious whether a variable is a member of a class.”Hungarian Notation Pop QuizWhat is: nCount?What is: pnCountWhat is: bQuitWhat’s the difference? m_bQuit vs bQuitHungarian Notation Pop QuizWhat is: nCount?Integer: int CountWhat is: pnCountInteger pointer: int* CountWhat is: bQuitBoolean: BOOL QuitWhat’s the difference? m_bQuit vs bQuitbQuit is local, m_bQuit is a member of a ClassOut With The Old…In With The New!New “Hello World!” – Win32 APIint MessageBoxA( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);In With The New!New “Hello World!” – MFC API (Global)int AfxMessageBoxA( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0);In With The New!New “Hello World!” – MFC APIint MessageBoxA( LPCTSTR lpszText, LPCTSTR lpszCaption = 0, UINT nType = 0);MessageBoxA(“Hello World!”);A New Way (Win32 API)In With The New (MFC API)The WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemThe WindowsProgrammingModelNot ProceduralEvent-DrivenProcesses messages sent by the operating systemMessages, Messages, Messages…Console vs. Windows ApplicationConsole application’s entry pointint main(void)Windows application’s entry pointint WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)int main(int argc, char **argv)No More FakingTo this point we’ve used int main()We’ve used the Win32/MFC APIs to display a message box but we have not created a “Window” nor a Windows applicationWin32 App / Win32 Source MFC App / MFC SourceWindows API or MFC API?Essentially equivalent in functionalityGenerally, MFC will allow the programmer to do the same tasks more easilyMFC is an OO wrapper of Win32 APIMaybe neither… Win32 and MFC are being replaced by newer frameworks (e.g. .NET)Still lots of Win32/MFC application around, use MFC if possible.Now What Can I Do?Make a Windows programTake simple programs, like your early CS assignments and make it into a Windows appThis looks hard/complicated, why bother?Can’t 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 understandingThe Road Less Traveled…Knowing the more tedious details can have its advantages and produce some more interesting resultsWant to control a program that you didn’t write?Want to automate a process with program you didn’t write?A more interesting example…Final ExampleHomework QuestionsWhat 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 <windows.h>Works CitedProsise, Jeff. Programming Windows with MFC Second Edition. Redmond, Washington: Microsoft Press, 1999Microsoft Developer Network:
View Full Document