Presentation is loading. Please wait.

Presentation is loading. Please wait.

IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.

Similar presentations


Presentation on theme: "IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE."— Presentation transcript:

1 IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE YOU LEAVE LAB. (ALWAYS bring your book to lab!)

2 IN-LAB # 1 - GETTING STARTED - STRUCTURE OF LABS: 1.Attendance is required 2.Can NOT be made up 3.Usually about 10 - 20 minutes of lecture/demo and then class time to work on your project 4.I will be drifting in and out of lab. You must come to lab prepared!

3 IN-LAB # 1 - GETTING STARTED - OBJECTIVES OF LAB 1: 1.Learn about the overall components of a Windows Program 2.Understand the major components associated with WinMain (specifically) and introduce a Window Procedure 3.Look at some sample code 4.Build and execute a windows app using 6.0 MSVC

4 IN-LAB NOTES Lab #1 -- Getting Started u WinMain( ) performs the following tasks: 1.Define/Register a Window Class 2.Creating a Window 3.Display the Window 4.Process Messages (Window Procedure) Minimal Windows Program Components 1.WinMain( ) 2.Window Function(WndProc) (next time)

5 WinMain Example u WinMain( ) 1.Entry point into your program 2.Must be called WinMain( ) 3.Syntax: int WINAPI (… ) calling convention(95/98) Minimal Windows Components WinMain( ) Window Function(WndProc)

6 WinMain Example #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpszCmdParam, int nCmdShow) {static char szAppName[ ] = “Examp1”; HWND hwnd; MSGmsg; WNDCLASSEX wndclass: if (!RegisterClassEx (&wndclass) { MessageBox(NULL, “Trouble – use NT”, szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, …); (see examp0 now) ShowWindow (hwnd, nCmdShow); // put window(or icon) on the display UpdateWindow (hwnd); // if nCmdShow SW_SHOWNORMAL, client area is erased & then UpdateWindow causes client area to be repainted WinMain( ) performs the following tasks: 1.Define/Register a Window Class 2.Creating a Window 3.Display the Window 4.Process Messages (Window Proc) LPSTR?

7 WinMain Example WinMain( ) performs the following tasks: 1.Define/Register a Window Class 2.Creating a Window 3.Display the Window 4.Process Messages (Window Proc) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpszCmdParam, int nCmdShow) {hwnd = CreateWindow(szAppName, …); (see examp0 now) ShowWindow (hwnd, nCmdShow); // put window(or icon) on the display UpdateWindow (hwnd); while(GetMessage (&msg, NULL, 0, 0))// m e s s a g e {TranslateMessage (&msg);// l o o p DispatchMessage(&msg);// passes struct back to windows - then windows send a message to the appropriate window procedure for processing }return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lParam)

8 Review: what happens in WinMain? Next time: The message loop in detail! NOTE: Please print out a copy of your code for class discussion purposes - bring to class! ****** D E M O ***** Questions up to This Point

9 DEMO - Creating a Project / Windows App 1.Creating a Project for a Windows App a. Make sure you create a new project b. Make sure MFC is off c. Create a Windows Application (.EXE) 2.Add the necessary source/C files 3.Compile/run the application (DEFinition Files required in Win3.1 - A ‘text file that tells linker program’s code and data segments, size of local data heap, and size of program’s stack - next page for brief example. Optional in ’95/98)

10 DEMO - Creating a Project / Windows App: Module DEFinition File NAME SAMPLE0 (usually name of.EXE) DESCRIPTION ‘First Samp - © by R. Albert’ (puts into exe file) EXETYPE WINDOWS (says its a windows program/app) STUB ‘WINSTUB.EXE’ (program inserted into EXE and executed when someone runs SAMPLE0 from DOS command line) CODE PRELOAD MOVEABLE DISCARDABLE (load segment into memory immediately; windows can move if it needs to; can discard and later reload from.EXE) DATA PRELOAD MOVEABLE MULTIPLE (…; multiple means each ‘instance’ of the program gets its own separate data segment) HEAPSIZE 4096 (for local variables) STACKSIZE 8192 (for parameter passing - more if using recursion) EXPORTS WndProc (allows Win3.1 to call the function)

11 R. Albert CST 238 - GUI Programming IN-LAB EXERCISE #1 1.Take your time - complete ALL steps in LAB 1 2.Make extensive use of on-line help 3.Try some stuff (run Petzolds code)…. 4. Extra excitement: Play with error sample (on web) Etc….. D E M O NOTE: LAB1 is on the web - due next Wed!


Download ppt "IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE."

Similar presentations


Ads by Google