#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <GDIPlusEx.au3>
;注册回调函数
Global $hCallback = DllCallbackRegister("YourFunc", "int", "hWnd;uint;wparam;lparam");函数名,返回值,参数
Global $ptrCallback = DllCallbackGetPtr($hCallback)
GUICreate("侧写lable", 300, 200)
Global $nlableId = GUICtrlCreateLabel("中文和ENGLISH", 10, 10, 20,130)
Global $hlableWnd = GUICtrlGetHandle($nlableId)
;设置lable控件的处理函数,也就是所谓的控件子类化
Global $hOldProc = _WinAPI_SetWindowLong($hlableWnd, $GWL_WNDPROC, $ptrCallback)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
ExitLoop
Case $nlableId
ShellExecute("www.autoitx.com")
EndSwitch
WEnd
GUIDelete()
Exit
Func YourFunc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_PAINT
Local $tPAINTSTRUCT;接收_WinAPI_BeginPaint返回的$tagPAINTSTRUCT结构,这结构内部参数我还不清晰
;获取控件DC并消除WM_PAINT消息,这函数一定要用_WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)解除
Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
;获取控件长高
Local $HWND_CX = _WinAPI_GetWindowWidth($hWnd)
Local $HWND_CY = _WinAPI_GetWindowHeight($hWnd)
Local $sText = _WinAPI_GetWindowText($hWnd);获取窗口标题,就是lable上的文字
;开始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)
;~ _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF);这句可以看lable的大小
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2);平滑模式,2为8*8抗距齿
;字顶朝左的写法
_GDIPlus_GraphicsTranslateTransform($hBackbuffer, 0, $HWND_CY);画布下移$HWND_CY控件高度,也就是画布的原点到了控件左下角
_GDIPlus_GraphicsRotateTransform($hBackbuffer, -90);画布旋转-90度,即逆时针绕原点转动90度
;下面是;字顶朝右的写法
;~ _GDIPlus_GraphicsTranslateTransform($hBackbuffer, $HWND_CX, 0);画布下移$HWND_CY控件高度,也就是画布的原点到了控件左下角
;~ _GDIPlus_GraphicsRotateTransform($hBackbuffer, 90);画布旋转-90度,即逆时针绕原点转动90度
_GDIPlus_GraphicsDrawString($hBackbuffer, $sText, 0, 0, "Arial", 10);我感觉中文9好看,英文10好看
;画在位图画布上的图形,在$hBitap上,把$hBitmap画入DC的画布,也就在DC上显示了,双缓冲画图时间再长,画入DC画布就一次操作,图形不会闪烁
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $HWND_CX, $HWND_CY)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Return _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT);返回,一定要用_WinAPI_EndPaint($hWnd, $tPAINTSTRUCT) 结束WM_PAINT
EndSwitch
Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lParam);没有处理的消息让原先的处理程序处理
EndFunc ;==>YourFunc
|