I don't know why but ...
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
include ole32.inc
include oleaut32.inc
include masm32.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
includelib ole32.lib
includelib oleaut32.lib
includelib masm32.lib
........
invoke BitmapFromResource, hInstance, 100
invoke CreatePatternBrush,eax
mov wc.hbrBackground,eax
...this code don't work at WinXp. The same code unders win98 worked fine. What i'm doing wrong ?
--Hador
hador,
At a guess, I would think that \masm32\include\ and \masm32\lib\ may have been in the environment path variable on the win98 machine but not on the winxp machine.
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\ole32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\masm32.lib
The above is gauranteed to work as long as masm32 is installed.
Paul
not sure, but maybe this (http://www.daniweb.com/code/snippet86.html) can help:
It would be helpful if you could explain what is not working, is there an exception or does the image just not display? What is the value BitmapFromResource returns ? Without supplying a suitable piece of code that we can test or at least more than "this does not work" it is difficult to determine the nature of the problem. I don't run XP but I have experienced buffer related problems with it that were not present in 98 or 2K, there is a known buffer that is not hanlded properly in Ernies graphics lib, can't remember what it was though as I wrote my own graphics library for my use. You might search the Win32ASM community for references to the problem.
The BitmapFromResource procedure does not use the hInstance parameter for anything (uses NULL instead). I had reported this bug but it got lost due to the last forum hack. It's really easy to fix, anyway.
There is a solution for the problem about Ernie's image handling library:
http://board.win32asmcommunity.net/viewtopic.php?p=145356#145356
http://board.win32asmcommunity.net/viewtopic.php?p=143807#143807
Hi...
sorry that I don't response to yours 'reply'.
pbrennick: I don't understand how "environment path" may change the program... Masm is in the same directory (c:\masm32) like previously.
donkey: I attach original program that I wrote on Win98 (and I remember that program working fine). All functions like FindResource return realistic values.
[attachment deleted by admin]
hador,
At least we can now see what the problem is. For some reason the jpg does not display on an XP machine but it displays fine on a win98 machine. I tested it on both machines and you are right, there is an interesting problem, here.
Paul
Hador,
There is a known problem (buffer overflow) when using GDIPlus on XP involving the use of jpg images. Unless M$ fixes this problem, you may have to find another solution. Donkey knows more about this type of application than I do, so let's wait to see if he has a solution (he usually does).
Paul
Well, when you create your pattern brush then assign it to the window class, everything is fine. But then you create the class and delete the brush, the brush must remain a valid handle in order to be used by Windows. So...
invoke BitmapFromResource, hInst, 100
invoke CreatePatternBrush,eax
push eax
mov wc.hbrBackground,eax
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,hInst,101
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
pop eax
invoke DeleteObject,eax
Remove the DeleteObject line as well as the push/pop eax and store the brush handle in memory then delete it on exiting your message loop...
invoke BitmapFromResource, hInst, 100
mov hBitmap, eax
invoke CreatePatternBrush,eax
mov hBrush,eax
mov wc.hbrBackground,eax
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,hInst,101
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke GetSystemMetrics , SM_CXSCREEN
sub eax, szerokosc
shr eax, 1
push eax
invoke GetSystemMetrics , SM_CYSCREEN
sub eax, wysokosc
shr eax, 1
pop ebx
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
ebx,eax,szerokosc,wysokosc,\
NULL,NULL,hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
invoke DeleteObject,hBrush
invoke DeleteObject,hBitmap
That works nicely, of course, don't forget to add
QuotehBrush HANDLE ?
hBitmap HANDLE ?
to the .data? section and delete the .const line as Donkey always (properly) suggests. :U
Paul
thanks donkey :U
...terribly true "i'm lazy"
invoke BitmapFromResource, hInst, 100
mov hBitmap, eax
invoke CreatePatternBrush,eax
mov hBrush,eax
mov wc.hbrBackground,eax
but now i have a lesson :P
--Hador
Off-topic:
There is also a trick that I found to burry bitmap files in my executables without using resources.
I use f0dder's bin2o tool to convert the bitmap to an object file to be linked with the executable.
Displaying the image:
.IF uMsg==WM_CREATE
lea eax,[pBitmap+sizeof(BITMAPFILEHEADER)] ; start of BITMAPINFOHEADER header
invoke CreateDIBSection,0,eax,DIB_RGB_COLORS,ADDR ppvBits,0,0
mov hBitmap,eax
lea eax,[pBitmap+54] ; + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
invoke MemCopy,eax,ppvBits,30134-54 ; copy bitmap's bit values ; BMP size = 30134 bytes
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd,ADDR ps
mov hdc,eax
invoke CreateCompatibleDC,eax
mov hMemDC,eax
invoke SelectObject,eax,hBitmap
lea edx,[pBitmap+sizeof(BITMAPFILEHEADER)] ; start of BITMAPINFOHEADER header
ASSUME edx:ptr BITMAPINFOHEADER
invoke BitBlt,hdc,0,0,[edx].biWidth,[edx].biHeight,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC
invoke EndPaint,hWnd,ADDR ps
ASSUME edx:NOTHING
.elseif uMsg==WM_DESTROY
invoke DeleteObject,hBitmap
invoke PostQuitMessage,NULL
[attachment deleted by admin]
Hi Vortex,
I hope all is well with you. You know, I bet you could turn that idea into a very cool bitmap manager!
Paul
Hi pbrennick,
Thanks, everything seems to be OK. The bitmap manager idea is really nice :U The problem with my algo is that it's capable to handle only 24-bit images, I need to study more about bitmaps.