News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Transparent Edit Box with Background Picture

Started by diablo2oo2, August 14, 2005, 06:15:23 PM

Previous topic - Next topic

diablo2oo2

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]

ramguru

This is a dirty way, but it works now...

[attachment deleted by admin]

diablo2oo2

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...

ramguru

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

i changed the code a little. now it works with scroll text also...

[attachment deleted by admin]

jojo

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?

diablo2oo2


jojo

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?

EGOiST

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

jojo

Quote from: EGOiST on August 21, 2005, 12:57:57 AM
try this out  :U
...
full code here

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"...

ramguru

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

jojo

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.

ramguru

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.

RZX

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.

diablo2oo2

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.