WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

invoke LoadBitmap,hInst,backgr
mov hbackgr,eax
invoke CreatePatternBrush,hbackgr
mov hbackgrbrush,eax

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
push hbackgrbrush
pop wc.hbrBackground
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax

invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,400,400,NULL,NULL,\
hInst,NULL
mov hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.WHILE TRUE
invoke PeekMessage, ADDR msg,NULL,0,0,PM_REMOVE
.IF eax!=0
.IF (msg.message==WM_QUIT)
.BREAK
.ENDIF
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ELSE
;-------PUTDASTUFFAHERA
.ENDIF
.ENDW

mov eax,msg.wParam
ret
WinMain endp
Posted on 2003-03-28 13:59:48 by AceEmbler
There are a few things you have to check ...

1. Is the value of hbackgr a valid handle, it may not be properly loading the resource
2. If you are using Win95/98 is the bitmap 8x8
3. This line is probably ok but it is worth looking into (elsewhere you use hInst not hInstance)
push hInstance
pop wc.hInstance

If you want to use a bitmap larger than 8x8 for win95/98 you are going to have to process the WM_PAINT message and paint the bitmap onto the window.
Posted on 2003-03-28 14:51:49 by donkey

There are a few things you have to check ...

1. Is the value of hbackgr a valid handle, it may not be properly loading the resource
2. If you are using Win95/98 is the bitmap 8x8
3. This line is probably ok but it is worth looking into (elsewhere you use hInst not hInstance)
push hInstance
pop wc.hInstance

If you want to use a bitmap larger than 8x8 for win95/98 you are going to have to process the WM_PAINT message and paint the bitmap onto the window.


I'm using win XP this bitmap is 400x400 i dont wont to use WM_PAINT to make this background i do not know if this handle is valid becouse dbg PrintError macro aint working in this case.
Posted on 2003-03-28 14:57:36 by AceEmbler
invoke LoadBitmap,hInst,backgr
.IF eax == NULL
invoke MessageBox,NULL,ADDR SomeText,NULL,MB_OK
.ENDIF
mov hbackgr,eax

This will verify the bitmap handle, you can use GetLast Error to retrieve extended information
Posted on 2003-03-28 15:01:03 by donkey
yeaa :( (shit) u were right eax == 0 but what should i do now ??
btw GetLastError didn't work.
Posted on 2003-03-28 15:16:21 by AceEmbler
It could be three things,

1. Your bitmap is not being added to your RES file
2. Your RES file is not being linked to the executable
3. You are using the wrong value in backgr to ID your bitmap

LOCAL TextBuffer[16] :BYTE
LOCAL nError :DWORD

invoke LoadBitmap,hInst,backgr
.IF eax == NULL
invoke GetLastError
mov nError,eax
invoke dw2a, nError, ADDR TextBuffer
invoke MessageBox,NULL,ADDR TextBuffer,NULL,MB_OK
.ENDIF
mov hbackgr,eax
Posted on 2003-03-28 15:24:14 by donkey
And the Error IS ::::: >>>>>> 1814 :( :(
Posted on 2003-03-28 15:33:43 by AceEmbler
ERROR_RESOURCE_NAME_NOT_FOUND

You have to figure out which of the 3 problems is the one. Check your RC file to make sure the bitmap is added and verify the ID number of the bitmap then verify your link command line to make sure that you are linking the RES file.
Posted on 2003-03-28 15:36:11 by donkey
I'm adding this fast made stuff becouse i cant solve the problem.
Posted on 2003-03-29 04:23:40 by AceEmbler
i made this methode with WM_ERASEBKGND and it's working. :)
Posted on 2003-03-29 08:44:27 by AceEmbler
Try this, I took a quick look at your proggy but this is definitely one problem

invoke LoadBitmap,hInst, ADDR pushme
invoke CreatePatternBrush,eax
push eax
Posted on 2003-03-29 08:57:25 by donkey
ok i solved the problem so now i can tell HOW TO SET BITMAP AS A BACKGROUND.

ways how to do it :

Method 1. Bitmap as a brush.

.data
bitmap db "Place:\Where\The\Bitmap\is.bmp"

; btw this method load bmp from the file while executing.
; but u can use resource too :)

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

invoke LoadImage,hInst,addr bitmap,IMAGE_BITMAP,500,500,LR_LOADFROMFILE
invoke CreatePatternBrush,eax
push eax ; push handle to brush

; here was the bug i was using LoadBitmap insteda of LoadImage.

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
pop wc.hbrBackground ;pop handle to brush here
;mov wc.hbrBackground,0
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName

Method 2. use WM_ERASEBKGND

;in this example i load file from the resource
;+ some macros

;=======macros=====
LOADPICTURE MACRO Hdc,bitmap,hbitmap,hMemDC
invoke LoadBitmap,hInstance,ADDR bitmap
mov hbitmap,eax
invoke CreateCompatibleDC,Hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hbitmap
ENDM
; that time we were using LoadBitmap
;--------------------
DELOADPICTURE MACRO hbitmap,hMemDC
invoke DeleteObject,hbitmap
invoke DeleteDC,hMemDC
ENDM
;=======end macros===

.IF uMsg==WM_DESTROY
DELOADPICTURE hbackgr,hbackgrDC
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke GetDC,hWnd
mov hdc,eax
LOADPICTURE hdc,backgr,hbackgr,hbackgrDC
invoke ReleaseDC,hWnd,hdc
;.ELSEIF uMsg==WM_ERASEBKGND
invoke GetDC,hWnd
mov hdc,eax
invoke BitBlt,hdc,0,0,400,400,hbackgrDC,0,0,SRCCOPY
invoke ReleaseDC,hWnd,hdc
.ELSE

Simply u load bmp from memory and BitBlt it to the screen while uMsg==WM_ERASEBKGND

Method 3.

this method BitBlt bmp while WM_PAINT instead of WM_ERASEBKGND

Remember: Method 2 and probably 3 (i'm not shure about 3)

u need to remember not to repaint the background during for example InvalidateRect ( it is the last parameter, should be FALS)
btw it is good to mov wc.hbrBackground,0 while using BitBlt's methods (it might flicker without this one)

; Just forgoted to add that most of this was already posted on this board. I just rewrited it here to show how this stuff looks in a prog. Just in case some newbie like me wont to use some bmp as a bkg :)


BAHHH i messed a little with this LoadImage and LoadBitmap probably u can use LoadBitmap instead of LoadImage. but do not worry it is working just few more parameters to add :P but than u can not load it from file :P <-- that was third edit

And this is probably 5 or maby 6 edit. becouse i just deleted some hereses about this two API's i wrote in this post a few minutes ago. We should use LoadImage in Method 1 becouse we can write the size of a bmp so this picture will be resized, we can use smaller on bigger bmp to fill the window with just one picture.
Posted on 2003-03-29 10:23:21 by AceEmbler
... and how i can put a bitmap as background in a DIALOG BOX?
Posted on 2003-03-30 10:57:34 by xyzero
Assuming that you have the bitmap in your resource section, you load the bitmap on WM_INITDIALOG and process the WM_PAINT command
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

.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

.ELSE
mov eax,FALSE
ret

.ENDIF

mov eax, TRUE
ret
DialogProc endp
Posted on 2003-03-30 11:39:52 by donkey
Hi donkey,

PERFECT...

Thank you very much!

:-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-)

... 3 little questions:

(1) Why did you use

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

(... or better... what?s this :-( )

Why not:

.ELSEIF uMsg == WM_CLOSE
invoke ExitProcess,NULL


(2) .IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke LoadBitmap,hInstance,ADDR BitMap
mov hBitMap,eax
;<<< Why RET isn?t neecessary????


(3) Is it possible to restrict my bitmap to a portion of dialogbox (for exemple inside a custom control, or a groupbox, etc), or include a bitmap of smaller size than the dialogobox in a relative position of the dialog box?

:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?:-?
Posted on 2003-03-30 13:52:57 by xyzero
WM_ERASEBKGND it is better to use this one than WM_PAINT to make bmp background. It's good to have small WM_PAINT. I'm only using one BitBlt in WM_PAINT, to BitBlt my back buffer.
Posted on 2003-03-30 14:04:25 by AceEmbler

(1) Why did you use

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


This is the proper way to end a dialog. This will end the dialog message loop and destroy the dialog but not exit the process. Place your ExitProcess after the DialogBoxParam command to ensure that it functions correctly. ie:

invoke DialogBoxParam, hInstance, ADDR szDialogName,NULL, addr DialogProc, OutputText
invoke ExitProcess, eax


(2) .IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke LoadBitmap,hInstance,ADDR BitMap
mov hBitMap,eax

The return is handled at the bottom of the proc

(3) Is it possible to restrict my bitmap to a portion of dialogbox (for exemple inside a custom control, or a groupbox, etc), or include a bitmap of smaller size than the dialogobox in a relative position of the dialog box?


The position of the dialog is handled by the BitBlt function change the x,y parameters. The other stuff depends on your control, there are WM_CTLCOLORxxxx messages and styles that handle this better.

Donkey
Posted on 2003-03-30 14:06:40 by donkey

WM_ERASEBKGND it is better to use this one than WM_PAINT to make bmp background. It's good to have small WM_PAINT. I'm only using one BitBlt in WM_PAINT, to BitBlt my back buffer.


Hi xyzero,

Don't use the WM_ERASEBKGND message to processs the routine that I showed you, you will find that it does not properly repaint the background if you use a fixed (ie BitBlt instead of StrecthBlt) image and a resizable frame. You will have to write extra painting logic if you decide not to use WM_PAINT. I agree that you should keep your WM_PAINT section as small as possible however, I attempted to make up for this by verifying the handle before processing the paint message.
Posted on 2003-03-30 22:59:25 by donkey
Thank you very much!!!


I write a little "Hello World" dialogbox with icon, cursor, messagebox and
a background bitmap. It is working fine, however the result didn't come out
exactly as I wanted.

Well... 2 questions :-S

(1) i put a text in dialogbox but the "gray box" of text hides a part of the image (background). The simple solution is draw a text on the image...
Is there a more "intelligent" solution?

(2) the custom cursor only appears in static controls of dialogbox.
Is it possible to do the cursor also appears on the other
controls (buttons, edittext, etc) of the dialogbox?



xyzero
Posted on 2003-03-31 18:10:34 by xyzero
Originally posted by xyzero
(1) i put a text in dialogbox but the "gray box" of text hides a part of the image (background). The simple solution is draw a text on the image...
Is there a more "intelligent" solution?

(2) the custom cursor only appears in static controls of dialogbox.
Is it possible to do the cursor also appears on the other
controls (buttons, edittext, etc) of the dialogbox?
1. You can remove the border styles of the edit control and it will only show a white rectangle.
2. Yes, but you would have to use a custom class for the edit and button controls in order to change the cursor easily
Posted on 2003-03-31 18:18:16 by donkey