找回密码
 加入
搜索
查看: 1216|回复: 1

[AU3基础] 一段代码求c转au3-关于gdi+的【已解决】【自己搞定】

[复制链接]
发表于 2017-7-23 15:15:45 | 显示全部楼层 |阅读模式
本帖最后由 yamakawa 于 2017-7-24 19:22 编辑
// TaiJi.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "TaiJi.h"

/*
* 由于需要用GDI+进行绘图,所以需要先含GDI+库
* 首先,包含Gdiplus.h头文件, 引入Gdiplus命名空间, 包含gdiplus.lib库
* 在stdafx.h头文件中,取消 WIN32_LEAN_AND_MEAN 宏的定义,如果不取消这个宏定义,编译时会报错.
*/
#include <GdiPlus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")

#define MAX_LOADSTRING 100

// 全局变量:
HINSTANCE hInst;                                // 当前实例
TCHAR szTitle[MAX_LOADSTRING] = TEXT("旋转的太极");                    // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名

ULONG_PTR GdiplusToken;

// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

     // TODO: 在此放置代码。
    MSG msg;
    HACCEL hAccelTable;

    // 初始化全局字符串
    LoadString(hInstance, IDC_TAIJI, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TAIJI));

    // 主消息循环:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style            = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra        = 0;
    wcex.cbWndExtra        = 0;
    wcex.hInstance        = hInstance;
    wcex.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TAIJI));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName    = NULL;
    wcex.lpszClassName    = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // 将实例句柄存储在全局变量中

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, 600, 400, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    
    GdiplusStartupInput gdiplusStartupInput;

    const int width = 300;
    const int height = 300;

    static RECT rect;

    static Bitmap *pBufferBmp;
    static Graphics *pGrphBmp;
    static SolidBrush* pBrsh1;
    static SolidBrush* pBrsh2;
    
    switch (message)
    {
    case WM_CREATE:
        //初始化GDI+
        GdiplusStartup(&GdiplusToken, &gdiplusStartupInput, NULL);
        
        //获取客户区的大小,计算位图在客户区居中显示的位置
        GetClientRect(hWnd, &rect);
        rect.left = (rect.right - width) / 2;
        rect.right = rect.left + width;
        rect.top = (rect.bottom - height) / 2;
        rect.bottom = rect.top + height;

        //创建一个黑色画刷
        pBrsh1 = new SolidBrush(Color::Black);
        //创建一个白色画刷
        pBrsh2 = new SolidBrush(Color::White);

        //创建一个宽高300像素的正方形位图
        pBufferBmp = new Bitmap(width, height);
        pGrphBmp = Graphics::FromImage(pBufferBmp);

        //设置绘制图形时消除锯齿
        pGrphBmp->SetSmoothingMode(SmoothingModeAntiAlias);

        //设置坐标原点位于位图的中心
        pGrphBmp->TranslateTransform(float(width/2), float(height/2));

        SetTimer(hWnd, 1, 30, NULL);
        break;
    case WM_TIMER:
                
        //逆时针每次旋转坐标5度
        pGrphBmp->RotateTransform(-5);

        //用黄绿色填充位图背景
        pGrphBmp->Clear(Color::YellowGreen);

        //用黑色画刷绘制左侧的黑色半圆
        pGrphBmp->FillPie(pBrsh1, -100, -100, 200, 200, 90, 180);
        
        //用白色画刷绘制右侧的白色半圆
        pGrphBmp->FillPie(pBrsh2, -100, -100, 200, 200, 90, -180);

        //绘制黑色阴阳鱼的鱼头
        pGrphBmp->FillPie(pBrsh1, -51, 0, 100, 100, 90, -180);

        //绘制白色阴阳鱼的鱼头
        pGrphBmp->FillPie(pBrsh2, -49, -100, 100, 100, 90, 180);

        //绘制黑色阴阳鱼的眼睛
        pGrphBmp->FillEllipse(pBrsh1, -10, -60, 20, 20);

        //绘制白色阴阳鱼的眼睛
        pGrphBmp->FillEllipse(pBrsh2, -10, 40, 20, 20);

        
        InvalidateRect(hWnd, &rect, FALSE);
        break;
    
    case WM_PAINT:
    {
        hdc = BeginPaint(hWnd, &ps);

        Graphics *pGrph = Graphics::FromHDC(hdc);
        pGrph->DrawImage(pBufferBmp, rect.left, rect.top);

        EndPaint(hWnd, &ps);
        break;
    }

    case WM_DESTROY:
        KillTimer(hWnd, 1);
        delete pBrsh1;
        delete pBrsh2;
        delete pGrphBmp;
        delete pBufferBmp;

        //释放GDI+
        GdiplusShutdown(GdiplusToken);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
 

源码: http://pan.baidu.com/share/link?shareid=535102&uk=1678089569
网上看的一段代码,感觉挺有意思的。哪位高人能帮我转成au3么
 楼主| 发表于 2017-7-23 15:16:48 | 显示全部楼层
        pGrphBmp->TranslateTransform(float(width/2), float(height/2));
        pGrphBmp->RotateTransform(-5);
主要是这两个。。。。额。。不知道为嘛写的总不对
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-3-28 21:47 , Processed in 0.070714 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表