Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Laboratory Korea University

Similar presentations


Presentation on theme: "Graphics Laboratory Korea University"— Presentation transcript:

1 Graphics Laboratory Korea University
Windows Programming Graphics Laboratory Korea University

2 Microsoft Visual C++ 6.0

3 File  New

4 New Project

5 Win32 Application (1/2)

6 Win32 Application (2/2)

7 Workspace

8 New File

9 Workspace  FileView

10 “main.cpp”

11 #include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // global variables char *szClassName = "Draw2DClass"; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { // Registers the window class WNDCLASSEX wcex; wcex.cbSize = sizeof(wcex); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL,IDI_APPLICATION); wcex.hIconSm = NULL; wcex.hCursor = LoadCursor(NULL,IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = szClassName; RegisterClassEx(&wcex); // Create the main window HWND hWnd = CreateWindow(szClassName, "Draw in 2D", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL); if (!hWnd) return FALSE; ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Main message loop MSG msg; while (GetMessage(&msg, NULL, 0, 0)) TranslateMessage(&msg); DispatchMessage(&msg); } UnregisterClass(szClassName, wcex.hInstance); return msg.wParam;

12 Window Message Handling
/* * WndProc: to process messages for the main window */ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (message) case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;

13 Build

14 Execute

15 Draw Points /* * WndProc: to process messages for the main window */
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; register int i, j; switch (message) case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... for(i=-5; i<=5; i++) for(j=-5; j<=5; j++) SetPixel(hdc, 400+i, 300+j, RGB(255, 0, 0)); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;

16 Result – Draw Points

17 Mouse Event Handing (1/2)
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; register int i, j; switch (message) case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... for(i=-5; i<=5; i++) for(j=-5; j<=5; j++) SetPixel(hdc, 400+i, 300+j, RGB(255, 0, 0)); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MOUSEMOVE: default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;

18 Mouse Event Handing (1/2)
int point[2] = { -5, -5 }; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; register int i, j; switch (message) case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... for(i=-5; i<=5; i++) for(j=-5; j<=5; j++) SetPixel(hdc, point[0]+i, point[1]+j, RGB(255, 0, 0)); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); case WM_LBUTTONDOWN: point[0] = LOWORD(lParam); point[1] = HIWORD(lParam); InvalidateRect(hWnd, NULL, FALSE); default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;

19 Result – Mouse Event Handling

20 Insert  Resource

21 Resources

22 Menu (1/6)

23 Menu (2/6)

24 Menu (3/6)

25 Menu (4/6)

26 Menu (5/6)

27 Menu (6/6)

28 Save Resources

29 Include Resources (1/3)

30 Include Resources (2/3)

31 Include Resources (3/3)

32 Result – Menu

33 Menu Event Handling

34 Result – Menu Event Handling

35 Miscellanies Check / Uncheck a item of menu
CheckMenuItem(GetMenu(hWnd), ID_PRIM_LINE, MF_CHECKED); CheckMenuItem(GetMenu(hWnd), ID_PRIM_LINE, MF_UNCHECKED); Enable / Disable a item of menu EnableMenuItem(GetMenu(hWnd), ID_PRIM_LINE, MF_ENABLED); EnableMenuItem(GetMenu(hWnd), ID_PRIM_LINE, MF_GRAYED); COLORREF GetPixel( int x, int y ) const; COLORREF SetPixel( int x, int y, COLORREF crColor );

36 RGB Color Model R G B Color Colors are additive 0.0 0.0 0.0 Black 1.0
Red 0.0 1.0 0.0 Green 0.0 0.0 1.0 Blue 1.0 1.0 0.0 Yellow 1.0 0.0 1.0 Magenta 0.0 1.0 1.0 Cyan 1.0 1.0 1.0 White

37 Insert  Resource

38 Dialog Box (1/5)

39 Dialog Box (2/5)

40 Dialog Box (3/5)

41 Dialog Box (4/5)

42 Dialog Box (5/5)

43 New Menu

44 Dialog Callback Function (1/2)

45 Dialog Callback Function (2/2)

46 Dialog Creation

47 Result – Dialog Box

48 Debug


Download ppt "Graphics Laboratory Korea University"

Similar presentations


Ads by Google