Advertisement
Guest User

Untitled

a guest
May 25th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.98 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3. #include <time.h>
  4.  
  5. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  6. HINSTANCE hInst ;
  7. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  8.                     PSTR szCmdLine, int iCmdShow)
  9.      {
  10.      static char szAppName[] = "HelloWin" ;
  11.      HWND        hwnd ;
  12.      MSG         msg ;
  13.      WNDCLASSEX  wndclass ;
  14.  
  15.      wndclass.cbSize        = sizeof (wndclass) ;
  16.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  17.      wndclass.lpfnWndProc   = WndProc ;
  18.      wndclass.cbClsExtra    = 0 ;
  19.      wndclass.cbWndExtra    = 0 ;
  20.      wndclass.hInstance     = hInstance ;
  21.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  22.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  23.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  24.      wndclass.lpszMenuName  = NULL ;
  25.      wndclass.lpszClassName = szAppName ;
  26.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  27.      
  28.      RegisterClassEx (&wndclass) ;
  29.  
  30.      hwnd = CreateWindow (szAppName,        //
  31.              "????????????? ?????? ? ???????",   //
  32.                    WS_OVERLAPPEDWINDOW,     //
  33.                    CW_USEDEFAULT,           //
  34.                    CW_USEDEFAULT,           //
  35.                    CW_USEDEFAULT,           //
  36.                    CW_USEDEFAULT,           //
  37.                    NULL,                    //
  38.                    NULL,                    //
  39.                    hInstance,               //
  40.            NULL) ;         //
  41.  
  42.      ShowWindow (hwnd, iCmdShow) ;
  43.      UpdateWindow (hwnd) ;
  44.  
  45.      while (GetMessage (&msg, NULL, 0, 0))
  46.           {
  47.           TranslateMessage (&msg) ;
  48.           DispatchMessage (&msg) ;
  49.           }
  50.      return msg.wParam ;
  51.      }
  52.  
  53. #define BTN_WIDTH        150
  54. #define BTN_HEIGHT       20
  55. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){
  56.      HDC         hdc ;
  57.      PAINTSTRUCT ps ;
  58.      RECT        rect ;
  59.      static HWND  hwndButton1, hwndButton2, hwndButton3;
  60.      static char txt[32]="";
  61.      static char AuthorName[32]="Parkhomenko Viktor";
  62.      int loword,hiword;
  63.      static int fpic=0;
  64.      static HPEN hpen;
  65.      static HBRUSH hbrush;
  66.     static int koef_x=10;
  67.      switch (iMsg)
  68.           {
  69.           case WM_CREATE :
  70.               srand(time(0));
  71.               hdc = GetDC (hwnd) ;
  72.               /*hwndButton1 = CreateWindow ("button", "??????",
  73.                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  74.                                   100, 50, BTN_WIDTH, BTN_HEIGHT,
  75.                                   hwnd, (HMENU) 1, hInst, NULL) ;
  76.              
  77.               hwndButton2 = CreateWindow ("button", "????????",
  78.                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  79.                                   100, 100, BTN_WIDTH, BTN_HEIGHT,
  80.                                   hwnd, (HMENU) 2, hInst, NULL) ;
  81.  
  82.                 hwndButton3 = CreateWindow ("button", "?????",
  83.                                   WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
  84.                                   100, 150, BTN_WIDTH, BTN_HEIGHT,
  85.                                   hwnd, (HMENU) 3, hInst, NULL) ;*/    
  86.  
  87.                return 0 ;
  88.         /*case WM_COMMAND :
  89.             hpen = CreatePen(PS_SOLID, 10,RGB(rand()%256,rand()%256,rand()%256));
  90.             hbrush = CreateSolidBrush (RGB(rand()%256,rand()%256,rand()%256));
  91.             loword=LOWORD(wParam);
  92.             hiword=HIWORD(wParam);
  93.             switch(loword){
  94.                 case 1: strcpy(txt,"??????"); fpic=1; break;
  95.                 case 2: strcpy(txt,"????????"); fpic=2; break;
  96.                 case 3: strcpy(txt,"?????"); fpic=3; break;
  97.                 default:    strcpy(txt,"?????????? ???"); break;
  98.             }
  99.             InvalidateRect (hwnd, NULL, TRUE) ;
  100.             return 0 ;*/
  101.      
  102.             case WM_TIMER:
  103.                 InvalidateRect(hwnd,0,TRUE);
  104.             return 0;
  105.  
  106.             case WM_LBUTTONDOWN:
  107.                     SetTimer(hwnd,1,1000,0);
  108.             return 0 ;
  109.             case WM_RBUTTONDOWN:   
  110.                 KillTimer(hwnd,1);
  111.             return 0;
  112.  
  113.           case WM_PAINT :
  114.            hdc = BeginPaint (hwnd, &ps) ;
  115.                GetClientRect (hwnd, &rect) ;
  116.                HBRUSH hBrush1,hBrush2,hBrush3,hBrush4;
  117.                hBrush1 = CreateSolidBrush(RGB(0,255,0));
  118.                hBrush2 = CreateSolidBrush(RGB(0,0,255));
  119.                hBrush3 = CreateSolidBrush(RGB(255,0,0));
  120.                hBrush4 = CreateSolidBrush(RGB(150,150,150)); //?????
  121.                 TextOut (hdc, 100, 300, txt, strlen(txt)) ;
  122.                 SelectObject (hdc, hbrush);
  123.                 SelectObject (hdc, hpen);
  124.                 HRGN Rgn1, Rgn3, Rgn4, Rgn5,Rgn6;
  125.                 POINT ptArray1[4];
  126.                 ptArray1[0].x =45*koef_x; ptArray1[0].y =120;
  127.                 ptArray1[1].x =60*koef_x; ptArray1[1].y =120;
  128.                 ptArray1[2].x =60*koef_x; ptArray1[2].y =220;
  129.                 ptArray1[3].x =45*koef_x; ptArray1[3].y =220;
  130.                 POINT ptArray2[4];
  131.                 ptArray2[0].x =65*koef_x; ptArray2[0].y =120;
  132.                 ptArray2[1].x =80*koef_x; ptArray2[1].y =120;
  133.                 ptArray2[2].x =80*koef_x; ptArray2[2].y =220;
  134.                 ptArray2[3].x =65*koef_x; ptArray2[3].y =220;
  135.                 POINT ptArray3[6];
  136.                 ptArray3[0].x =40*koef_x; ptArray3[0].y =100;
  137.                 ptArray3[1].x =80*koef_x; ptArray3[1].y =100;
  138.                 ptArray3[2].x =95*koef_x; ptArray3[2].y =200;
  139.                 ptArray3[3].x =95*koef_x; ptArray3[3].y =300;
  140.                 ptArray3[4].x =95*koef_x; ptArray3[4].y =300;
  141.                 ptArray3[5].x =40*koef_x; ptArray3[5].y =300;
  142.                 Rgn1 = CreatePolygonRgn(ptArray1,sizeof(ptArray1)/sizeof(POINT),ALTERNATE);
  143.                 //Rgn2 = CreateRectRgn(400, 100, 1000, 300);
  144.                 Rgn3 = CreateEllipticRgn(50*koef_x, 250, 60*koef_x, 350);
  145.                 Rgn5 = CreateEllipticRgn(80*koef_x, 250, 90*koef_x, 350);
  146.                 Rgn4 = CreatePolygonRgn(ptArray2,sizeof(ptArray2)/sizeof(POINT),ALTERNATE);
  147.                 Rgn6 = CreatePolygonRgn(ptArray3,sizeof(ptArray3)/sizeof(POINT),ALTERNATE);
  148.                 //FillRgn(hDC, Rgn1, hBrush3);
  149.                     FillRgn(hdc, Rgn6, hBrush2);
  150.                     FillRgn(hdc, Rgn3, hBrush4);
  151.                     FillRgn(hdc, Rgn5, hBrush4);
  152.                     FillRgn(hdc, Rgn1, hBrush3);
  153.                     FillRgn(hdc, Rgn4, hBrush3);   
  154.                
  155.                
  156.             koef_x++;
  157.            EndPaint (hwnd, &ps) ;
  158.                return 0 ;
  159.            
  160.           case WM_DESTROY :
  161.                PostQuitMessage (0) ;
  162.                return 0 ;
  163.           }
  164.  
  165.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  166.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement