Programowanie Windows - PowerPoint PPT Presentation

About This Presentation
Title:

Programowanie Windows

Description:

BitBlt(hdc,0,0,rc.right,rc.bottom,hdcMap,0,0,SRCCOPY); break; BITMAPA Okno aplikacji podczas przetwarzania komunikatu WM_MOUSEMOVE xk, yk BitBlt (hdc ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 18
Provided by: AnnaJ155
Category:

less

Transcript and Presenter's Notes

Title: Programowanie Windows


1
Programowanie Windows
  • W srodowisku Visual C
  • Czesc I

Anna Tomkowska Politechnika Koszalinska 2007
2
Szkielet aplikacji
1/14
Ladownie bibliotek include Deklaracja
zmiennych globalnych Deklaracja funkcji Int
WINAPI WinMain(..) deklaracja
zmiennych wypelnienie klasy WNDCLASS rejestracja
wypelnionej klasy RegisterClass() utworzenie
okna uzyskujac uchwyt HWND CreateWindowEx() wysw
ietlenie okna ShowWindow() odswierzenie okna
UpdateWindow() Petla komunikatów LRESULT
CALLBACK ProceduraOkna() deklaracja
zmiennych switch(komunikat) Inne
ewentualne funkcje
3
Rysowanie
1/14
LRESULT CALLBACK WndProc() static int xp, yp,
xk, yk HDC hdc case WM_LBUTTONDOWN
xpxkLOWORD(lParam) ypykHIWORD(lParam)
return 0 case WM_LBUTTONUP
xkLOWORD(lParam) ykHIWORD(lParam)
hdc GetDC(hWnd) Rectangle(hdc, xp, yp,
xk, yk) ReleaseDC(hWnd,hdc) return
0
4
Rysowanie
4/14
LRESULT CALLBACK WndProc() static int
rysuj0 case WM_LBUTTONDOWN rysuj1
return 0 case WM_LBUTTONUP rysuj0
return 0 case WM_MOUSEMOVE if
(rysuj) hdc
GetDC(hWnd) xkLOWORD(lParam) ykHIWORD(lParam
) Rectangle(hdc,xp,yp,xk,yk) ReleaseDC(hWnd,h
dc) return 0
5
Tworzenie bitmap
3/14
LRESULT CALLBACK WndProc() static HBITMAP
hBitmap, HDC hdcMap RECT rc case
WM_CREATE GetClientRect(hWnd,rc) hdcGetDC(h
Wnd) hBitmap CreateCompatibleBitmap(hdc,rc.rig
ht,rc.bottom) hdcMap CreateCompatibleDC(hdc)
SelectObject(hdcMap,hBitmap) PatBlt(hdcMap,0,0,
rc.right,rc.bottom,WHITENESS) ReleaseDC(hWnd,hd
c) return 0 case WM_DESTROY
DeleteDC(hdcMap) DeleteObject(hBitmap)
PostQuitMessage(0) return 0
6
Rysowanie po bitmapie
4/14
LRESULT CALLBACK WndProc() case
WM_LBUTTONUP hdc GetDC(hWnd)
Rectangle(hdc, xp, yp, xk, yk)
ReleaseDC(hWnd,hdc) Rectangle(hdcMap, xp,
yp, xk, yk) InvalidateRect(hWnd,0,0)
return 0
7
Wyswietlanie bitmapy
5/14
LRESULT CALLBACK WndProc() PAINTSTRUCT ps
case WM_MOUSEMOVE
BitBlt(hdc,xp,yp,xk-xp,yk-yp,hdcMap,xp,yp,SRCCOPY)
xkLOWORD(lParam)
ykHIWORD(lParam) return 0
case WM_PAINT GetClientRect(hWnd,rc)
hdc BeginPaint(hWnd,ps)
BitBlt(hdc,0,0,rc.right,rc.bottom,hdcMap,0,0,SRCCO
PY) EndPaint(hWnd,ps) return 0
8
5/14
Okno aplikacji podczas przetwarzania komunikatu
WM_MOUSEMOVE
BITMAPA
BitBlt(hdc, xp, yp, a, b, hdcMap, xp, yp,
SRCCOPY)
xp, yp
b
case WM_LBUTTONDOWN xpxkLOWORD(lParam)
ypykHIWORD(lParam) break case
WM_LBUTTONUP xkLOWORD(lParam)
ykHIWORD(lParam) break case
WM_MOUSEMOVE (jezeli rysuj 1)
BitBlt(hdc,xp,yp,xk-xp,yk-yp,hdcMap,xp,yp,SRCCOPY)
xkLOWORD(lParam) ykHIWORD(lParam)
( Rysuj figure) break case WM_PAINT
BitBlt(hdc,0,0,rc.right,rc.bottom,hdcMap,0,0,SRCCO
PY) break
xk, yk
xk, yk
a
b yk-yp
a xk -xp
9
Tworzenie piór i pedzli
6/14
LRESULT CALLBACK WndProc() static HPEN
pen static HBRUSH brush case WM_CREATE
srand((unsigned) time(0)) return
0 case WM_LBUTTONDOWN pen
CreatePen(PS_SOLID,3,RGB(rand()256,rand()256,ran
d()256)) brush CreateSolidBrush(RGB(rand
()256,rand()256,rand()256)) return 0
case WM_LBUTTONUP
DeleteObject(pen) DeleteObject(brush)
return 0
10
Uzywanie piór i pedzli
7/14
LRESULT CALLBACK WndProc() case
WM_LBUTTONUP pen(HPEN)
SelectObject(hdcMap,pen) brush(HBRUSH)
SelectObject(hdcMap,brush)
Rectangle(hdcMap, xp, yp, xk, yk)
pen(HPEN) SelectObject(hdcMap,pen)
brush(HBRUSH) SelectObject(hdcMap,brush)
DeleteObject(pen) DeleteObject(brush) return
0 case WM_MOUSEMOVE pen(HPEN)
SelectObject(hdc,pen) brush(HBRUSH)
SelectObject(hdc,brush) Rectangle(hdc, xp,
yp, xk, yk) pen(HPEN) SelectObject(hdc,pe
n) brush(HBRUSH) SelectObject(hdc,brush)
DeleteObject(pen) DeleteObject(brush)
return 0
11
Tworzenie menu glównego
8/14
2.
1.
3.
4.
5.
12
Tworzenie menu glównego
9/14
1.
3.
4.
2.
5.
13
Dodawanie menu glównego
10/14
int WINAPI WinMain() WNDCLASS
wc wc.lpszMenuName MAKEINTRESOURCE(IDR_MENU1)

int WINAPI WinMain() HMENU hMenu
LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1)) HWND
hWnd CreateWindow("klasa_okna", "program",
WS_OVERLAPPED, 0, 0, 300,300,
0, hMenu,
hInst, 0 )
14
Komunikaty menu
11/14
LRESULT CALLBACK WndProc() static int figura
ID_RYSUJ_PROSTOKAT case WM_COMMAND
switch(LOWORD(wParam)) case ID_RYSUJ_
PROSTOKAT case ID_RYSUJ_ELIPSA case
ID_RYSUJ_WIELOKAT CheckMenuItem(GetMenu
(hWnd), figura, MF_UNCHECKED)
figuraLOWORD(wParam)
CheckMenuItem(GetMenu(hWnd), figura,
MF_CHECKED) break return 0
15
Rysowanie
12/14
void RysujFigure(HDC hdc, int xp, int yp, int
xk,int yk,int figura) LRESULT CALLBACK
WndProc() case WM_LBUTTONUP
Rectangle(hdcMap, xp, yp, xk, yk)
RysujFigure(hdcMap, xp, yp, xk, yk, figura)
return 0 case WM_MOUSEMOVE
Rectangle(hdc, xp, yp, xk, yk) RysujFigure(hdc,
xp, yp, xk, yk, figura) return 0
16
13/14
void RysujFigure(HDC hdc, int xp, int yp, int
xk,int yk,int figura) switch(figura)
case ID_RYSUJ_PROSTOKAT Rectangle(hdc,xp,yp
,xk,yk) break case
ID_RYSUJ_ELIPSA Ellipse(hdc,xp,yp,xk,yk)
break case ID_RYSUJ_WIELOKAT
POINT pts6xp,yp, xp(xk-xp)/2,yp,
xp2(xk-xp)/3,yp(yk-yp)/2,
xk,yk, xk-(xk-xp)/2,yk, xk-2(xk-xp)/3,yk-(
yk-yp)/2 Polygon(hdc,pts,6)
break
17
Menu podreczne
14/14
LRESULT CALLBACK WndProc() HMENU hMenuP POINT
pt case WM_CREATE hMenuP
GetSubMenu(GetMenu(hWnd), 0) return 0
case WM_RBUTTONUP pt.x LOWORD(lParam)
pt.y HIWORD(lParam) ClientToScreen(hWnd
, pt) TrackPopupMenu(hMenuP,
TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, 0)
return 0
Write a Comment
User Comments (0)
About PowerShow.com