• 画图函数——点,线,矩形等等


    矩形应用,画一个3行3列的矩形组合

    #include <windows.h>
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    #define edge 30 //矩形边长
    HBRUSH hbrush[2];//刷子数组
    void paint(HDC hdc);//画图声明
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("HelloWin") ;
         HWND         hwnd ;                
         MSG          msg ;               
         WNDCLASS     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 ;
    
         if (!RegisterClass (&wndclass))return 0 ;            
         hwnd = CreateWindow (szAppName,                  
                              TEXT ("一个简单的Win32程序"), 
                              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 ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
         HDC hdc;
         PAINTSTRUCT ps;
         switch (message)
         {          
         case WM_PAINT:
          hdc=BeginPaint(hwnd,&ps);
          paint(hdc);
          EndPaint(hwnd,&ps);
          return 0;
          
         case WM_DESTROY:
             DeleteObject(hbrush[0]);
             DeleteObject(hbrush[1]);
              PostQuitMessage (0) ; //在消息队列中插入一条“退出”消息
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam);//执行默认的消息处理
    }
    void paint(HDC hdc)
    {    
        int i,j;
        hbrush[0]=CreateSolidBrush(RGB(255,0,0));
        hbrush[1]=CreateSolidBrush(RGB(255,255,0));      
            for(j=0;j<3;j++) //
                for(i=0;i<3;i++)//
            {
                    if(j%2==0)
                    {
    
                    Sleep(50);
                    SelectObject(hdc,hbrush[0]);    
                    Rectangle(hdc,i*edge,j*edge,(i+1)*edge,(j+1)*edge);    
                    }
                    else
                    {    
                    Sleep(100);
                    SelectObject(hdc,hbrush[1]);    
                    Rectangle(hdc,i*edge,j*edge,(i+1)*edge,(j+1)*edge);    
                    }
    
            }
    }
    View Code
  • 相关阅读:
    2017-2018-1 20155218 《信息安全系统设计基础》第十一周学习总结
    # 课堂测试(CH6)20155218
    Elasticsearch6.0 IKAnalysis分词使用
    ELK6.0环境搭建及配置
    使用PHP抓取网站ico图标
    centos下apache+mysql+php安装及配置
    PHP的(Thread Safe与Non Thread Safe)
    作业九
    附加题
    作业八
  • 原文地址:https://www.cnblogs.com/tinaluo/p/5429229.html
Copyright © 2020-2023  润新知