Jump to content
Sign in to follow this  
PhoenixXL

Transparent Background Edit Control WinAPI/GDI+ Implementation Issues

Recommended Posts

PhoenixXL

Hello members..

I have tried to make a transparent edit control with a transparent background.

The edit has a transparent background, but the repaint and the text delete is not working properly.

The text gets overlapped, doesn't delete upon pressing BackSpace.

IDK what am I missing. Thanks for your time and help :)

I'm new to GDI+ and hence I took some references, the following are the respective links..

http://www.drx.dk/bktxtedit.php

http://codepad.org/ajqIvwl1

http://forum.tuts4you.com/topic/30054-solved-c-winapi-transparent-editbox/

Here is my starting code.

#include-once
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <APIConstants.au3>
#include <EditConstants.au3>

; Unregister, Unsubclass upon Exitting
OnAutoItExitRegister("_AutoExit")
;...Variables Global.---
Global _
$hbmp, _;
$hbitmapDC, _;
$hfont, _;
$poldWndProc, _;
$hEdit;
; Register callback function and obtain handle to _New_WndProc
Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam")
; Get pointer to _New_WndProc
Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc)


Example()

Func Example()
Local $myedit, $msg

GUICreate(@ScriptName) ; will create a dialog box that when displayed is centered

GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_MSGHANDLER")
$iEdit = GUICtrlCreateEdit("", 10, 10, -1, -1, 0, 0)
$hEdit = GUICtrlGetHandle(-1)
$poldWndProc = _SubClass($hEdit, $___pNew_WndProc)
GUIRegisterMsg($WM_COMMAND, "WM_MSGHANDLER")


GUISetState()

_loadBitmap()
$hfont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)


; Run the GUI until the dialog is closed
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_MINIMIZE
MsgBox(0, 0, GUICtrlRead($iEdit))
EndSwitch
WEnd
GUIDelete()
EndFunc   ;==>Example

Func _loadBitmap()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hEdit)
$hbmp = _GDIPlus_BitmapCreateFromGraphics($hGraphic, _WinAPI_GetWindowWidth($hEdit), _WinAPI_GetWindowHeight($hEdit))
$hbitmapDC = _WinAPI_CreateCompatibleDC(0); current screen DC
_WinAPI_SelectObject($hbitmapDC, $hbmp);
_GDIPlus_GraphicsDispose($hGraphic)
EndFunc   ;==>_loadBitmap

Func WM_MSGHANDLER($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_CTLCOLOREDIT
_WinAPI_SetBkMode($wParam, $TRANSPARENT);
_WinAPI_SetTextColor($wParam, 0xFF0000);

Return _WinAPI_GetStockObject($HOLLOW_BRUSH);
Case $WM_COMMAND ;<<<<<<<<<<<<<<<<<< Don't know what to do here..

;tell windows to update the edit box region
If $lParam = $hEdit Then Return _WinAPI_UpdateWindow($lParam)
EndSwitch

Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_MSGHANDLER

Func _SubClass($hWnd, $pNew_WindowProc)
Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc)
If @error Then Return SetError(1, 0, 0)
If $iRes = 0 Then Return SetError(1, 0, 0)
Return SetError(0, 0, $iRes)
EndFunc   ;==>_SubClass

Func _AutoExit()
; Unregister the Prediction
_SubClass($hEdit, $poldWndProc)
; Now free UDF created WndProc
DllCallbackFree($___hNew_WndProc)
EndFunc   ;==>_AutoExit

Func _New_WndProc($hWnd, $iMsg, $wParam, $lParam)
; Process WM_PAINT#cs
Switch $iMsg
Case $WM_PAINT
Local $tPaint = DllStructCreate($tagPAINTSTRUCT)
Local $hDc = _WinAPI_BeginPaint($hWnd, $tPaint)

;PatBlt may even help .. confused ??
_WinAPI_BitBlt($hDc, 0, 0, _WinAPI_GetWindowWidth($hWnd), _WinAPI_GetWindowHeight($hWnd), $hbitmapDC, 0, 0, $SRCCOPY)

Local $editStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $textStyle;
If BitAND($editStyle, $ES_CENTER) Then
$textStyle = $DT_CENTER;
ElseIf BitAND($editStyle, $ES_LEFT) Then
$textStyle = $DT_LEFT;
ElseIf BitAND($editStyle, $ES_RIGHT) Then
$textStyle = $DT_RIGHT;
EndIf

If (Not BitAND($editStyle, $ES_MULTILINE)) Then
$textStyle = BitOR($DT_TOP, $textStyle) ;
Else
$textStyle = BitOR($DT_EDITCONTROL, $textStyle) ;
EndIf

Local $Caption = _WinAPI_GetWindowText($hWnd);
_WinAPI_SetBkMode($hDc, $TRANSPARENT);
_WinAPI_SetTextColor($hDc, 0xFF0000);

Local $rcEC = _WinAPI_GetClientRect($hWnd);
_WinAPI_SelectObject($hDc, $hfont);
_WinAPI_DrawText($hDc, $Caption, $rcEC, $DT_EDITCONTROL);

_Winapi_EndPaint($hWnd, $tPaint);
Return ; Message Handled
Case $WM_ERASEBKGND ;<<<<<<<<<<<<<<< Don't know what to do here..

#cs
Local $tClientRect = _WinAPI_GetClientRect($hWnd)
Local $hBrush = _WinAPI_GetStockObject($HOLLOW_BRUSH)

_WinAPI_FillRect($wParam, DllStructGetPtr($tClientRect), $hBrush)
_WinAPI_DeleteObject($hBrush)

Return
#ce
EndSwitch

; Pass to the Original Window Procedure.
Return _WinAPI_CallWindowProc($poldWndProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_New_WndProc

I have already tried to set the bkcolor of edit as MENU color, that makes it background but now I'm trying with a gradient background and therefore been into issues

Kindly help me

Thanks :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
stormbreaker

A transparent edit control (from the forum search):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

$hGUI = GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered
$hEdit = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 2, 2, 394, 268)
GUISetState()

_GuiCtrlMakeTrans($hEdit, 100)
Sleep(4000)
Exit

Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

global $pHwnd, $nHwnd, $aPos, $a

$hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
If $hWnd = 0 then Return SetError(1,1,0)
$pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
If $pHwnd[0] = 0 then Return SetError(1,2,0)
$aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
If @error then Return SetError(1,3,0)
$nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
If $nHwnd = 0 then Return SetError(1,4,0)
$a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
If $a[0] = 0 then Return SetError(1,5,0)
If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
GUISetState(@SW_Show,$nHwnd);show the new child gui

WinSetTrans($nHwnd,"",$iTrans);set the transparency
If @error then Return SetError(1,7,0)
GUISwitch($pHwnd[0]);switch back to the parent Gui

Return $nHwnd;Return the handle for the new Child gui

EndFunc

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites
PhoenixXL

Sorry and apologies for my inefficient explanation.

I want an edit control with a transparent background.

I have checked the Forum and havent found any clue.


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

I feel there is some error with the _Winapi_RedrawWindow part

When I just use _WInapi_UpdateWindow, writing becomes clear but the erase part is messed.

with Redraw both get messed up.. :huh:


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

The edit has a transparent background

What do you mean by that? I have this which does not seem to be transparent at all. Can you show me what you have?

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

I have again updated the example..

by transparent I mean that there should be no background. i.e. the white color.

The underlying color should be displayed rather.

This is what I have

#include-once
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <APIConstants.au3>
#include <EditConstants.au3>

; Unregister, Unsubclass upon Exitting
OnAutoItExitRegister("_AutoExit")
;...Variables Global.---
Global _
$hbmp, _;
$hbitmapDC, _;
$hfont, _;
$poldWndProc, _;
$hEdit;
; Register callback function and obtain handle to _New_WndProc
Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam")
; Get pointer to _New_WndProc
Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc)


Example()

Func Example()
Local $myedit, $msg

GUICreate(@ScriptName) ; will create a dialog box that when displayed is centered

GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_MSGHANDLER")
$iEdit = GUICtrlCreateEdit("", 10, 10, -1, -1, 0, 0)
$hEdit = GUICtrlGetHandle(-1)
$poldWndProc = _SubClass($hEdit, $___pNew_WndProc)
GUIRegisterMsg($WM_COMMAND, "WM_MSGHANDLER")


GUISetState()

_loadBitmap()
$hfont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)


; Run the GUI until the dialog is closed
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_MINIMIZE
MsgBox(0, 0, GUICtrlRead($iEdit))
EndSwitch
WEnd
GUIDelete()
EndFunc   ;==>Example

Func _loadBitmap()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hEdit)
$hbmp = _GDIPlus_BitmapCreateFromGraphics($hGraphic, _WinAPI_GetWindowWidth($hEdit), _WinAPI_GetWindowHeight($hEdit))
$hbitmapDC = _WinAPI_CreateCompatibleDC(0); current screen DC
_WinAPI_SelectObject($hbitmapDC, $hbmp);
_GDIPlus_GraphicsDispose($hGraphic)
EndFunc   ;==>_loadBitmap

Func WM_MSGHANDLER($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_CTLCOLOREDIT
_WinAPI_SetBkMode($wParam, $TRANSPARENT);
_WinAPI_SetTextColor($wParam, 0xFF0000);

Return _WinAPI_GetStockObject($HOLLOW_BRUSH);
Case $WM_COMMAND ;<<<<<<<<<<<<<<<<<< Don't know what to do here..

;tell windows to update the edit box region
If $lParam = $hEdit Then Return _WinAPI_UpdateWindow($lParam)
EndSwitch

Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_MSGHANDLER

Func _SubClass($hWnd, $pNew_WindowProc)
Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc)
If @error Then Return SetError(1, 0, 0)
If $iRes = 0 Then Return SetError(1, 0, 0)
Return SetError(0, 0, $iRes)
EndFunc   ;==>_SubClass

Func _AutoExit()
; Unregister the Prediction
_SubClass($hEdit, $poldWndProc)
; Now free UDF created WndProc
DllCallbackFree($___hNew_WndProc)
EndFunc   ;==>_AutoExit

Func _New_WndProc($hWnd, $iMsg, $wParam, $lParam)
; Process WM_PAINT#cs
Switch $iMsg
Case $WM_PAINT
Local $tPaint = DllStructCreate($tagPAINTSTRUCT)
Local $hDc = _WinAPI_BeginPaint($hWnd, $tPaint)

;PatBlt may even help .. confused ??
_WinAPI_BitBlt($hDc, 0, 0, _WinAPI_GetWindowWidth($hWnd), _WinAPI_GetWindowHeight($hWnd), $hbitmapDC, 0, 0, $SRCCOPY)

Local $editStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $textStyle;
If BitAND($editStyle, $ES_CENTER) Then
$textStyle = $DT_CENTER;
ElseIf BitAND($editStyle, $ES_LEFT) Then
$textStyle = $DT_LEFT;
ElseIf BitAND($editStyle, $ES_RIGHT) Then
$textStyle = $DT_RIGHT;
EndIf

If (Not BitAND($editStyle, $ES_MULTILINE)) Then
$textStyle = BitOR($DT_TOP, $textStyle) ;
Else
$textStyle = BitOR($DT_EDITCONTROL, $textStyle) ;
EndIf

Local $Caption = _WinAPI_GetWindowText($hWnd);
_WinAPI_SetBkMode($hDc, $TRANSPARENT);
_WinAPI_SetTextColor($hDc, 0xFF0000);

Local $rcEC = _WinAPI_GetClientRect($hWnd);
_WinAPI_SelectObject($hDc, $hfont);
_WinAPI_DrawText($hDc, $Caption, $rcEC, $DT_EDITCONTROL);

_Winapi_EndPaint($hWnd, $tPaint);
Return ; Message Handled
Case $WM_ERASEBKGND ;<<<<<<<<<<<<<<< Don't know what to do here..

#cs
Local $tClientRect = _WinAPI_GetClientRect($hWnd)
Local $hBrush = _WinAPI_GetStockObject($HOLLOW_BRUSH)

_WinAPI_FillRect($wParam, DllStructGetPtr($tClientRect), $hBrush)
_WinAPI_DeleteObject($hBrush)

Return
#ce
EndSwitch

; Pass to the Original Window Procedure.
Return _WinAPI_CallWindowProc($poldWndProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_New_WndProc
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

I have converted a C++ script of a transparent edit example and it has the same redraw issue (in AutoIt) except if you redraw in addition the edit control on a KEYDOWN WM.

Edit: I have moved the script

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

Yes that is the problem.

Maybe I will find a workaround.

Will post the results in that case

Thanks for help Firefox :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

The script I have posted does not fit your need ? :mellow:

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

The work with pattern works good, everytime a pattern is drawn on the edit background.

But after all its a pattern Brush right ?

I tried it with a linear gradient brush but it fails miserably

Have a look

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3> ;required for: $GUI_EVENT_CLOSE
#include <StaticConstants.au3> ;required for: $GUI_EVENT_CLOSE
#include <Constants.au3>
#include <WinAPIEx.au3> ;url: http://www.autoitscript.com/forum/topic/98712-winapiex-udf/
#include <Color.au3> ;required for: _RGBtoBGR
#include <Debug.au3> ;required for: _Assert
#include <GDIPlus.au3> ;required for: _Assert

#region Global Vars
Global Const $WM_APP_REDRAWWINDOW = $WM_APP + 1

Global $hBrushLin = 0, $_hBitmapBack = 0, $_pfnDefEditProc = 0

Local $hNew_WndProc = DllCallbackRegister("_MyEdit_Proc", "int", "hwnd;uint;wparam;lparam")
Global $_pNew_WndProc = DllCallbackGetPtr($hNew_WndProc)
#endregion Global Vars

#region GUI
Local Const $hGUI = GUICreate("Demo Transparent Edit Control", 358, 208, -1, -1, BitOR($DS_MODALFRAME, $WS_POPUP, $WS_CAPTION, $WS_SYSMENU))
CreateBackground_Static($hGUI)

Global Const $tbMyEdit = GUICtrlCreateEdit("", 15, 16, 240, 176, BitOR($ES_MULTILINE, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL))

;~ GUIRegisterMsg($WM_INITDIALOG, "WM_INITDIALOG")
WM_INITDIALOG($hGUI)
GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUIRegisterMsg($WM_DESTROY, "WM_DESTROY")

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

#region Loop
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

GUIDelete($hGUI)
#endregion Loop

#region WM
Func WM_INITDIALOG($hWnd) ;bool

    $hBrushLin = $hBrushLin ;$hBrushLin is created in CreateBackground_Static as global brush

    ; Subclass edit control
    Local $hWndEdit = _WinAPI_GetDlgItem($hWnd, $tbMyEdit)
;~     _Assert("$hWndEdit <> 0") ;commented, reason: bug
    $_pfnDefEditProc = _WinAPI_SetWindowLong($hWndEdit, $GWL_WNDPROC, $_pNew_WndProc)

    Return False
EndFunc   ;==>WM_INITDIALOG

Func WM_CTLCOLOREDIT($hWnd, $uMsg, $wParam, $lParam) ;HBRUSH
    Local $hBrush = 0

    Switch $uMsg
        Case $WM_CTLCOLOREDIT
            _WinAPI_SetTextColor($wParam, _RGBtoBGR(0x800000))
            _WinAPI_SetBkMode($wParam, $TRANSPARENT)
            $hBrush = $hBrushLin
    EndSwitch

    Return $hBrush
EndFunc   ;==>WM_CTLCOLOREDIT

Func WM_ERASEBKGND($hWnd, $uMsg, $wParam, $lParam) ;bool
    Local $tRect = _WinAPI_GetClientRect($hWnd)
    Local $hOldBrush = _WinAPI_SelectObject($wParam, $hBrushLin)
    _WinAPI_PatBlt($wParam, 0, 0, DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left"), DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top"), $PATCOPY)
    _WinAPI_SelectObject($wParam, $hOldBrush)

    Return True
EndFunc   ;==>WM_ERASEBKGND

Func WM_DESTROY($hWnd, $uMsg, $wParam, $lParam) ;void
    _WinAPI_DeleteObject($_hBitmapBack)
    _WinAPI_DeleteObject($hBrushLin)
EndFunc   ;==>WM_DESTROY
#endregion WM

Func _MyEdit_Proc($hWnd, $uMsg, $wParam, $lParam) ;LRESULT CALLBACK
    Switch $uMsg
        Case $WM_VSCROLL, $WM_HSCROLL, $WM_MOUSEWHEEL, $WM_KEYDOWN
            _WinAPI_PostMessage($hWnd, $WM_APP_REDRAWWINDOW, $hWnd, 0)
        Case $WM_APP_REDRAWWINDOW
            Return _MyEdit_OnRedrawWindow($wParam, $lParam)
    EndSwitch

    Return _WinAPI_CallWindowProc($_pfnDefEditProc, $hWnd, $uMsg, $wParam, $lParam)
EndFunc   ;==>_MyEdit_Proc

Func _MyEdit_OnRedrawWindow($wParam, $lParam) ;HRESULT
    Local $uFlags = BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_ERASE)

    _WinAPI_RedrawWindow($wParam, 0, 0, $uFlags)

    Return 0
EndFunc   ;==>_MyEdit_OnRedrawWindow

Func _RGBtoBGR($iColor) ;by FireFox
    Return "0x" & Hex(_ColorGetRed($iColor), 2) & Hex(_ColorGetGreen($iColor), 2) & Hex(_ColorGetBlue($iColor), 2)
EndFunc   ;==>_RGBtoBGR

Func CreateBackground_Static($hWnd, $iColor_Start = 0x99000000, $iColor_End = 0xDD000000, $iMode = 1)

_GDIPlus_Startup()

$iWidth = _WinAPI_GetWindowWidth($hWnd)
$iHeight = _WinAPI_GetWindowHeight($hWnd)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
_GDIPlus_GraphicsDispose($hGraphic)

$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

;**********************
; Create Line Brush Using minimum number of settings- Brush size same size as Rectangle to fill
$hBrushLin = GDIPlus_CreateLineBrushFromRect(0, 0, $iWidth, $iHeight, -1, -1, $iColor_Start, $iColor_End, 1)

;Fill a rectangle using the above brush
_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrushLin)
;***************************

Local Const $_STM__SETIMAGE = 0x0172, $_SS__BITMAP = 0x0E
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

$iRet = GUICtrlCreatePic('', 0, 0, $iWidth, $iHeight, $SS_BITMAP)
GUICtrlSendMsg(-1, 370, $IMAGE_BITMAP, $hHBitmap)

_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()

GUICtrlSetState(-1, $GUI_DISABLE)

Return $iRet
EndFunc   ;==>CreateBackground_Static

Func GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
$iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
If $WrapMode = -1 Then $WrapMode = 1

$tRect = DllStructCreate("float X;float Y;float Width;float Height")
$pRect = DllStructGetPtr($tRect)
DllStructSetData($tRect, "X", $iX)
DllStructSetData($tRect, "Y", $iY)
DllStructSetData($tRect, "Width", $iWidth)
DllStructSetData($tRect, "Height", $iHeight)

;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
$aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
"int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

$iCount = UBound($aPositions)
$tFactors = DllStructCreate("float[" & $iCount & "]")
$pFactors = DllStructGetPtr($tFactors)
For $iI = 0 To $iCount - 1
DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
Next
$tPositions = DllStructCreate("float[" & $iCount & "]")
$pPositions = DllStructGetPtr($tPositions)
For $iI = 0 To $iCount - 1
DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
Next

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>GDIPlus_CreateLineBrushFromRect
I was just wondering can't it be just transparent as like a Static control, I mean even with the pattern the user could easily distinguish that the background of the GUI is different from that of the edit contol... Can't it just be purely transparent. ? Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

Tried with a RichEdit Control
Till the time it works

#include-once
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Main()

Func Main()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1, 0, $WS_EX_COMPOSITED)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a a transparent Rich Edit Control." & @CRLF & _
            "Press Esc To Exit", 10, 10, 300, 220, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)
    CreateBackground_Static($hGui, 0, 0)

    GUISetState()

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    _GUICtrlRichEdit_Destroy($hRichEdit)
    GUIDelete()

EndFunc   ;==>Main

Func CreateBackground_Static($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $iColor_Start = 0xAA000000, $iColor_End = 0x70000000, $iMode = 1)

    _GDIPlus_Startup()

    If $iWidth < 0 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
    If $iHeight < 0 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    _GDIPlus_GraphicsDispose($hGraphic)

    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    ;**********************
    ; Create Line Brush Using minimum number of settings- Brush size same size as Rectangle to fill
    $hBrushLin = GDIPlus_CreateLineBrushFromRect(0, 0, $iWidth, $iHeight, -1, -1, $iColor_Start, $iColor_End, 1)

    ;Fill a rectangle using the above brush
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrushLin)
    ;***************************

    Local Const $_STM__SETIMAGE = 0x0172, $_SS__BITMAP = 0x0E
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

    $iRet = GUICtrlCreatePic('', $iX, $iY, $iWidth, $iHeight, $_SS__BITMAP)
    Local Const $__IMAGE_BITMAP = 0
    GUICtrlSendMsg(-1, $_STM__SETIMAGE, $__IMAGE_BITMAP, $hHBitmap)

    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_Shutdown()

    GUICtrlSetState(-1, $GUI_DISABLE)

    Return $iRet
EndFunc   ;==>CreateBackground_Static

Func GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

    If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>GDIPlus_CreateLineBrushFromRect

Better Example

#include-once
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Constants.au3>

Main()

Func Main()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1, 0, $WS_EX_COMPOSITED)

    If FileExists(@ScriptDir & "\cute.jpg") = 0 Then InetGet("http://www.picgifs.com/graphics/c/cute/graphics-cute-920618.jpg", @ScriptDir & "\cute.jpg")
    If @error Then Exit 1

    _GDIPlus_Startup()

    Local $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\cute.jpg")

    $hRichEdit = _GUICtrlRichEdit_Create($hGui, @CRLF & @CRLF & "This is a a transparent Rich Edit Control." & @CRLF & _
            "Press Esc To Exit" & @CRLF & @CRLF & "Phoenix XL", 10, 190, 280, 80, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)

    CreateBackground_Static($hGui, 10, 190, 280, 80)    ;comment this to get pure transparency
    CreateBackground_Static($hGui, 0, 0, 320, 350, $hBitmap)


    _GDIPlus_BitmapDispose($hBitmap)

    GUISetState()

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd


    _GUICtrlRichEdit_Destroy($hRichEdit)
    _GDIPlus_Shutdown()

    GUIDelete()

EndFunc   ;==>Main

Func CreateBackground_Static($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $hBitmap = 0, $iColor_Start = 0xAA000000, $iColor_End = 0x70000000, $iMode = 1)

    If $iWidth < 0 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
    If $iHeight < 0 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)

    Local $hGraphic

    If $hBitmap = 0 Then

        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
        $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
        _GDIPlus_GraphicsDispose($hGraphic)

        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

        ;**********************
        ; Create Line Brush Using minimum number of settings- Brush size same size as Rectangle to fill
        Local $hBrushLin = GDIPlus_CreateLineBrushFromRect(0, 0, $iWidth, $iHeight, -1, -1, $iColor_Start, $iColor_End, 1)

        ;Fill a rectangle using the above brush
        _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrushLin)
        ;***************************

    EndIf

    Local Const $_STM__SETIMAGE = 0x0172, $_SS__BITMAP = 0x0E
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

    $iRet = GUICtrlCreatePic('', $iX, $iY, $iWidth, $iHeight, $_SS__BITMAP)
    Local Const $__IMAGE_BITMAP = 0
    GUICtrlSendMsg(-1, $_STM__SETIMAGE, $__IMAGE_BITMAP, $hHBitmap)

    If $hGraphic Then _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hHBitmap)

    GUICtrlSetState(-1, $GUI_DISABLE)

    Return $iRet
EndFunc   ;==>CreateBackground_Static

Func GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

    If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>GDIPlus_CreateLineBrushFromRect
Edited by PhoenixXL
  • Like 2

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

Glad you got it working :)

Sorry I havn't got the time to help you before.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

No worries :) :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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  

×