Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <time.h>
- LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
- HINSTANCE hInst ;
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
- PSTR szCmdLine, int iCmdShow)
- {
- static char szAppName[] = "HelloWin" ;
- HWND hwnd ;
- MSG msg ;
- WNDCLASSEX wndclass ;
- wndclass.cbSize = sizeof (wndclass) ;
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName = szAppName ;
- wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
- RegisterClassEx (&wndclass) ;
- hwnd = CreateWindow (szAppName, //
- "????????????? ?????? ? ???????", //
- WS_OVERLAPPEDWINDOW, //
- CW_USEDEFAULT, //
- CW_USEDEFAULT, //
- CW_USEDEFAULT, //
- CW_USEDEFAULT, //
- NULL, //
- NULL, //
- hInstance, //
- NULL) ; //
- ShowWindow (hwnd, iCmdShow) ;
- UpdateWindow (hwnd) ;
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- return msg.wParam ;
- }
- #define BTN_WIDTH 150
- #define BTN_HEIGHT 20
- LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
- HDC hdc ;
- PAINTSTRUCT ps ;
- RECT rect ;
- static HWND hwndButton1, hwndButton2, hwndButton3;
- static char txt[32]="";
- static char AuthorName[32]="Parkhomenko Viktor";
- int loword,hiword;
- static int fpic=0;
- static HPEN hpen;
- static HBRUSH hbrush;
- static int koef_x=10;
- switch (iMsg)
- {
- case WM_CREATE :
- srand(time(0));
- hdc = GetDC (hwnd) ;
- /*hwndButton1 = CreateWindow ("button", "??????",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 100, 50, BTN_WIDTH, BTN_HEIGHT,
- hwnd, (HMENU) 1, hInst, NULL) ;
- hwndButton2 = CreateWindow ("button", "????????",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 100, 100, BTN_WIDTH, BTN_HEIGHT,
- hwnd, (HMENU) 2, hInst, NULL) ;
- hwndButton3 = CreateWindow ("button", "?????",
- WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
- 100, 150, BTN_WIDTH, BTN_HEIGHT,
- hwnd, (HMENU) 3, hInst, NULL) ;*/
- return 0 ;
- /*case WM_COMMAND :
- hpen = CreatePen(PS_SOLID, 10,RGB(rand()%256,rand()%256,rand()%256));
- hbrush = CreateSolidBrush (RGB(rand()%256,rand()%256,rand()%256));
- loword=LOWORD(wParam);
- hiword=HIWORD(wParam);
- switch(loword){
- case 1: strcpy(txt,"??????"); fpic=1; break;
- case 2: strcpy(txt,"????????"); fpic=2; break;
- case 3: strcpy(txt,"?????"); fpic=3; break;
- default: strcpy(txt,"?????????? ???"); break;
- }
- InvalidateRect (hwnd, NULL, TRUE) ;
- return 0 ;*/
- case WM_TIMER:
- InvalidateRect(hwnd,0,TRUE);
- return 0;
- case WM_LBUTTONDOWN:
- SetTimer(hwnd,1,1000,0);
- return 0 ;
- case WM_RBUTTONDOWN:
- KillTimer(hwnd,1);
- return 0;
- case WM_PAINT :
- hdc = BeginPaint (hwnd, &ps) ;
- GetClientRect (hwnd, &rect) ;
- HBRUSH hBrush1,hBrush2,hBrush3,hBrush4;
- hBrush1 = CreateSolidBrush(RGB(0,255,0));
- hBrush2 = CreateSolidBrush(RGB(0,0,255));
- hBrush3 = CreateSolidBrush(RGB(255,0,0));
- hBrush4 = CreateSolidBrush(RGB(150,150,150)); //?????
- TextOut (hdc, 100, 300, txt, strlen(txt)) ;
- SelectObject (hdc, hbrush);
- SelectObject (hdc, hpen);
- HRGN Rgn1, Rgn3, Rgn4, Rgn5,Rgn6;
- POINT ptArray1[4];
- ptArray1[0].x =45*koef_x; ptArray1[0].y =120;
- ptArray1[1].x =60*koef_x; ptArray1[1].y =120;
- ptArray1[2].x =60*koef_x; ptArray1[2].y =220;
- ptArray1[3].x =45*koef_x; ptArray1[3].y =220;
- POINT ptArray2[4];
- ptArray2[0].x =65*koef_x; ptArray2[0].y =120;
- ptArray2[1].x =80*koef_x; ptArray2[1].y =120;
- ptArray2[2].x =80*koef_x; ptArray2[2].y =220;
- ptArray2[3].x =65*koef_x; ptArray2[3].y =220;
- POINT ptArray3[6];
- ptArray3[0].x =40*koef_x; ptArray3[0].y =100;
- ptArray3[1].x =80*koef_x; ptArray3[1].y =100;
- ptArray3[2].x =95*koef_x; ptArray3[2].y =200;
- ptArray3[3].x =95*koef_x; ptArray3[3].y =300;
- ptArray3[4].x =95*koef_x; ptArray3[4].y =300;
- ptArray3[5].x =40*koef_x; ptArray3[5].y =300;
- Rgn1 = CreatePolygonRgn(ptArray1,sizeof(ptArray1)/sizeof(POINT),ALTERNATE);
- //Rgn2 = CreateRectRgn(400, 100, 1000, 300);
- Rgn3 = CreateEllipticRgn(50*koef_x, 250, 60*koef_x, 350);
- Rgn5 = CreateEllipticRgn(80*koef_x, 250, 90*koef_x, 350);
- Rgn4 = CreatePolygonRgn(ptArray2,sizeof(ptArray2)/sizeof(POINT),ALTERNATE);
- Rgn6 = CreatePolygonRgn(ptArray3,sizeof(ptArray3)/sizeof(POINT),ALTERNATE);
- //FillRgn(hDC, Rgn1, hBrush3);
- FillRgn(hdc, Rgn6, hBrush2);
- FillRgn(hdc, Rgn3, hBrush4);
- FillRgn(hdc, Rgn5, hBrush4);
- FillRgn(hdc, Rgn1, hBrush3);
- FillRgn(hdc, Rgn4, hBrush3);
- koef_x++;
- EndPaint (hwnd, &ps) ;
- return 0 ;
- case WM_DESTROY :
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement