找回密码
 加入
搜索
楼主: wangms

[GUI管理] 【已解决】GDI+绘制分层窗口不分层

  [复制链接]
 楼主| 发表于 2015-4-3 16:34:20 | 显示全部楼层
谦虚啦!还望以后多多批评指正和指导。
 楼主| 发表于 2015-4-4 13:49:46 | 显示全部楼层
本帖最后由 wangms 于 2015-4-4 13:52 编辑

不见高手出手帮忙,还是自己一点一点试吧,终于试出来了!
#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <GDIPlusEx.au3>

Opt("GUIOnEventMode", 1) 

Local $sText = "Music site Spotify *compiled a list of the most-streamed female artists on International Women’s Day, and Rihanna *reigns supreme as the top female artist among all Spotify listeners worldwide, reported Reuters. This most-streamed female artist for the third year in a row had a smash hit with her Eminem collaboration, The Monster, last year. The song has been streamed over 200 million times on Spotify. With this service, users don’t download content, rather it is seamlessly delivered to them via the Internet. Katy Perry, Beyonce, Lana Del Rey and Lady Gaga were next up on the list." & @CRLF
$sText &= "新浪财经讯周一早盘,沪指高开低走后,盘中在地产的带领下,金融、有色、煤炭等权重集体发力,沪指拉升,再上3400点,突破前期3406点的高点,创出67个月来的新高;临近午间收盘,券商、银行、保险直线拉升,带动大盘走高;午后,沪指再新高后小幅回落,尾盘再度走高,创出2449.30点的67个月新高;截至收盘,沪指报3449.30点,涨2.26%;深成指报12017.77点,涨2.60%;创业板报2142.67点,涨3.56%。大数据100指数涨3.31%。两市共成交9118亿元。"

Global $hCallback = DllCallbackRegister("YourFunc", "int", "hWnd;uint;wparam;lparam");函数名,返回值,参数
Global $ptrCallback = DllCallbackGetPtr($hCallback)
 
$hGUI = GUICreate("无背景色", 600, 500, -1 , -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetOnEvent($GUI_EVENT_SECONDARYUP, '_GUIDelete', $hGUI) 
$nCtrlId = GUICtrlCreatePic("", 0, 0, 600, 500,-1,$GUI_WS_EX_PARENTDRAG)
;$nCtrlId = GUICtrlCreateLabel("", 0, 0, 600, 500, -1, $GUI_WS_EX_PARENTDRAG)
$hPicWnd = GUICtrlGetHandle($nCtrlId)
GUISetBkColor(0x888888, $hGui)
_API_SetLayeredWindowAttributes($hGui, 0x888888)


;设置lable控件的处理函数,也就是所谓的控件子类化
Global $hOldProc = _WinAPI_SetWindowLong($hPicWnd, $GWL_WNDPROC, $ptrCallback)
 
GUISetState()
 
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Exit
 
Func YourFunc($hWnd, $iMsg, $wParam, $lParam)
        Local $au3Dir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\Autoit", "InstallDir");au3安装目录
        Switch $iMsg
                Case $WM_PAINT
                        Local $tPAINTSTRUCT
                        Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
                        ;获取控件长高
                        Local $HWND_CX = _WinAPI_GetWindowWidth($hWnd)
                        Local $HWND_CY = _WinAPI_GetWindowHeight($hWnd)
                        ;开始GDI+
                        _GDIPlus_Startup()
                        ;获取画布,这是从DC获取,还可以用_GDIPlus_GraphicsCreateFromHWND($hWnd)从控件句柄获取,使用完成要释放画布_GDIPlus_GraphicsDispose($hGraphics)
                        $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
                        ;根据画布创建位图对象,我们等会的画图均是针对位图来操作的,也就是没有直接画在画布上,就是所谓的双缓冲画图
                        $hBitmap = _GDIPlus_BitmapCreateFromGraphics($HWND_CX, $HWND_CY, $hGraphics)
                        ;获取位图对象的画布,图就画在位图的画布上
                        $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
                        ;用颜色0xFFE0E0E0清除画布,GDI+的颜色全是ARGB格式,A是透明度,RGB是红绿蓝,这里FF就是不透明,E0E0E0是红绿蓝成分
                    ;    _GDIPlus_GraphicsClear($hBackbuffer, 0xFFE0E0E0)
                        _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000)
                        _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2);平滑模式,2为8*8抗距齿
                                        ;    $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)           ;创建实心画笔对象.
                                                $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)           ;创建实心画笔对象.
                                                $hFormat = _GDIPlus_StringFormatCreate()                  ;创建字符串格式对象.
                                                $hFamily = _GDIPlus_FontFamilyCreate('Arial')              ;创建字体族对象.
                                                $hFont = _GDIPlus_FontCreate($hFamily, 16, 0)         ;创建字体对象.
                                                $tLayout = _GDIPlus_RectFCreate(0, 0, 600, 500)    ;创建 $tagGDIPRECTF(图形填充矩形) 结构.  暂按特别高的高度、规定的宽度测量。
                                                $aInfo = _GDIPlus_GraphicsMeasureString($hBackbuffer,  $sText, $hFont, $tLayout, $hFormat)  ;测量字符串尺寸. 
                                                $iFontHeight = _GDIPlus_FontGetHeight ( $hFont, $hBackbuffer )      ;获取当前指定图形对象中某种字体的行距单位.  测量行距特别准确!比 GetStringDimensions、_GetTabbedStringSize 测量得要精确多得多。
                                                _GDIPlus_GraphicsDrawStringEx($hBackbuffer,  $sText, $hFont, $aInfo[0], $hFormat, $hBrush)   ;绘制字符串(使用数据结构).
                                                _GDIPlus_BrushDispose($hBrush);画刷用完要释放

                        ;画在位图画布上的图形,在$hBitap上,把$hBitmap画入DC的画布,也就在DC上显示了,双缓冲画图时间再长,画入DC画布就一次操作,图形不会闪烁
                        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 600, 500)
                        _GDIPlus_BitmapDispose($hBitmap)
                        _GDIPlus_GraphicsDispose($hBackbuffer)
                        _GDIPlus_GraphicsDispose($hGraphics)
                        _GDIPlus_Shutdown()
                        _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
                        Return 0
        EndSwitch
        Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lParam);没有处理的消息让原先的处理程序处理
EndFunc   ;==>YourFunc

Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
        Local Const $AC_SRC_ALPHA = 1
        Local Const $ULW_ALPHA = 2
        Local Const $LWA_ALPHA = 0x2
        Local Const $LWA_COLORKEY = 0x1
        If Not $isColorRef Then
                $i_transcolor = Hex(String($i_transcolor), 6)
                $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
        EndIf
        Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
        Select
                Case @error
                        Return SetError(@error, 0, 0)
                Case $Ret[0] = 0
                        Return SetError(4, 0, 0)
                Case Else
                        Return 1
        EndSelect
EndFunc   ;==>_API_SetLayeredWindowAttributes

Func _GUIDelete()
        GUIDelete()
        Exit
EndFunc   ;==>_GUIDelete
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 00:50 , Processed in 0.064368 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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