Hiya!

I've got a problem when trying to show a JPEG image to in a control. I'm using a resource file;


#include "C:\masm32\include\resource.h"

#define ID_BUTTON1 201
#define ID_BUTTON2 202
#define IDC_LIST1 203

SAC DIALOG DISCARDABLE  0, 0, 242, 241
STYLE DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION |
    WS_SYSMENU
CAPTION "Test"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON  "&Connect",ID_BUTTON1,65,215,50,14
    PUSHBUTTON      "C&lose",ID_BUTTON2,123,215,50,14
    LISTBOX        IDC_LIST1,10,95,220,110,LBS_NOINTEGRALHEIGHT |
                    WS_VSCROLL | WS_TABSTOP
    CONTROL        "",IDC_STATIC,"Static",SS_BITMAP | SS_CENTERIMAGE |
                    SS_REALSIZEIMAGE,5,0,230,98
END

IDI_ICON1              ICON    DISCARDABLE    "test.ico"
2000                    IMAGE  DISCARDABLE    "test.jpg"


Now, the problem is that it won't paint the image to the control. I've searched forum, checked some examples and done my own fiddling, but it just won't work. This is a part of my "DlgProc" function code:


; Window related variables
LOCAL hBrush:DWORD
LOCAL rect:RECT
LOCAL logbrush:LOGBRUSH

; Image related variables
LOCAL dwImage:DWORD
LOCAL hDC:HDC
LOCAL hOld:DWORD
LOCAL memDC:DWORD
LOCAL ps:PAINTSTRUCT
LOCAL pImage:DWORD ; Picturebox hWnd

.IF uMsg==WM_CREATE
; Load picture
MOV dwImage, FUNC(BitmapFromResource, dwInstance, 2000)
;.ELSEIF uMsg==WM_SYSCOLORCHANGE
;.ELSEIF uMsg==WM_SIZE
.ELSEIF uMsg==WM_PAINT
MOV pImage, FUNC(GetDlgItem, hWnd, IDC_STATIC)

MOV hDC, FUNC(BeginPaint, hWnd, ADDR ps)
INVOKE GetClientRect, pImage, ADDR rect
MOV memDC, FUNC(CreateCompatibleDC, hDC)
MOV hOld, FUNC(SelectObject, memDC, dwImage)
                        ;1
INVOKE BitBlt, hDC, 0, 0, rect.right, rect.bottom, memDC, 0, 0, SRCCOPY

INVOKE SelectObject, hDC, hOld
INVOKE DeleteDC, memDC

INVOKE EndPaint, hWnd, ADDR ps
.ELSEIF uMsg==WM_ERASEBKGND
MOV logbrush.lbStyle, BS_SOLID
MOV logbrush.lbColor, 0
INVOKE CreateBrushIndirect, ADDR logbrush
MOV hBrush, EAX
INVOKE GetClientRect, hWnd, ADDR rect
INVOKE FillRect, wParam, ADDR rect, hBrush
MOV EAX, TRUE
RET


And yes, I've included all necessary files. What's wrong? :sad:
Posted on 2005-11-12 13:18:48 by Seb
Hi Seb,

Here is an example of using the BitmapFromResource function coming with the latest version of the image library.

http://www.asmcommunity.net/board/index.php?action=dlattach;topic=22185.0;attach=1130
Posted on 2005-11-12 16:09:10 by Vortex
Hi Vortex!

Great, I'll check it out. :)

Thanks a lot!
Posted on 2005-11-12 16:34:58 by Seb
I'm afraid the problem still exists. I changed the code based on the example in the ZIP you provided - no change. I checked the return value of "BitmapFromResource" and it's not the function failing.


.ELSEIF uMsg==WM_PAINT
MOV hDC, FUNC(BeginPaint, hWnd, ADDR ps)
MOV hMemDC, FUNC(CreateCompatibleDC, hDC)
MOV hOld, FUNC(SelectObject, hMemDC, hImage)
                        ;1
INVOKE BitBlt, hDC, 0, 0, 336, 156, hMemDC, 0, 0, SRCCOPY
INVOKE DeleteDC, hMemDC

INVOKE EndPaint, hWnd, ADDR ps


Any ideas?
Posted on 2005-11-12 18:23:12 by Seb
Hi Seb,

Your code snippet looks fine. Could you attach your zipped project to the forum?
Posted on 2005-11-13 02:38:53 by Vortex
Hi Vortex!

Sure, it's attached. BTW, if you spot any other bugs, feel free to report/fix them. :D
Attachments:
Posted on 2005-11-13 09:16:03 by Seb
Hi Seb,

You should remove this line below :

LOCAL hImage:DWORD


Keep in mind that local variables in procedures are not preserved.

Put your hImage variable in the uninitialized data section and your image will be displayed :
hImage dd ?


Notice that you should try to use the image functions from the library I posted to the forum. The functions from masm32.lib contains bugs.
Posted on 2005-11-13 09:53:31 by Vortex

Put your hImage variable in the uninitialized data section and your image will be displayed :


Wow, that sorted it! Thanks a lot! :)


Notice that you should try to use the image functions from the library I posted to the forum. The functions from masm32.lib contains bugs.


Yep, I'll do that now. Thanks again. :)
Posted on 2005-11-13 10:16:47 by Seb