Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics1 Windows NT Graphics Interface.

Similar presentations


Presentation on theme: "Computer Graphics1 Windows NT Graphics Interface."— Presentation transcript:

1 Computer Graphics1 Windows NT Graphics Interface

2 Computer Graphics2 References n Since a complete study of the Windows NT programming isn’t possible within the time limits we have, for additional information you can use any of the following: u Windows 95 Programming Nuts & Bolts for experienced Programmers / Herbert Schildt u Microsoft Visual C++ X.X help. u Any other windows NT programming guides.

3 Computer Graphics3 Some Application Fundamentals n WinMain int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous // instance HINSTANCE hPrevInstance, // handle to previous // instance LPSTR lpCmdLine,// pointer to command line int nCmdShow // show state of window ); u All Windows NT programs begin execution with a call to WinMain(), except for console applications, which begin in main().

4 Computer Graphics4 Some Application Fundamentals n The Window Function u All Windows NT programs must contain a special function that is not called by your program, but is called by Windows NT. u It is through this function that Windows communicates with your program. The window function is called whenever Windows needs to pass a “message” to your program. u Example: ViewProc(HWND hWnd, UINT wMessage, UINT wParam, LONG lParam) UINT wParam, LONG lParam)

5 Computer Graphics5 Some Application Fundamentals u It is passed the first four members of the MSG structure as parameters: n Message structure: typedef struct tagMSG { HWND wnd;// window that message is for UINT message; // message WPARAM wParam; // message-dependent info LPARAM lParam;// more message-dependent info DWORD time;// time message posted POINT pt;// x,y location of mouse } MSG;

6 Computer Graphics6 Message Macros WM_PAINT - WM_PAINT - Windows or another application makes a request to paint a portion of an application's window. WM_LBUTTONUP - WM_LBUTTONUP - the user releases the left mouse button while the cursor is in the client area of a window. WM_LBUTTONDOWN - WM_LBUTTONDOWN - the user presses the left mouse button while the cursor is in the client area of a window. WM_MOUSEMOVE - WM_MOUSEMOVE - the cursor moves

7 Computer Graphics7 Drawing in Windows NT: n HDC - Device Context u Contains the information on the way it is possible to draw on the screen: F color (background, foreground) F Paint structure F Pen F Other info. n HPEN - Type of pen to draw lines on the screen u line color u line width u line style

8 Computer Graphics8 Drawing in Windows NT - Cont. n To get the default pen of the screen: HPEN hPen = SelectObject(hDC,GetStockObject(BLACK_PEN)); n Drawing a line: u Moving a pen to location (x,y): MoveToEx(hDC, x, y, NULL); MoveToEx(hDC, x, y, NULL); u Drawing a line from the current point to (x,y): LineTo(hDC, x, y);

9 Computer Graphics9 Toolbar n A Toolbar is One of the most important common controls because it can speed up menu selection when you are using a mouse. n Often, a Toolbar is used in conjunction with a standard menu. n To create a Tollbar, use the CreateToolbarEx() function: HWND CreateToolbarEx( HWND hwnd, DWORD ws,UINT wID, int nBitmaps, HINSTANCE hBMInst, UINT wBMID, LPCTBBUTTON lpButtons, int iNumButtons, int dxButton, int dyButton, int dxBitmap, int dyBitmap, UINT uStructSize );

10 Computer Graphics10 Example n In your header file, there should be definitions for the names of the buttons you are using, so that they can be identified when pressed. For example, in Skeleton.h: #define CG_TOOLBAR (WM_USER) #define CG_PERSP (CG_TOOLBAR + 1) #define CG_ORTHO (CG_TOOLBAR + 2) n Also, the style of each button, and the way they appear is determined in a TBBUTTON struct.

11 Computer Graphics11 TBBUTTON typedef struct _TBBUTTON { int iBitmap;// int iBitmap;// Zero-based index of button image int idCommand; // int idCommand; // Command identifier associated with // the button BYTE fsState; // BYTE fsState; // Button state flags BYTE fsStyle; // BYTE fsStyle; // Button style DWORD dwData; // DWORD dwData; // Application-defined value. int iString; // int iString; // Zero-based index of button string. } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON; FAR* LPTBBUTTON;

12 Computer Graphics12 TBBUTTON - Cont. n For example, in Skeleton.C: static TBBUTTON tbButtons[] = { { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP }, { 0, CG_ORTHO, TBSTATE_ENABLED | TBSTATE_CHECKED, TBSTYLE_CHECKGROUP }, { 1, CG_PERSP, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP }, { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP }, TBSTYLE_SEP }, { 2, CG_ROTAT, TBSTATE_ENABLED | TBSTATE_CHECKED, TBSTYLE_CHECKGROUP },... { 8, CG_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON }, { 8, CG_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON },...

13 Computer Graphics13 Summarize of the exercises skeleton n In the skeleton, 2 windows are created. The first (szAppName) is initially 512x512, and contains a tool bar child, and contains a child window (szViewName). n The parent window is not seen, but it handles the messages that are sent from the tool bar, any time a button is pressed. n The child window receives the messages of the mouse pressing and moving, which cause the calls to the functions that you will have to write.


Download ppt "Computer Graphics1 Windows NT Graphics Interface."

Similar presentations


Ads by Google