
#演示在屏幕上画图


#预处理函数: 可配置 MKScript 脚本加载后自动运行
#mkscript_config_auto_start()


#预处理函数: 初始化MKScript窗口位置
mkscript_window_initial_position(900, 500)


#获得系统绘图设备
int hdc = get_dc(mkNull)

for int i = 1 to 3

    #创建辅助绘图设备
    int memDC = create_compatible_dc(0)

    int g_nWidth = 800
    int g_nHeight = 800

    #创建掩码位图（画布）
    int bmpBack = create_compatible_bitmap(hdc, g_nWidth, g_nHeight)

    #将画布贴到绘图设备上
    select_object(memDC, bmpBack)

    #创建画笔
    int penBack = create_pen(mkPS_SOLID, 1, rgb(255, 0, 255))

    #将画笔选到绘图设备上
    select_object(memDC, penBack)

    #创建画刷
    int brushBack = create_solid_brush(rgb(255, 255, 255))

    #将画刷选到绘图设备上
    select_object(memDC, brushBack)

    #擦除背景

    #获得库存物体，白色画刷
    int brushTemp = get_stock_object(mkWHITE_BRUSH)

    #填充客户区域
    fill_rect(memDC, 0, 0, g_nWidth, g_nHeight, brushTemp)

    #创建物体画刷
    int brushObj = create_solid_brush(rgb(0, 255, 0))

    #绘制维网格，矩形画法。

    int dw = 30
    int rows = g_nHeight / dw
    int cols = g_nWidth / dw
    for int r = 0 to rows - 1

        for int c = 0 to cols - 1
        
            if r == c
                select_object(memDC, brushObj)
            else
                select_object(memDC, brushBack)
            endif
            
            rectangle(memDC, c * dw, r * dw, (c+1) * dw, (r+1) * dw)
            
        next

    next

    delete_object(brushObj)

    #复制到系统设备上显示
    bit_blt(hdc, 0, 0, g_nWidth, g_nHeight, memDC, 0, 0, mkSRCCOPY)

    #释放
    delete_object(penBack)
    delete_object(brushBack)
    delete_object(bmpBack)
    delete_dc(memDC)
    release_dc(0, memDC)

    sleep(1000)

    println("1秒后重新绘制...")

next

println("刷新整个屏幕")

#刷新整个屏幕
invalidate_rect(0, 0, 0, 0, 0, mkFalse)

println("结束")





