Lessons XIV : Đưa ảnh yêu thích lên màn hình làm việc

Đưa ảnh yêu thích lên màn hình làm việc

Thứ sáu, 05 Tháng 9 2008 01:44 blood_wizard Hướng dẫn lập trình AutoIT
Email In

Bạn sử dụng đoạn code sau

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3> #NoTrayIcon Global Const $AC_SRC_ALPHA = 1 Global $hGUI, $Im
Opt("MustDeclareVars", 1)
$hGUI = GUICreate('',250,250,400,300,$WS_BORDER,$WS_EX_LAYERED)
_GDIPlus_Startup()
$im = _GDIPlus_ImageLoadFromFile(@ScriptDir&'\Images\batquai.png' )
SetBitMap($hGUI, $Im, 255)
GUISetState()
GUIRegisterMsg($WM_HSCROLL , "WM_HSCROLL" )
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST" )
WinSetOnTop('','',1)
do
until GUIGetMsg() =$GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($Im)
_GDIPlus_Shutdown()
Func WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
SetBitMap($hGUI, $Im, 255)
EndFunc
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $hGUI) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc 
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize )
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha" , $iOpacity )
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC (0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC ($hMemDC)
EndFunc

Sau đó tạo 1 folder mới tên Images và cho ảnh vào trong thư mục này( Lưu ý: ảnh phải được đặt tên là batquai.png và có kích thước tối đa là 200×200 pixels)

Trao đổi trong diễn đàn: http://www.huongdanlaptrinh.com/trung-tam-tin-hoc/AutoIT/28-Dua-anh-yeu-thich-len-man-hinh-lam-viec.html

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: