The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: diablo2oo2 on August 14, 2005, 06:15:23 PM

Title: Transparent Edit Box with Background Picture
Post by: diablo2oo2 on August 14, 2005, 06:15:23 PM
Hi all!

I try to code a transparent edit box so that its possible to see the background picture instead the Editbox background color. I coded something, but the text looks crappy (see picture!). Maybe somebody know what is missing in my code?

.586p
.mmx
.model flat, stdcall
option casemap :none

;******************************************************************************
;* INCLUDES                                                                   *
;******************************************************************************
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\advapi32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\masm32.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\masm32.lib

include \masm32\include\wsock32.inc
includelib \masm32\lib\wsock32.lib
include \masm32\include\wininet.inc
includelib \masm32\lib\wininet.lib

;include \masm32\include\diablo2oo2.inc
;includelib \masm32\lib\diablo2oo2.lib

;******************************************************************************
;* PROTOTYPES                                                                 *
;******************************************************************************
DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

;******************************************************************************
;* DATA & CONSTANTS                                                           *
;******************************************************************************
.const
DLG_EDIT equ 101
BTN_OK equ 102

.data

.data?


;******************************************************************************
;* CODE                                                                       *
;******************************************************************************
.code
main:
invoke GetModuleHandle,0
        invoke DialogBoxParam,eax,1,0,addr DialogProc,0
        invoke ExitProcess,0
       
DialogProc Proc uses ebx esi edi  hwnd:dword,message:dword,wParam:dword,lParam:dword
mov eax,message
.if eax==WM_COMMAND
mov eax,wParam
.if ax==BTN_OK
jmp @close
.endif
.elseif eax==WM_CTLCOLORSTATIC||eax==WM_CTLCOLOREDIT
invoke GetDlgCtrlID,lParam
.if ax==DLG_EDIT
invoke SetBkMode,wParam,TRANSPARENT ;Background of Text
invoke SetTextColor,wParam,0E3DEDDh ;TextColor
invoke GetStockObject,NULL_BRUSH
ret
.endif
.elseif eax==WM_CLOSE
@close:
invoke EndDialog,hwnd,0
.endif
xor eax,eax
ret                          
DialogProc endp

end main

[attachment deleted by admin]
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 15, 2005, 03:30:56 PM
This is a dirty way, but it works now...

[attachment deleted by admin]
Title: Re: Transparent Edit Box with Background Picture
Post by: diablo2oo2 on August 16, 2005, 03:10:21 PM
thanks for your help. subclassing is a good idea.  :U
i also thought of it, but i didnt know the right api to use there...
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 16, 2005, 05:13:33 PM
You probably noticed that after selection a view is crappy, so u should consider other ways like custom edit control...(and get rid of flicker)
Title: Re: Transparent Edit Box with Background Picture
Post by: diablo2oo2 on August 16, 2005, 06:34:50 PM
i changed the code a little. now it works with scroll text also...

[attachment deleted by admin]
Title: Re: Transparent Edit Box with Background Picture
Post by: jojo on August 20, 2005, 09:50:57 AM
Quote from: ramguru on August 16, 2005, 05:13:33 PM
You probably noticed that after selection a view is crappy, so u should consider other ways like custom edit control...(and get rid of flicker)

diablo2oo2's version with scroll bars flickers with every mouse movement, while ramguru's is calm. Any explanation for that?
Title: Re: Transparent Edit Box with Background Picture
Post by: diablo2oo2 on August 20, 2005, 11:41:53 AM
i redraw the editbox on WM_MOUSEMOVE
Title: Re: Transparent Edit Box with Background Picture
Post by: jojo on August 20, 2005, 04:36:20 PM
Quote from: diablo2oo2 on August 20, 2005, 11:41:53 AM
i redraw the editbox on WM_MOUSEMOVE

If I take WM_MOUSEMOVE away, flicker stops, and the box works fine. Why do you need a redraw for WM_MOUSEMOVE?
Title: Re: Transparent Edit Box with Background Picture
Post by: EGOiST on August 21, 2005, 12:57:57 AM
try this out  :U


DlgProc proc uses ebx edi esi hWnd,wMsg,wParam,lParam
LOCAL tmp:dword
LOCAL ps:PAINTSTRUCT
LOCAL pt:POINT

.if wMsg == WM_CREATE
push hWnd
pop hDlg
invoke CreateWindowEx,0,addr _ed,0,WS_TABSTOP or WS_VISIBLE or WS_CHILDWINDOW or ES_LEFT or ES_AUTOHSCROLL,110,100,150,18,hWnd,IDC_EDIT1,hInstance,0
invoke BitmapFromResource,hInstance,IDC_BMP
mov edBmp, eax
invoke CreatePatternBrush,eax
mov edBrush, eax
invoke GetDC,hWnd
mov tmp, eax
invoke CreateCompatibleDC,eax
mov dcBG, eax
invoke SelectObject,dcBG,edBmp
invoke DeleteDC,tmp
invoke SetDlgItemText,hWnd,IDC_EDIT1,addr _nz

.elseif wMsg == WM_PAINT
invoke BeginPaint,hWnd,addr ps
mov tmp, eax
invoke BitBlt,tmp,0,0,350,240,dcBG,0,0,SRCCOPY
invoke SetBkMode,tmp,TRANSPARENT
invoke EndPaint,hWnd,addr ps

.elseif wMsg == WM_CTLCOLOREDIT
invoke SetBkMode,wParam,TRANSPARENT
invoke SetTextColor,wParam,000000ffh ; red color
invoke GetBrushOrgEx,wParam,addr pt
xor edi, edi
sub edi, 110 ; x coordinate
xor esi, esi
sub esi, 100 ; y coordinate
invoke SetBrushOrgEx,wParam,edi,esi,addr pt
mov eax, edBrush
ret

.elseif wMsg == WM_LBUTTONDOWN
invoke PostQuitMessage,0

.else
invoke DefWindowProc,hWnd,wMsg,wParam,lParam
ret
.endif

mov eax, TRUE

ret
DlgProc endp


full code here (http://www.asmines.com/masm32.transparent.edit.box-egoist.tsrh.rar)
Title: Re: Transparent Edit Box with Background Picture
Post by: jojo on August 21, 2005, 08:49:19 AM
Quote from: EGOiST on August 21, 2005, 12:57:57 AM
try this out  :U
...
full code here (http://www.asmines.com/masm32.transparent.edit.box-egoist.tsrh.rar)

Interesting. The exe starts but I can't type anything; all I see is a blue bitmap with a mix of Russian (?) and English text that closes when I click on it. The ASM doesn't compile - "undefined symbol BitmapFromResource"...
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 21, 2005, 09:39:19 AM
2 EGOiST:
Your code has the same problem  :tdown (like in 1st attachment)
2 jojo:
BitmapFromResource uses
oleaut32.inc/oleaut32.lib
ole32.inc/ole32.lib
use LoadBitmap instead
Title: Re: Transparent Edit Box with Background Picture
Post by: jojo on August 21, 2005, 09:48:09 AM
Quote from: ramguru on August 21, 2005, 09:39:19 AM
2 EGOiST:
Your code has the same problem  :tdown (like in 1st attachment)
2 jojo:
BitmapFromResource uses
oleaut32.inc/oleaut32.lib
ole32.inc/ole32.lib
use LoadBitmap instead

Thanks, ramguru. It's also in masm32.lib - I had an old version.
Egoist: I don't know what your code should do, but it actually does nothing on my PC (WinXP). It just shows the back.jpg. The mouse cursor changes to "hourglass" while over the window.
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 21, 2005, 09:59:19 AM
jojo,
first of all replace WM_LBUTTONDOWN with WM_RBUTTONDOWN
now look at red word egoist, it's actually an edit-box (in place it not supposed to be)
but that control has ES_LEFT style, not ES_CENTER, and you may think it works correct until you press delete.
Title: Re: Transparent Edit Box with Background Picture
Post by: RZX on August 21, 2005, 12:13:03 PM
Hi;
i was coded a KG template before. It is very buggy but may help you. i havent got sources anymore but you can decompile it if you find it useful. Already coded in MASM. uhmmm and it is too big for a KG template anyway. Unoptimized code and resources  :P :wink

And EGOiST's code seems to be nice enough.

.....i removed links coz they are useless......

All untested under W98, ME.

Best regards.
Title: Re: Transparent Edit Box with Background Picture
Post by: diablo2oo2 on August 21, 2005, 12:32:07 PM
ok, rzx... but this doesnt help anyone here!

i think ramgurus solution is best one so far. :clap: because its dynamic and doesnt depend on a certain bitmap. you can put any bitmap(s)  into the resource and place it where you want in the dialog and it still works fine.
Title: Re: Transparent Edit Box with Background Picture
Post by: RZX on August 21, 2005, 12:41:21 PM
Uhm. Well. You right diablo2002. I can try to post some code about this.
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 21, 2005, 02:52:03 PM
OK I modified EGOIST's code (it has no problems with selection), I think it flickers at moderate rate now.

[attachment deleted by admin]
Title: Re: Transparent Edit Box with Background Picture
Post by: PBrennick on August 21, 2005, 03:07:09 PM
I think it would be VERY easy for a programmer tp use ramguru's example in a project to make a better looking 'About' box, not to mention a ton of other uses especially when programming 'dialog as main' type applications.  This is very useful code!  Thanks, ramguru!  :U

Paul
Title: Re: Transparent Edit Box with Background Picture
Post by: ramguru on August 21, 2005, 03:29:21 PM
Thanks to diablo2oo2 actually  :red, I just fixed some bugs.
Title: Re: Transparent Edit Box with Background Picture
Post by: PBrennick on August 21, 2005, 03:48:14 PM
I think there is plenty of thanks to go around.  You guys have done a nice job.  I said what I said because he also said that.

Quote
i think ramgurus solution is best one so far.

Anyway, I am still playing with it so that it will respond to mouse clicks.  I haven't tried the last posting by diablo2oo2, but so far, none of the versions handle this event.  You can drag the mouse over the text to highlight it and this will work correctly.  If you change your mind you should be able to click anywhere in the box and the highlight should go away.  It doesn't.

Paul