If you wanna do that sort of thing, quit loading the bmp as a pattern brush, and have a go at writing a WM_PAINT handler. Normally you'd probably use BitBlt or similar to paint the bitmap at a given location. Be aware that your program is already being sent WM_PAINT messages whenever it decides to repaint itself, and atm those are being simply handed on to the default os handler.
Posted on 2003-03-31 20:49:43 by Homer
Originally posted by donkey
1. You can remove the border styles of the edit control and it will only show a white rectangle.

It is not an EDIT CONTROL, it is a TEXT CONTROL:
CTEXT "Hello World DialogBox",-1,14,10,102,12

:-Xyzero
Posted on 2003-03-31 21:35:16 by xyzero
Oh it's a STATIC control. Well you can control the color of a static control with the WM_CTLCOLORSTATIC message. It's the same routine as I gave you last time but it includes the static coloring message. It assumes that you have created a variable named hBrush
DialogProc proc uses ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hdc :DWORD
LOCAL hMemDC :DWORD
LOCAL rect :RECT
LOCAL ps :PAINTSTRUCT

.IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke LoadBitmap,hInstance,BitMapResID
mov hBitMap,eax
[COLOR=red]invoke CreateSolidBrush,00FEFEFEh
mov hBrush,eax[/COLOR]

.ELSEIF uMsg == WM_CLOSE
invoke DeleteObject,hBitMap
invoke EndDialog,hWnd,-1

.ELSEIF uMsg==WM_PAINT
mov eax,hWnd
.IF eax == hDlg
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBitMap
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC
invoke EndPaint,hDlg,addr ps
.ENDIF

[COLOR=red].ELSEIF uMsg == WM_CTLCOLORSTATIC
mov eax,hBrush
ret[/COLOR]

.ELSE
mov eax,FALSE
ret

.ENDIF

mov eax, TRUE
ret
DialogProc endp
Posted on 2003-03-31 21:42:54 by donkey
Hi donkey,


Didn't work... (or didn't I work!?!). I placed the value 00DFBAA2h
(to see better) and the results is shown in the figure.
I would like to eliminate the blue area and the white area
about of the text " Hello World DialogBox " so that appeared
the background.

But thank you very much... I am learning a lot :-)
Posted on 2003-03-31 22:34:35 by xyzero
Mmmmm I seem to be writing most of the program for you. :) You can try to insert the text when you process the WM_PAINT Message. Set the rectangle for where you want to set the text and paint the text directly to the image. Haven't tried this out beforehand though so I'm not sure how it will look
.ELSEIF uMsg==WM_PAINT

mov eax,hWnd
.IF eax == hDlg
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBitMap
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC
[COLOR=red]invoke DrawText, hdc, offset Text, -1, ADDR rect, DT_SINGLELINE[/COLOR]
invoke EndPaint,hDlg,addr ps
.ENDIF


Actually this won't work either, thinking about it it will just give you the white bkgnd again. I'll see what I can come up with
Posted on 2003-03-31 22:45:23 by donkey
Hi xyzero,

Nope, got me. I can see a way to do it but it's way too complicated. It involves making a mask for the text and painting it that way but that would be quite a bit of work. There is pobably a much easier way to do it but I don't know it. I'd be interested to know how though. Maybe blit it onto the MemDC with the SRCAND Flag set.
Posted on 2003-03-31 23:14:28 by donkey
Hi donkey,

:alright: :-) I'm really learning a lot... thkx


xyzero
Posted on 2003-03-31 23:29:18 by xyzero
Try this, it creates a new device context and bitmap, paints the text into a rectangle that's size is calculated by the GetTextExtentPoint32 function then merges the two bitmaps. Change the red numbers to the x/y where you want to place the text. Might work...
LOCAL hTbm				:DWORD ; extra local to add


.ELSEIF uMsg==WM_PAINT
mov eax,hWnd
.IF eax == hDlg
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBitMap
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC

invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SetTextColor,hMemDC,000000FFh
invoke lstrlen,ADDR Text
mov edx,eax
invoke GetTextExtentPoint32,hMemDC,ADDR Text,edx,ADDR rect.right
invoke CreateCompatibleBitmap,hdc,rect.right,rect.bottom
mov hTbm,eax
invoke SelectObject,hMemDC,hTbm
mov rect.left,0
mov rect.top,0
invoke DrawText, hMemDC, offset Text, -1, ADDR rect, DT_SINGLELINE
invoke BitBlt, hdc, [COLOR=red]100, 100,[/COLOR] rect.right, rect.bottom, hMemDC, \
0, 0, MERGEPAINT
invoke DeleteDC,hMemDC
invoke DeleteObject,hTbm
invoke EndPaint,hDlg,addr ps
.ENDIF
Posted on 2003-03-31 23:43:02 by donkey
:grin: :grin: :grin:

PERFECT!!!!!!!!!!!!!!!




xyzer;)
Posted on 2003-03-31 23:59:15 by xyzero
Cool, lots of code for Hello World :grin: Probably an easier way
Posted on 2003-04-01 00:01:34 by donkey
Hi Donkey

It's really great, but how to do the function work with an multiline text ?

I mean....If we have something like..


.data

Text db "Hello World DialogBox, working great with single lines, but
what about the multiines, the one that has carrets ?
Is that possible", 0

(...)

code:LOCAL hTbm :DWORD ; extra local to add

.ELSEIF uMsg==WM_PAINT
mov eax,hWnd
.IF eax == hDlg
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
(...)
invoke DrawText, hMemDC, offset Text, -1, ADDR rect, DT_SINGLELINE
(...)


I changed the equate of the DrawText fucntion with DT_WORDBREAK, but the app crashed.

The function DrwaTexEx, seems not to work with multilines too.

How can this be fixed ?

Best Regards,

Guga
Posted on 2003-09-27 16:11:49 by Beyond2000!
Does this simpler approach work?

; Write the text
Invoke SelectObject, hDC, EnterYourFontHere
mov hOldFont, eax
Invoke SetTextColor, hDC, EnterYourTextColourHere
mov rgbPrevText, eax
Invoke SetBkMode, hDC, TRANSPARENT
; Single Line
Invoke ExtTextOut, hDC, x, y, 0, NULL, offset szText, dwTextLength, NULL

; Multiline - rc is a RECT with the dimensions of the area to draw the text into
; Comment out the above and uncomment this to use
; Invoke ExtTextOut, hDC, x, y, ETO_CLIPPED,
; addr rc, addr szText, dwTextLength, NULL

Invoke SelectObject, hDC, hOldFont
Invoke SetTextColor, hDC, rgbPrevText
Invoke SetBkMode, hdc, OPAQUE
Posted on 2003-09-27 16:53:43 by andrew_k
Yes, that should work. Also you can se this approach for some fancy text effects (like text with a shadow). I've seen that somewhere else in this board (unfortunately I don't remember exactly wich thread, but it's worth a search).
Posted on 2003-09-27 17:25:43 by QvasiModo
Hi.

No, it's not working...

It only fills the 1st line, and a white rectangle outside....(Just like the problem reported before Dopnkey fix that).....

The text is inside a Static Control...

I used the name of the font of Garamond or Courier New, and nothing happened.


Best Regards,
Guga
Posted on 2003-09-27 17:32:08 by Beyond2000!
Hi Beyond2000,
Don't use a static control, all you need is a text string in your .data section. Then simply use the code in the WM_PAINT handler in the parent window to write the text. You will need to create a font too, not just enter the name of one.
eg.

mov logfont.lfHeight, dwMyFontHeight
mov logfont.lfWidth, 0
mov logfont.lfEscapement, 0
mov logfont.lfOrientation, 0
mov logfont.lfWeight, FW_NORMAL
mov logfont.lfItalic, 0
mov logfont.lfUnderline, 0
mov logfont.lfStrikeOut, 0
mov logfont.lfCharSet, ANSI_CHARSET
mov logfont.lfOutPrecision, OUT_TT_PRECIS
mov logfont.lfClipPrecision, CLIP_DEFAULT_PRECIS
mov logfont.lfQuality, DEFAULT_QUALITY
mov logfont.lfPitchAndFamily, DEFAULT_PITCH or FF_DONTCARE
Invoke lstrcpy, addr logfont.lfFaceName, addr szMyFontName
Invoke CreateFontIndirect, addr logfont
mov hFont, eax

Don't forget to delete the font when you're finished with it.
Invoke DeleteObject, hFont
See if this works.
Posted on 2003-09-27 17:43:25 by andrew_k
Wasn't there a way to print text with a transparent background? I mean, no need to mask anything. :confused:
Posted on 2003-09-27 17:57:42 by QvasiModo
Hi QvasiModo,
Do you mean something other than using:
Invoke SetBkMode, hDC, TRANSPARENT
with ExtTextOut?
Posted on 2003-09-27 18:15:14 by andrew_k
Hi Guys,

it's not working...


i tried all ways, including and excluding the static control, or the ways you propoesd but nothing....

This is the original way Donkey did:



DialogProc proc uses ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc :DWORD
LOCAL hMemDC :DWORD
LOCAL rect :RECT
LOCAL ps :PAINTSTRUCT

.IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke LoadBitmap,hInstance,BitMapResID
mov hBitMap,eax
invoke CreateSolidBrush,00FEFEFEh
mov hBrush,eax

.ELSEIF uMsg == WM_CLOSE
invoke DeleteObject,hBitMap
invoke EndDialog,hWnd,-1

.ELSEIF uMsg==WM_PAINT
mov eax,hWnd
.IF eax == hDlg
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBitMap
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC


invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SetTextColor,hMemDC,000000FFh
invoke lstrlen,ADDR Text
mov edx,eax
invoke GetTextExtentPoint32,hMemDC,ADDR Text,edx,ADDR rect.right
invoke CreateCompatibleBitmap,hdc,rect.right,rect.bottom
mov hTbm,eax
invoke SelectObject,hMemDC,hTbm
mov rect.left,0
mov rect.top,0
invoke DrawText, hMemDC, offset Text, -1, ADDR rect, DT_SINGLELINE
invoke BitBlt, hdc, 100, 100, rect.right, rect.bottom, hMemDC, \
0, 0, MERGEPAINT
invoke DeleteDC,hMemDC
invoke DeleteObject,hTbm
invoke EndPaint,hDlg,addr ps
.ENDIF

.ELSEIF uMsg == WM_CTLCOLORSTATIC
mov eax,hBrush
ret

.ELSE
mov eax,FALSE
ret

.ENDIF

mov eax, TRUE
ret
DialogProc endp



And this is waht i'm trying to do:



.data

dwMyFontHeight db 8
szMyFontName db "Courier New"
szText db "Hello World DialogBox, working great with single lines, but
what about the multiines, the one that has carrets ?
Is that possible", 0

hDlg dd 0
dwTextLength dd ?



DialogProc proc uses ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc :DWORD
LOCAL hMemDC :DWORD
LOCAL rect :RECT
LOCAL ps :PAINTSTRUCT

LOCAL hFont : DWORD ; Added as Local var
LOCAL rgbPrevText : DWORD ; Added as Local var


.IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke LoadBitmap,hInstance,BitMapResID
mov hBitMap,eax
invoke CreateSolidBrush,00FEFEFEh
mov hBrush,eax

.ELSEIF uMsg == WM_CLOSE
invoke DeleteObject,hBitMap
invoke EndDialog,hWnd,-1

.ELSEIF uMsg==WM_PAINT
mov eax,hWnd
.IF eax == hDlg

; --------------------------------------------------------------------
; Here is to show the background image in the dialog
; --------------------------------------------------------------------
invoke BeginPaint,hDlg,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBitMap
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC

; -------------------------------------------------------------------


mov logfont.lfHeight, dwMyFontHeight
mov logfont.lfWidth, 0
mov logfont.lfEscapement, 0
mov logfont.lfOrientation, 0
mov logfont.lfWeight, FW_NORMAL
mov logfont.lfItalic, 0
mov logfont.lfUnderline, 0
mov logfont.lfStrikeOut, 0
mov logfont.lfCharSet, ANSI_CHARSET
mov logfont.lfOutPrecision, OUT_TT_PRECIS
mov logfont.lfClipPrecision, CLIP_DEFAULT_PRECIS
mov logfont.lfQuality, DEFAULT_QUALITY
mov logfont.lfPitchAndFamily, DEFAULT_PITCH or FF_DONTCARE
Invoke lstrcpy, addr logfont.lfFaceName, addr szMyFontName
Invoke CreateFontIndirect, addr logfont
mov hFont, eax


; Write the text
Invoke SelectObject, hDC, szMyFontName
mov hFont, eax
Invoke SetTextColor, hDC, 00FEFEFEh
mov rgbPrevText, eax
Invoke SetBkMode, hDC, TRANSPARENT
; Single Line
; Invoke ExtTextOut, hDC, 10, 41, 0, NULL, offset szText, dwTextLength, NULL

; Multiline - rc is a RECT with the dimensions of the area to draw the text into
; Comment out the above and uncomment this to use
Invoke ExtTextOut, hDC, 10, 41, ETO_CLIPPED, addr rc, addr szText, dwTextLength, NULL

Invoke SelectObject, hDC, hFont
Invoke SetTextColor, hDC, rgbPrevText
Invoke SetBkMode, hdc, OPAQUE

Invoke DeleteObject, hFont


.ENDIF

; .ELSEIF uMsg == WM_CTLCOLORSTATIC ; -? Need to be erased ?
; mov eax,hBrush
; ret

.ELSE
mov eax,FALSE
ret

.ENDIF

mov eax, TRUE
ret
DialogProc endp



I don't know what am i doing wrong...can someone fix this partf of the code ?

And also,...one more thing...The setbkmode function is using the TRANSPARENT equate...does it works on win95 too ? I mean, the code seems to work only on windows2000.


Best Regards,

Guga
Posted on 2003-09-27 21:08:30 by Beyond2000!
Hi Guga,
There are a couple of things we need to tweak. Firstly, create your font in the WM_INITDIALOG handler, not in response to the WM_PAINT message where it creates and recreates the font in a block of code that may be called frequently and, hence, needs to be minimal in size.

The following code:

Invoke CreateFontIndirect, addr logfont
mov hFont, eax

creates the actual font and stores the handle to it a global variable named hFont. When we select objects into device contexts what we actually load into the dc are handles to GDI objects. Hence in your WM_PAINT code you need to replace:

Invoke SelectObject, hDC, szMyFontName
mov hFont, eax

with
Invoke SelectObject, hDC, hFont
mov hOldFont, eax ; hOldFont is a local variable

Your original code seeks to load a text string into the device context. A device context is like an artists canvas and palette combined. It is a surface you draw on with the tools currently selected into it. To use a particular font you have to load a handle to that font into the device context.

The line:

mov hOldFont, eax

saves the handle to the font object previously loaded into the device context. The first time you load a GDI object of a certain type you want to retain this returned value so you can load it back into the dc at the end of that block of code. If you don't a resource leak results. However when you saved this returned value to hFont you overwrote the handle returned by CreateFontIndirect, meaning your application was then unable to destroy the font. This would have been done in response to the WM_DESTROY message (or WM_NCDESTROY), and prevents another resource leak:

.ELSEIF uMsg == WM_DESTROY
Invoke DestroyObject hFont


SetBkMode works on Windows 95/NT 3.1 or later.
See if this helps.
Posted on 2003-09-28 15:14:09 by andrew_k
Hi Guys...

Yeah..it's close. :)

I did it, and am trying to put the text in paragraphs, but nothing is working so far.

I initialzed the font, on WM_INITDIALOG, and put the proper coding on the WM_PAINTG....but even if the text is fully showed now...it is on a single line.....(The carrets are not being used to build the paragraphs - See the attached image).


The code i did was:



.data



dwMyFontHeight db 8

szMyFontName db "Garamond"

szText db "Hello World DialogBox, working great with single lines, but ; Paragraph here
what about the multiines, the one that has carrets ? ; Paragraph here

Is that possible", 0



hDlg dd 0

dwTextLength dd ?
hInstance dd ?


DialogProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hdc :DWORD
LOCAL hMemDC :DWORD
LOCAL rect :RECT
LOCAL ps :PAINTSTRUCT
LOCAL hFont : DWORD ; Added as Local var
LOCAL rgbPrevText : DWORD ; Added as Local var
LOCAL hOldFont : DWORD ; Added as Local var
LOCAL logfont :LOGFONT

.IF uMsg == WM_INITDIALOG

; Background image

mov eax, hWin
mov hDlg, eax
invoke LoadBitmap, hInstance, IDB_BGD
mov hBitMap, eax
(?)

; Create our font routine

mov logfont.lfHeight, 10
mov logfont.lfWidth, 0
mov logfont.lfEscapement, 0
mov logfont.lfOrientation, 0
mov logfont.lfWeight, FW_NORMAL
mov logfont.lfItalic, 0
mov logfont.lfUnderline, 0
mov logfont.lfStrikeOut, 0
mov logfont.lfCharSet, ANSI_CHARSET
mov logfont.lfOutPrecision, OUT_TT_PRECIS
mov logfont.lfClipPrecision, CLIP_DEFAULT_PRECIS
mov logfont.lfQuality, DEFAULT_QUALITY
mov logfont.lfPitchAndFamily, DEFAULT_PITCH or FF_DONTCARE
invoke lstrcpy, logfont.lfFaceName, logfont, szMyFontName
invoke CreateFontIndirect, logfont
mov hFont, eax

.ELSEIF uMsg==WM_PAINT

mov eax hWin
.If eax = hDlg
invoke BeginPaint, hDlg, ps
mov hdc, eax
invoke CreateCompatibleDC, hdc
mov hMemDC, eax
invoke SelectObject, hMemDC, hBitMap
invoke GetClientRect, hDlg, rect
invoke BitBlt, hdc, 0, 0, rect.right, rect.bottom, hMemDC 0 0 SRCCOPY
invoke DeleteDC, hMemDC

; Text Colors


invoke SelectObject, hdc, hFont;
mov hOldFont, eax
invoke SetTextColor, hdc, 0DFBAA2h
mov rgbPrevText, eax
invoke SetBkMode, hdc, TRANSPARENT
; invoke ExtTextOut, hdc, 10, 41, 0, NULL, MsgSobre2, rect.bottom, NULL ; Single Line
invoke ExtTextOut, hdc, 10, 41, ETO_CLIPPED, rect MsgSobre2, rect.bottom, NULL
invoke SelectObject, hdc, hFont
invoke SetTextColor, hdc, rgbPrevText
invoke SetBkMode, hdc, OPAQUE
invoke DeleteObject, hFont

.End_If


.ELSEIF uMsg = WM_COMMAND
(?) command buttons

.ELSEIF uMsg = WM_COMMAND

..Else_If uMsg = WM_CLOSE

invoke DeleteObject, hBitMap
invoke EndDialog, hWin, NULL


..Else_If uMsg = WM_DESTROY

invoke DeleteObject, hFont
invoke PostQuitMessage, NULL
mov eax, FALSE

..EndIf

invoke DefWindowProc, hWin, uMsg, wParam, lParam
mov eax, FALSE

DialogProc endp



How to put the mesage uging the paragrahps ? The message shopuld be displayed as:


Hello World DialogBox, working great with single lines, but
what about the multiines, the one that has carrets ?

Is that possible.


And not like:


Hello World DialogBox, working great with single lines, but what about the multiines, the one that has carrets ? Is that possible.


Btw: I removed the WM_CTLCOLORSTATIC, but the text should fit in the area of the other static control as showned.

Best Regards,

Guga
Posted on 2003-09-28 17:44:37 by Beyond2000!