Sign in to follow this  
Followers 0
wolf9228

GUI Background Without any problem

5 posts in this topic

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Run_After="ress.exe "%out%""
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Const $Style_Stretch = 1 , $Style_Tile = 2 , $Style_Center = 3
Global $hBitmap , $ImageHeight , $ImageWidth , $Image_Style
$Form = GUICreate("Form", 500, 500, 303, 100)
LoadBitmap_FromFile("Style_Stretch.bmp" ,$Style_Stretch)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
if $hBitmap Then
$D_C = _WinAPI_CreateCompatibleDC($wParam)
$Object = _WinAPI_SelectObject($D_C, $hBitmap)

Select
Case $Image_Style = 1
StretchBlt($wParam, 0, 0 , _WinAPI_GetClientWidth($hWnd), _WinAPI_GetClientHeight($hWnd), $D_C, 0, 0, _
$ImageWidth , $ImageHeight, $SRCCOPY)


Case $Image_Style = 2
For $i1 = 0 To (_WinAPI_GetClientHeight($hWnd) - 1) Step $ImageHeight
For $i2 = 0 To (_WinAPI_GetClientWidth($hWnd) - 1) Step $ImageWidth
_WinAPI_BitBlt($wParam,$i2,$i1, _WinAPI_GetClientWidth($hWnd), _WinAPI_GetClientHeight($hWnd), _
$D_C ,0,0,$SRCCOPY)
Next
Next

Case $Image_Style = 3
if ($ImageWidth < _WinAPI_GetClientWidth($hWnd)) Then
$i2 = ((_WinAPI_GetClientWidth($hWnd) - $ImageWidth) / 2)
Else
$i2 = 0
EndIf
if($ImageHeight < _WinAPI_GetClientHeight($hWnd)) Then
$i1 = ( (_WinAPI_GetClientHeight($hWnd) - $ImageHeight) / 2)
Else
$i1 = 0
EndIf
_WinAPI_BitBlt($wParam,$i2,$i1,_WinAPI_GetClientWidth($hWnd), _WinAPI_GetClientHeight($hWnd) , _
$D_C ,0,0,$SRCCOPY)
EndSelect

$Object = _WinAPI_SelectObject($D_C, $Object)

Return True
EndIf
EndFunc

Func StretchBlt($hdcDest,$nXOriginDest,$nYOriginDest,$nWidthDest,$nHeightDest,$hdcSrc,$nXOriginSrc, _
$nYOriginSrc,$nWidthSrc,$nHeightSrc,$dwRop)
$DllCall = DllCall("Gdi32.dll" ,"int","StretchBlt","hwnd",$hdcDest,"int",$nXOriginDest,"int",$nYOriginDest,"int",$nWidthDest , _
"int",$nHeightDest,"hwnd",$hdcSrc,"int",$nXOriginSrc,"int",$nYOriginSrc,"int",$nWidthSrc,"int",$nHeightSrc,"long",$dwRop)
Return $DllCall[0]
EndFunc


Func LoadBitmap_FromFile($sFileName ,$ImageStyle)
$IMAGE_BITMAP = 0
$LR_LOADFROMFILE = 0x0010
$hBitmap = _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0),$sFileName,$IMAGE_BITMAP ,0,0,$LR_LOADFROMFILE)
_GDIPlus_Startup ()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
$ImageWidth = _GDIPlus_ImageGetWidth ($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight ($hImage)
$Image_Style = $ImageStyle
_GDIPlus_ShutDown ()
EndFunc

Func LoadBitmap_FromResources($resource_Name ,$ImageStyle)
$hBitmap = _WinAPI_LoadBitmap(_WinAPI_GetModuleHandle(0), $resource_Name)
_GDIPlus_Startup ()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
$ImageWidth = _GDIPlus_ImageGetWidth ($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight ($hImage)
$Image_Style = $ImageStyle
_GDIPlus_ShutDown ()
EndFunc


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



Very nice wolf9228, I like the tiled version when you have

$Form = GUICreate("Form", 128, 128, 303, 100,BitOr($GUI_SS_DEFAULT_GUI , $WS_SIZEBOX))

I think you should set those styles in your example, but it messes up the center version.

It's not obvious to me what the advantage is of the centre and stretched versions over using GuiCtrlCreatePic with the relevant resizing options which would be simpler.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Very nice wolf9228, I like the tiled version when you have

$Form = GUICreate("Form", 128, 128, 303, 100,BitOr($GUI_SS_DEFAULT_GUI , $WS_SIZEBOX))

I think you should set those styles in your example, but it messes up the center version.

It's not obvious to me what the advantage is of the centre and stretched versions over using GuiCtrlCreatePic with the relevant resizing options which would be simpler.

The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.

Problem when loading the Image from the resource to be the background of the Program

There is no function to perform this operation Without shortcomings and problems

And also in the C++ 6 no function of this operation Without shortcomings

You can use this message with the library's GDIPlus And with many types of images

Not Supported by the GUICtrlCreatePic function Such as this example

I translated this reply And I'm sorry if it contains clerical errors

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Opt("OnExitFunc", "endscript")
Global $hImage 
$Form = GUICreate("Form", 500, 500, 303, 100)
_GDIPlus_Startup ()
 LoadImage_FromFile("C:\CaptureWiz011.png")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)

   

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
$size = WinGetPos($hWnd)
 $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($wParam)
_GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $size[2] - 8, $size[3] - 31)
 Return True
EndFunc




Func LoadImage_FromFile($sFileName )
$hImage = _GDIPlus_ImageLoadFromFile ($sFileName)
EndFunc



Func endscript()
_GDIPlus_ShutDown ()
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Very Nice!! I too like the tiled look, they all look good on Vista...

Share this post


Link to post
Share on other sites

Very Nice!! I too like the tiled look, they all look good on Vista...

Thank you :D


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0