Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


PyQt-Using code to realize the form without border shadow

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Sun Aug 16, 2020 6:00 am    Post subject: PyQt-Using code to realize the form without border shadow Reply with quote

Code:
#coding:utf-8
'''
Created on 2015��8��1��

@author: guowu
'''
from PyQt4.QtGui import QWidget, QApplication, QPainterPath, QPainter, QBrush,\
    QColor, QPen
from PyQt4.QtCore import Qt, QSize, QRect, QPoint
import sys
import math
class TestFrame(QWidget):
    def __init__(self,parent=None):
        super(TestFrame,self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground,True)
        self.setFixedSize(QSize(500,500))
        self.currentPos = None
   
    def mousePressEvent(self,event):
        self.currentPos = event.pos()
   
    def mouseMoveEvent(self,event):
        self.move(QPoint(self.pos()+event.pos()-self.currentPos))
       
    def paintEvent(self,event):
        m = 9
       
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.addRect(m, m, self.width()-m*2, self.height()-m*2)
       
        painter = QPainter(self)
        #painter.drawLine(QLineF)
        #painter.setRenderHint(QPainter.Antialiasing, True)
        painter.fillPath(path, QBrush(Qt.white))
     
        color = QColor(100, 100, 100, 30)
        #for(int i=0; i<10; i++)
       
        for i in range(m):
            path = QPainterPath()
            path.setFillRule(Qt.WindingFill)
            path.addRoundRect(m-i, m-i, self.width()-(m-i)*2, self.height()-(m-i)*2,1,1)
            color.setAlpha(90 - math.sqrt(i)*30)
            painter.setPen(QPen(color,1,Qt.SolidLine))
            painter.drawRoundRect(QRect(m-i, m-i, self.width()-(m-i)*2, self.height()-(m-i)*2), 0,0)
           
#             path = QPainterPath()
#             path.setFillRule(Qt.WindingFill)
#             path.addRect(m-i, m-i, self.width()-(m-i)*2, self.height()-(m-i)*2)
#             color.setAlpha(90 - math.sqrt(i)*30)
#             painter.setPen(QPen(color,1))
#             painter.drawPath(path)
         
   
   
   

if __name__ == "__main__":
    app = QApplication(sys.argv)
    c = TestFrame()
    c.show()
    app.exec_()

Is it feasible to translate the above code to ce7.1。
Or how to use the windows API - updatelayeredwindow。



Form shadow.png
 Description:
 Filesize:  6.35 KB
 Viewed:  1665 Time(s)

Form shadow.png


Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Aug 19, 2020 3:24 pm    Post subject: Reply with quote

#1. Try using dwmapi.dll and CS_DROPSHADOW (but the form shadow is failed)

Code:
UDF1.OnMouseDown = function()
UDF1.dragNow() end

function DwmIsCompositionEnabled(en)
 return executeCodeLocalEx("dwmapi.DwmIsCompositionEnabled",en)
end

function DwmExtendFrameIntoClientArea(hwnd, MARGINS)
 return executeCodeLocalEx("dwmapi.DwmExtendFrameIntoClientArea", hwnd, MARGINS)
end

function DwmSetWindowAttribute(hwnd, attr, attrValue, attrSize)
 return executeCodeLocalEx("dwmapi.DwmSetWindowAttribute", hwnd, attr, attrValue, attrSize)
end

function GetClassLong(hWnd, nIndex)
 return executeCodeLocalEx('user32.GetClassLongA', hWnd, nIndex)
end

function SetClassLong(hWnd, nIndex, dwNewLong)
 return executeCodeLocalEx('user32.SetClassLongA', hwnd, nIndex, dwNewLong)
end

function DropShadow(hwnd)
 SetClassLong(hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE) | CS_DROPSHADOW)
 return CS_DROPSHADOW
end

CS_DROPSHADOW = 0x20000
GCL_STYLE = -26

function glassForm(hwnd, Ver, v, l, r, t, b)
 DwmSetWindowAttribute(hwnd, 2, v, 4)
 margins = createMemoryStream();
 margins.writeDword(l) --Left)
 margins.writeDword(r) --Right)
 margins.writeDword(t) --Top)
 margins.writeDword(b) --Bottom)
 DwmIsCompositionEnabled(Ver)
 DwmExtendFrameIntoClientArea(hwnd, margins.Memory)
 DropShadow(hwnd)
end

UDF1.Show()
glassForm(UDF1.handle, 6.2, 2, 5, 5, 5, 5)


Also, I don't know yet how to change extended frame color as the form shadow.
Note: by setting the margins to -1 will give glass effect on the form.

#2. More easy for me

1) Create an image having the desired drop shadow using photoshop or any other tool.
2) Use this image as background image of your form.
3) Set FormBorderStyle property of the form to None.
4) You are done!

See attach image for #2 LOL!



form shadow.png
 Description:
 Filesize:  18.84 KB
 Viewed:  1603 Time(s)

form shadow.png



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 202

PostPosted: Wed Aug 19, 2020 9:05 pm    Post subject: Reply with quote

Corroder wrote:
#1. Try using dwmapi.dll and CS_DROPSHADOW (but the form shadow is failed)
I don't know where the problem is because there is no indication of where the error is

Corroder wrote:

#2. More easy for me

1) Create an image having the desired drop shadow using photoshop or any other tool.
2) Use this image as background image of your form.
3) Set FormBorderStyle property of the form to None.
4) You are done!

See attach image for #2 LOL!
#2. in practice, the background of the form is still white


#1.png
 Description:
 Filesize:  428.03 KB
 Viewed:  1575 Time(s)

#1.png



#2.png
 Description:
 Filesize:  331.04 KB
 Viewed:  1576 Time(s)

#2.png


Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Aug 20, 2020 12:20 am    Post subject: Reply with quote

#2. > It's depend on how you create a rectangle image with drop shadow and save as a transparent image. I am using photoshop CC 2019 to create a borderless form with shadow and save as a png file, which you can see on attached image.

Code:
if f then f.destroy() end

f = createForm()
f.setSize(600,400)
f.Position = 'poScreenCenter'
f.BorderStyle = 'bsNone'

bg = createImage(f)
bg.Align = 'alClient'
bg.Stretch = true
bg.Picture.loadFromStream(findTableFile('formShadow2.png').Stream)
bg.OnMouseDown =  function() f.dragNow() end

f.Show()


Also, you can try set form layered attribute to make form transparent and attach your borderless form with shadow image as form background.

EDIT:
In Delphi should be like this.

Code:
procedure TForm1.FixSysShadowOrder;

  function FindSysShadowOrderProc(WindowHandle: HWND; // handle to window
    Form: TForm1 // application-defined value, 32-bit
    ): BOOL; stdcall;
  var
    Buffer: array [0 .. 255] of char;
    Rect: TRect;
  begin
    Result := True;
    if IsWindowVisible(WindowHandle) then
    begin
      // this code  search for SysShadow window created for this window.
      GetClassName(WindowHandle, Buffer, 255);
      if 0 <> AnsiStrComp(Buffer, PChar('SysShadow')) then
        Exit;

      GetWindowRect(WindowHandle, Rect);
      if (Rect.Left <> Form.Left) or (Rect.Top <> Form.Top) then
        Exit;

      Form.FSysShadowHandle := WindowHandle;
      // stop enumeration
      Result := False;
    end;
  end;

begin
  if not(csDesigning in ComponentState) and
    ((GetClassLong(Handle, GCL_STYLE) and CS_DROPSHADOW) = CS_DROPSHADOW)
    and IsWindowVisible(Handle) then
  begin
    // for speed, proper SysShadow handle is cached
    if FSysShadowHandle = 0 then
      EnumThreadWindows(GetCurrentThreadID(), @FindSysShadowOrderProc,
        lParam(Self));
    // if SysShadow exists, change its z-order, and place it directly below this window
    if FSysShadowHandle <> 0 then
      SetWindowPos(FSysShadowHandle, Handle, 0, 0, 0, 0,
        SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOOWNERZORDER or SWP_NOSIZE);
  end;
end;



Capture.JPG
 Description:
Using an image to create borderless form with shadow
 Filesize:  13.37 KB
 Viewed:  1565 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites