Presentation is loading. Please wait.

Presentation is loading. Please wait.

Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.

Similar presentations


Presentation on theme: "Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01."— Presentation transcript:

1 Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01

2 Quanta Confidential QUANTA WBU -2- 大綱 簡介 WinMain 流程 簡介原始範例結構 背景填色 繪製圖片 1 繪製圖片 2

3 Quanta Confidential QUANTA WBU -3- #define dim(x) (sizeof(x) / sizeof(x[0])) const TCHAR szAppName[] = TEXT ("Shapes"); const struct decodeUINT MainMessages[] = { WM_PAINT, DoPaintMain, WM_DESTROY, DoDestroyMain, };

4 Quanta Confidential QUANTA WBU -4- WinMain int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { // Initialize this instance. hwndMain = InitInstance(hInstance, lpCmdLine, nCmdShow); // Application message loop while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } // Instance cleanup return TermInstance (hInstance, msg.wParam); }

5 Quanta Confidential QUANTA WBU -5- InitInstance // InitInstance - Instance initialization HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){ WNDCLASS wc; // Register application main window class. wc.lpfnWndProc = MainWndProc; // Callback function wc.lpszClassName = szAppName; // Window class name // Create main window. hWnd = CreateWindowEx (WS_EX_NODRAG, // Ex Style szAppName, // Window class TEXT("Shapes"), // Window title WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); // Standard show and update calls ShowWindow (hWnd, nCmdShow); UpdateWindow (hWnd); return hWnd; }

6 Quanta Confidential QUANTA WBU -6- MainWndProc // MainWndProc - Callback function for application window LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { // Search message list to see if we need to handle this // message. If in list, call procedure. for (i = 0; i < dim(MainMessages); i++) { if (wMsg == MainMessages[i].Code) return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam); } return DefWindowProc (hWnd, wMsg, wParam, lParam); } WM_QUIT

7 Quanta Confidential QUANTA WBU -7- DoPaintMain LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { // 主程式 }

8 Quanta Confidential QUANTA WBU -8- BeginPaint //The BeginPaint function prepares the specified window for painting and fills a PAINTSTRUCT structure with information about the painting. HDC BeginPaint( HWND hwnd, // handle to window LPPAINTSTRUCT lpPaint // paint information );

9 Quanta Confidential QUANTA WBU -9- EndPaint //The EndPaint function marks the end of painting in the specified window. This function is required for each call to the BeginPaint function, but only after painting is complete. BOOL EndPaint( HWND hWnd, // handle to window CONST PAINTSTRUCT *lpPaint // paint data );

10 Quanta Confidential QUANTA WBU -10- DoPaintMain { PAINTSTRUCT ps; RECT rect; HDC hdc; HBRUSH hBr; TCHAR szText[128]; GetClientRect (hWnd, &rect); hdc = BeginPaint (hWnd, &ps); // 繪圖程式碼:背景填色、繪圖 1 、繪圖 2 EndPaint (hWnd, &ps); return 0; } WM_DESTROY

11 Quanta Confidential QUANTA WBU -11- 背景填色 hBr = (HBRUSH) GetStockObject (DKGRAY_BRUSH); FillRect(hdc,&rect,hBr); //DeleteObject(hBr);

12 Quanta Confidential QUANTA WBU -12- 繪製圖片 1 HBITMAP hBitmap,hOldBitmap; BITMAP bmp; HDC hdcMem; TCHAR sz[]=TEXT("\\bitmap1.bmp"); hBitmap=SHLoadDIBitmap((LPCTSTR)sz); hdcMem=CreateCompatibleDC(hdc); hOldBitmap=(HBITMAP) SelectObject(hdcMem,hBitmap); GetObject(hBitmap,sizeof(BITMAP),&bmp); BitBlt(hdc,rect.left,rect.top,bmp.bmWidth,bmp.bmHeight, hdcMem,0,0,SRCCOPY); SelectObject(hdcMem,hOldBitmap); DeleteObject (hOldBitmap); DeleteDC(hdcMem);

13 Quanta Confidential QUANTA WBU -13- 繪製圖片 2 hBitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_ BITMAP1)); hdcMem=CreateCompatibleDC(hdc); hOldBitmap= (HBITMAP) SelectObject(hdcMem,hBitmap); GetObject(hBitmap,sizeof(BITMAP),&bmp); BitBlt(hdc,rect.left,rect.top,bmp.bmWidth,bmp.bmHeight, hdcMem,0,0,SRCCOPY); SelectObject(hdcMem,hOldBitmap); DeleteObject (hOldBitmap); DeleteDC(hdcMem); DoPaintMain

14 Quanta Confidential QUANTA WBU -14- DoDestroyMain // DoDestroyMain - Process WM_DESTROY message for window LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { PostQuitMessage (0); return 0; } WinMain

15 Quanta Confidential QUANTA WBU -15- TermInstance // TermInstance - Program cleanup int TermInstance (HINSTANCE hInstance, int nDefRC) { return nDefRC; } WinMain

16 Quanta Confidential QUANTA WBU -16- #include #include // For all that Windows stuff #include "shapes.h" // Program-specific stuff #include "resource.h"

17 Quanta Confidential QUANTA WBU -17- decodeUINT struct decodeUINT { // Structure associates UINT Code; // messages // with a function. LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM); };

18 Quanta Confidential QUANTA WBU -18- LRESULT typedef LONG_PTR LRESULT;

19 Quanta Confidential QUANTA WBU -19- WNDCLASS //This structure contains the window class attributes that are registered by the RegisterClass function. typedef struct _WNDCLASS { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HANDLE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; } WNDCLASS;

20 Quanta Confidential QUANTA WBU -20- PAINTSTRUCT //This structure contains information that an application uses to paint the client area of a window owned by that application. typedef struct tagPAINTSTRUCT { HDC hdc; BOOL fErase; RECT rcPaint; BOOL fRestore; BOOL fIncUpdate; BYTE rgbReserved[32]; } PAINTSTRUCT;

21 Quanta Confidential QUANTA WBU -21- RECT //This structure defines the coordinates of the upper-left and lower-right corners of a rectangle. typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT;

22 Quanta Confidential QUANTA WBU -22- HDC

23 Quanta Confidential QUANTA WBU -23- HBRUSH

24 Quanta Confidential QUANTA WBU -24- TCHAR

25 Quanta Confidential QUANTA WBU -25- GetClientRect //The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower- right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0). BOOL GetClientRect( HWND hWnd, LPRECT lpRect );

26 Quanta Confidential QUANTA WBU -26- GetStockObject //The GetStockObject function retrieves a handle to one of the stock pens, brushes, fonts, or palettes. HGDIOBJ GetStockObject( int fnObject // stock object type );

27 Quanta Confidential QUANTA WBU -27-

28 Quanta Confidential QUANTA WBU -28- FillRect //This function fills a rectangle using the specified brush. This function fills the rectangle's left and top borders, but excludes the right and bottom borders. int FillRect( HDC hDC, CONST RECT* lprc, HBRUSH hbr );

29 Quanta Confidential QUANTA WBU -29- SelectObject //The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type. HGDIOBJ SelectObject( HDC hdc, // handle to DC HGDIOBJ hgdiobj // handle to object );

30 Quanta Confidential QUANTA WBU -30- HBITMAP

31 Quanta Confidential QUANTA WBU -31- BITMAP //This structure defines the type, width, height, color format, and bit values of a bitmap. typedef struct tagBITMAP { LONG bmType; LONG bmWidth; LONG bmHeight; LONG bmWidthBytes; WORD bmPlanes; WORD bmBitsPixel; LPVOID bmBits; } BITMAP;

32 Quanta Confidential QUANTA WBU -32- SHLoadDIBitmap

33 Quanta Confidential QUANTA WBU -33- CreateCompatibleDC //This function creates a memory device context (DC) compatible with the specified device. HDC CreateCompatibleDC( HDC hdc );

34 Quanta Confidential QUANTA WBU -34- GetObject //This function obtains information about a specified graphics object. Depending on the graphics object, the function places a filled-in BITMAP, DIBSECTION, LOGBRUSH, LOGFONT, or LOGPEN structure into a specified buffer. int GetObject( HGDIOBJ hgdiobj, int cbBuffer, LPVOID lpvObject );

35 Quanta Confidential QUANTA WBU -35- sizeof //This function returns the size, in bytes, of the specified resource. DWORD SizeofResource( HMODULE hModule, HRSRC hResInfo );

36 Quanta Confidential QUANTA WBU -36- BitBlt //This function transfers pixels from a specified source rectangle to a specified destination rectangle, altering the pixels according to the selected raster operation (ROP) code. BOOL BitBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop );

37 Quanta Confidential QUANTA WBU -37- DeleteDC //This function deletes the specified device context (DC). BOOL DeleteDC( HDC hdc );

38 Quanta Confidential QUANTA WBU -38- DeleteObject //This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. After the object is deleted, the specified handle is no longer valid. BOOL DeleteObject( HGDIOBJ hObject );

39 Quanta Confidential QUANTA WBU -39- LoadBitmap //This function loads the specified bitmap resource from the executable file for a module. HBITMAP LoadBitmap( HINSTANCE hInstance, LPCTSTR lpBitmapName );

40 Quanta Confidential QUANTA WBU -40- MAKEINTRESOURCE //This macro converts an integer value to a resource type compatible with Windows resource-management functions. This macro is used in place of a string containing the name of the resource. LPTSTR MAKEINTRESOURCE( WORD wInteger; );

41 Quanta Confidential QUANTA WBU -41- GetMessage //This function retrieves a message from the calling thread's message queue and places it in the specified structure. BOOL GetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax );

42 Quanta Confidential QUANTA WBU -42- TranslateMessage //This function translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function. BOOL TranslateMessage( const MSG* lpMsg );

43 Quanta Confidential QUANTA WBU -43- DispatchMessage //This function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function. LONG DispatchMessage( const MSG* lpmsg );

44 Quanta Confidential QUANTA WBU -44- CreateWindowEx //This function creates an overlapped, pop-up, or child window with an extended style; otherwise, this function is identical to the CreateWindow function. HWND CreateWindowEx( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam );

45 Quanta Confidential QUANTA WBU -45- ShowWindow //This function sets the specified window's show state. BOOL ShowWindow( HWND hWnd, int nCmdShow );

46 Quanta Confidential QUANTA WBU -46- UpdateWindow //This function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty.WM_PAINT UpdateWindow sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. BOOL UpdateWindow( HWND hWnd );

47 Quanta Confidential QUANTA WBU -47- DefWindowProc //This function calls the default window procedure to provide default processing for any window messages that an application does not process. This function ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure. LRESULT DefWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );

48 Quanta Confidential QUANTA WBU -48- PostQuitMessage //This function indicates to Windows that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message. void PostQuitMessage( int nExitCode );


Download ppt "Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01."

Similar presentations


Ads by Google