|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Thu Jan 05, 2023 12:55 am Post subject: How to Use GDI+ Correctly by CE |
|
|
Code: | if form==nil then
form=CreateForm(true)
end
function Message(hWnd, Text, Title, Type)
executeCodeLocalEx("user32.MessageBoxA",hWnd, Text, Title, Type)
end
Text=utf8ToAnsi('Hello World(Test)')
Title=utf8ToAnsi('Message(Test)')
Message(form.Handle, Text ,Title ,1)
--The following code does not work properly
function GdipCreateFromHDC(hWnd)
return executeCodeLocalEx("GdiPlus.GdipCreateFromHDC",hWnd)
end
function GdipCreatePen1(color)
return executeCodeLocalEx("GdiPlus.GdipCreatePen1",color)
end
function GdipDrawEllipse(pen, a, b, c, d)
return executeCodeLocalEx("GdiPlus.GdipDrawEllipse",pen, a, b, c, d)
end
hwnd=form.Canvas.Handle
GdipCreateFromHDC(hwnd)
pen=GdipCreatePen1(0xff)
GdipDrawEllipse(pen,0,50,200,100) |
Is this method not suitable for GDI+, or my method is wrong.
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8516 Location: 127.0.0.1
|
Posted: Thu Jan 05, 2023 1:52 am Post subject: |
|
|
Gdip requires that you initialize it first via GdiplusStartup:
https://learn.microsoft.com/en-us/windows/win32/api/Gdiplusinit/nf-gdiplusinit-gdiplusstartup
You are also not calling the API's correctly.
GdipCreateFromHDC is defined as:
Code: |
GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics);
|
GdipCreatePen1 is defined as:
Code: |
GpStatus WINGDIPAPI
GdipCreatePen1(ARGB color, REAL width, GpUnit unit, GpPen **pen);
|
_________________
- Retired. |
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Thu Jan 05, 2023 4:37 am Post subject: |
|
|
I don't understand.
This writing method lua seems unable to run
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jan 06, 2023 12:06 am Post subject: |
|
|
This one using gdi32 which no need call 'startup' and 'Shutdown'
Example : combine gdi32 function + form handle default by CE
Code: | if f then f.destroy() end
f = createForm()
function Elps(hdc, X1, Y1, X2, Y2)
return executeCodeLocalEx("gdi32.Ellipse", hdc, X1, Y1, X2, Y2)
end
function Pie(hdc, X1, Y1 , X2, Y2, X3, Y3, X4, Y4)
return executeCodeLocalEx("gdi32.Pie", hdc, X1, Y1 , X2, Y2, X3, Y3, X4, Y4)
end
function drawRandom()
c = f.canvas
----
c.Brush.Style = 0
c.Brush.Color = 0x0ff0ff
d = f.canvas.handle
Pie(d, 10, 10, f.Width, f.Height, 50, 0, 80, 200)
----
e = f.canvas
e.Brush.Style = 0
e.Brush.Color = 0xff
g = f.canvas.handle
Elps(g, 250,150, 110, 60)
end
f.show()
f.OnPaint = drawRandom |
tested on Windows 10 64 bit using CE 7.4 64 bit
Description: |
|
Filesize: |
3.89 KB |
Viewed: |
2002 Time(s) |
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Fri Jan 06, 2023 9:22 am Post subject: |
|
|
Corroder wrote: | This one using gdi32 which no need call 'startup' and 'Shutdown'
Example : combine gdi32 function + form handle default by CE |
Gdi32 only needs to pass in the handle, but gdi+can implement anti aliasing to make it smoother
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jan 06, 2023 9:34 pm Post subject: |
|
|
.lua wrote: | Gdi32 only needs to pass in the handle, but gdi+can implement anti aliasing to make it smoother |
Gdi32 have StretchBlt function and set to StretchBltMode to HALFTONE for anti aliasing image, shape, etc.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Sat Jan 07, 2023 10:24 pm Post subject: |
|
|
Corroder wrote: | Gdi32 have StretchBlt function and set to StretchBltMode to HALFTONE for anti aliasing image, shape, etc. | Can you give me an example for reference
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 08, 2023 12:48 am Post subject: |
|
|
.lua wrote: | Corroder wrote: | Gdi32 have StretchBlt function and set to StretchBltMode to HALFTONE for anti aliasing image, shape, etc. | Can you give me an example for reference |
The idea was (by some references)
1. Create original bitmap for drawing
2. Create temporary bitmap (2x, 4x or 8x) larger than the original bitmap
3. Render your graphics to this large temporary bitmap
(use any GDI method, pen or brush you like) but scale the graphics appropriately
4. Draw this temporary bitmap on the original bitmap scaled
(i.e. using StretchDIBits() method or any other you like),
but call SetStretchBltMode(HALFTONE) before this last step for the original DC
(which holds the original bitmap), and after scaling restore it back
Example code (even not as expected. Ported to CE Lua from VB6 Script) :
Code: | ANDSCANS = 1
ORSCANS = 2
DELETESCANS = 3
HALFTONE = 4
SRCCOPY = 0x00CC0020
SRCPAINT = 0x00EE0086
SRCAND = 0x008800C6
SRCINVERT = 0x00660046
SRCERASE = 0x00440328
NOTSRCCOPY = 0x00330008
NOTSRCERASE = 0x001100A6
MERGECOPY = 0x00C000CA
MERGEPAINT = 0x00BB0226
PATCOPY = 0x00F00021
PATPAINT = 0x00FB0A09
PATINVERT = 0x005A0049
DSTINVERT = 0x00550009
BLACKNESS = 0x00000042
WHITENESS = 0x00FF0062
MM_TEXT = 1
MM_LOMETRIC = 2
MM_HIMETRIC = 3
MM_LOENGLISH = 4
MM_HIENGLISH = 5
MM_TWIPS = 6
MM_ISOTROPIC = 7
MM_ANISOTROPIC = 8
MM_MIN = MM_TEXT
MM_MAX = MM_ANISOTROPIC
MM_MAX_FIXEDSCALE = MM_TWIPS
function SetStretchBltMode(hdc, iStretchMode)
return executeCodeLocalEx("gdi32.SetStretchBltMode", hdc, iStretchMode)
end
function StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, dwRop)
return executeCodeLocalEx("gdi32.StretchBlt", hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, dwRop)
end
function BitBlt(hdc, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop)
return executeCodeLocalEx("gdi32.BitBlt", hdc, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop)
end
function SetMapMode(hdc, fnMapMode)
return executeCodeLocalEx("gdi32.SetMapMode", hdc, fnMapMode)
end
function SetViewportExtEx(hdc, x, y, lpsz)
return executeCodeLocalEx("gdi32.SetViewportExtEx", hdc, x, y, lpsz)
end
function SetWindowExtEx(hdc, x, y, lpsz)
return executeCodeLocalEx("gdi32.SetViewportExtEx", hdc, x, y, lpsz)
end
if f then f.destroy() end
f = createForm()
f.Width = 300
f.Position = 'poScreenCenter'
f.Caption = "Test Stretch Blt gdi32"
btn = createButton(f)
btn.Top = f.Height - 35
btn.Left = 80
btn.Width = 150
btn.Caption = 'Antialiasing'
f.Repaint()
f.Canvas.Brush.Color = clYellow
f.Canvas.Ellipse(99, 38, 246, 183)
f.Canvas.TextOut(10,10, "Without Antialiasing")
function btnClick()
local ZOOM = 16
local Bmp
local StretchMode
f.Repaint()
f.Canvas.Brush.Color = clYellow
f.Canvas.Ellipse(98, 37, 245, 180)
Bmp = createBitmap()
Bmp.Width = f.ClientWidth * ZOOM
Bmp.Height = f.ClientHeight * ZOOM
Bmp.Canvas.Brush.Color = clYellow
--SetMapMode(Bmp.Canvas.Handle, MM_ISOTROPIC)
SetWindowExtEx(Bmp.Canvas.Handle, 100, 100, nil)
SetViewportExtEx(Bmp.Canvas.Handle, 100 * ZOOM, 100 * ZOOM, nil)
SetStretchBltMode(Bmp.Canvas.Handle, HALFTONE)
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, f.Canvas.Handle, 0, 0, SRCCOPY)
Bmp.Canvas.Ellipse(98, 37, 245, 180)
StretchMode = SetStretchBltMode(f.Canvas.Handle, HALFTONE)
StretchBlt(f.Canvas.Handle, 0, 0, f.ClientWidth * ZOOM, f.ClientHeight * ZOOM,
Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, SRCCOPY)
SetStretchBltMode(f.Canvas.Handle, _StretchMode)
f.Canvas.TextOut(10,10, "With HALFTONE Antialiasing")
Bmp.Destroy()
btn.Enabled = false
end
f.Show()
btn.OnClick = btnClick |
Ref : https://binaryworld.net/Main/CodeDetail.aspx?CodeId=3776
Note ;
Actually I try to use GDI+ on my Windows 10 64 bit CE 7.4 64 Bit, return "Error:Failure determining what gdiplus.GdiplusStartup means".
Seem the GdiplusStartup not call/loaded by CE.
Code: | GdiplusStartupInput = {}
GdiplusStartupInput.GdiplusVersion = 1
GdiplusStartupInput.DebugEventCallback = nil
GdiplusStartupInput.SuppressBackgroundThread = false
GdiplusStartupInput.SuppressExternalCodecs = false
function GdiplusStartup(token, inputbuf, outputbuf)
inputbuf = GdiplusStartupInput
outputbuf = 0
return executeCodeLocalEx("gdiplus.GdiplusStartup", token, inputbuf, outputbuf)
end
local mhToken ----- this is a pointer (ULONG) ?? not sure what value must set here!!
function UserControl_Initialize()
local tGpInput = GdiplusStartupInput
tGpInput.GdiplusVersion = 1
if GdiplusStartup(mhToken, tGpInput) then
showMessage("Unable to init GDI+")
return nil
end
GdipCreateSolidFill(0xFF00FF00, mhBrush)
end |
Anyhow, there is an old script in this forum, to reduce anti aliasing :
Code: | if f then f.destroy() end
f=createForm()
f.Width = 600
f.Height = 400
function setShape(str, vv)
local vx = str.Width;
local vy = str.Height;
if (bm1) then bm1.destroy() end
if (bm2) then bm2.destroy() end
local multAmount = 10;
local multOffset = 5;
bm1 = createBitmap(vx * multAmount, vy * multAmount)
bm1.Canvas.clear();
bm1.Canvas.Pen.Width = 1;
bm1.Canvas.AntialiasingMode = amOn;
bm1.Canvas.roundRect(0 + multOffset, 0 + multOffset, vx * multAmount - multOffset, vy * multAmount - multOffset, vv * multAmount, vv * multAmount);
bm2 = createBitmap(vx, vy)
bm2.Canvas.clear();
bm2.Canvas.Pen.Width = 1;
bm2.Canvas.AntialiasingMode = amOn;
bm2.Canvas.drawWithMask(0, 0, vx, vy, bm1, 0, 0, vx * multAmount, vy * multAmount);
str.setShape(bm2);
end
for i = 1, 3 do
p = createPanel(f);
p.setSize(140, 140);
p.setPosition(i * 100, 50);
p.Color = i * 50;
setShape(p, 200);
end |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Sun Jan 08, 2023 1:42 am Post subject: |
|
|
Corroder wrote: | Anyhow, there is an old script in this forum, to reduce anti aliasing | Hey hey, I sent the original post, but the result is still not ideal
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 08, 2023 2:44 am Post subject: |
|
|
.lua wrote: | Corroder wrote: | Anyhow, there is an old script in this forum, to reduce anti aliasing | Hey hey, I sent the original post, but the result is still not ideal |
Yes, I see you were sent the original post and the solution by atom0s.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Sun Jan 08, 2023 6:21 am Post subject: |
|
|
Corroder wrote: | Yes, I see you were sent the original post and the solution by atom0s. | I always feel that CE is subject to many programming restrictions and cannot use the API conveniently
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Sun Jan 08, 2023 2:27 pm Post subject: |
|
|
CE = Television
Drawings = Phone
If the TV does not have built-in screen recording (If it did, the footage would be in HD quality ), you record the screen with the phone and this creates some pixel intoxication.
Here's a different approach to CE and some features.
Instead of looking for quality for drawing, use a few quality pictures.
_________________
|
|
Back to top |
|
|
.lua Expert Cheater Reputation: 1
Joined: 13 Sep 2018 Posts: 189
|
Posted: Sun Jan 08, 2023 10:36 pm Post subject: |
|
|
AylinCE wrote: | Instead of looking for quality for drawing, use a few quality pictures. | Nevertheless, learning painting methods is very helpful to the program or myself
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|