Unformatted text preview:

Windows ProgrammingGetting StartedInside Visual C++John Hamill’s Visual Studio 6.0 DirectX Configuration GuideInstall C++ and DirectX SDKSelect Option in Tools MenuSelect Directories Tab and Show Directories Library FilesAdd the Directory where the DirectX libraries were installed “C:DXSDKLIB” by clicking the empty dashed box twiceClick the […] to browse for the location of the lib directory.Browse and select the folder where the DXSDKLIB is located Click OKHit Enter and then the up arrow key to leave […] input widgetClick the up arrow icon 2 times to move this to the topClick OKNow follow a similar procedure for the include directorySelect the Project->Setting…Select the Link tab Add “ddraw.lib dsound.lib dinput.lib dinput8.lib winmm.lib “ in the “Object/library modules:” field before all the other libraries that are already in this fieldNow build and run the program.DOS vs WindowsMicrosoft Hungarian NotationSlide 20These examples come from the LaMothe text.Command Line C++Windows VersionSlide 24Adviceint ncmdshowWindow ClassDeclare Windows FieldsCreating WindowsDisplaying the WindowEvent HandlerProcessing Messages - 1Processing Messages - 2Main Event LoopDifferent Main Event LoopProcessing MessagesTwo WaysAdd to SwitchMovable Window - 1Movable Window - 2Keyboard InputWM_CHARSlide 43Other Key MessagesWM_KEYDOWNMouse EventsMK_MOUSEMOVESlide 48Button Events1Windows ProgrammingCIS 577Bruce R. MaximUM-Dearborn2Getting Started•You need Visual C++ and installed on your computer, DirectX might be desirable (but not needed for the next assignment)•DirectX can be downloaded from the Internet•You will need to known the paths for the .lib and .h files on your computer (e.g. DXSDK/LIB and DXSDK/INCLUDES)3Inside Visual C++•You need to create a Win32 app workspace and use the project settings dialog box to adjust the directory links so that necessary .lib files are available during compliesWinmm.lib, Ddraw.lib, Dinput.lib, Dsound.lib•The runtime .dll files needs to be in the Windows/system32 directorywinmm.dll, Ddraw.dll, Dinput.dll, Dsound.dll4John Hamill’s Visual Studio 6.0 DirectX Configuration Guide5Install C++ and DirectX SDK•Install MS Visual Studio C++ 6.0•Install DirectX SDK 9.0. The installation puts it in C:\DXSDK by default.•Install the DirectX 9.0 runtime that comes with the DirectX SDK in the following area after DirectX is installed:C:\DXSDK\Redist\DirectX9\dxsetup.exe6Select Option in Tools Menu7Select Directories Tab and Show Directories Library Files8Add the Directory where the DirectX libraries were installed “C:\DXSDK\LIB” by clicking the empty dashed box twice9Click the […] to browse for the location of the lib directory.10Browse and select the folder where the DXSDK\LIB is locatedClick OK11Hit Enter and then the up arrow key to leave […] input widget12Click the up arrow icon 2 times to move this to the top13Click OK14Now follow a similar procedure for the include directory15Select the Project->Setting…16Select the Link tab Add “ddraw.lib dsound.lib dinput.lib dinput8.lib winmm.lib “ in the “Object/library modules:” fieldbefore all the other libraries that are already in this field17Now build and run the program.18DOS vs Windows•Windows is multi-tasking and supports multi-threaded applications•Windows programs are event driven which means they contain an infinite loop that continuously polls the system for events and messages19Microsoft Hungarian Notationc = charby = byten = int or shorti = intx,y = short coordscx,cy = short countsb = boolean (int)w = wordl = long worddw = double wordfu = functions = strings2,str = /0 terminated lp = 32 bit pointer20Microsoft Hungarian Notation•Function naming – capitalize first letter of each word•typedefs and constants done in all CAPS•Classes have capital C as a prefix21These examples come from the LaMothe text.22Command Line C++// DEMO2_1.CPP - standard version#include <stdio.h>// main entry point for all standard// DOS/console programsvoid main(void){printf("\nTHERE CAN BE ONLY ONE!!!\n");} // end main23Windows Version// DEMO2_2.CPP - a simple message box#define WIN32_LEAN_AND_MEAN #include <windows.h> // the main windows headers #include <windowsx.h> // a lot of cool macros // main entry point for all windows programsint WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)24Windows Version{// call message box api with NULL for parent// window handleMessageBox(NULL, //parent window handle "THERE CAN BE ONLY ONE!!!", //message string "MY FIRST WINDOWS PROGRAM", //window title MB_OK | MB_ICONEXCLAMATION); //style options // exit programreturn(0); } // end WinMain25Advice•You may need to add winmm.lib to your project for Win32 apps•You always need the the same first three lines in every Windows program•WinMain is a 32-bit function that use the Pascal calling convention and always must be defined like the example26int ncmdshow•SW_SHOW–Default size and position•SW_SHOWNORMAL–Default size and position •SW_SHOWMAXIMIZED–Display window max•SW_SHOWMINIMIZED–Display window min27Window Class•Everything in Windows programming is a window (even buttons and scrollbars)•You being by declaring a Window in WinMainWNDCLASSEX winclass; // this will hold the class we createHWND hwnd; // generic window handleMSG msg; // generic message28Declare Windows Fieldswinclass.cbSize = sizeof(WNDCLASSEX);winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; //set style winclass.lpfnWndProc = WindowProc; //set eventhandler winclass.cbClsExtra = 0;winclass.cbWndExtra = 0;winclass.hInstance = hinstance; //application instancewinclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);winclass.hCursor = LoadCursor(NULL, IDC_ARROW);winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);winclass.lpszMenuName = NULL;winclass.lpszClassName = WINDOW_CLASS_NAME;winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);29Creating Windows// register the window classif (!RegisterClassEx(&winclass)) return(0); // create the windowif (!(hwnd = CreateWindowEx(NULL, // extended style WINDOW_CLASS_NAME, // class "Your Basic Window", // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // initial x,y 400,400, // initial width, height NULL, // handle


View Full Document

U-M CIS 577 - Windows Programming

Download Windows Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Windows Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Windows Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?