The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: p0wder on July 27, 2006, 02:25:04 PM

Title: Loading JPEG as splash
Post by: p0wder on July 27, 2006, 02:25:04 PM

I found this code here, but without a resource file ...

I tried this in my .rc:

10000 IMAGE "PortableHTTPD.jpg"

The file assembles and links without errors, however the resource file is create with a weird randomish name and the file does not load the splash ...

Also, if I use a font in a resource file, will the font will be 'compiled' with the application? If I use an exotic pixel font and someone uses my application on another pc, will they see the font or not?


;******************************************************************************
;* ASM STUFF                                                                  *
;******************************************************************************
.586p
.model flat, stdcall
option casemap :none

;******************************************************************************
;* INCLUDES (better too much...)                                              *
;******************************************************************************
include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include advapi32.inc
include gdi32.inc
include comctl32.inc
include comdlg32.inc
include ole32.inc
include oleaut32.inc
include masm32.inc
include C:\masm32\macros\macros.asm

includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib advapi32.lib
includelib gdi32.lib
includelib comctl32.lib
includelib comdlg32.lib
includelib ole32.lib
includelib oleaut32.lib
includelib masm32.lib

include    wsock32.inc
includelib wsock32.lib
includelib wininet.lib
include    wininet.inc


;******************************************************************************
;* PROTOTYPES                                                                 *
;******************************************************************************
DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

;******************************************************************************
;* DATA                                                                       *
;******************************************************************************
.data?
splashscreen_hBmp dd ?

;******************************************************************************
;* 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
LOCAL ps:PAINTSTRUCT
        LOCAL hdc:HDC
        LOCAL hMemoryDC:HDC
        LOCAL bitmap:BITMAP
LOCAL DesktopRect:RECT

MOV EAX,message
.IF EAX==WM_INITDIALOG
;---load bitmap (jpg) from resource---
        INVOKE FindResource,0,chr$("SPLASH"),RT_RCDATA
MOV edi,EAX
INVOKE SizeofResource,0,EAX
MOV esi,EAX
INVOKE LoadResource,0,edi
INVOKE BitmapFromMemory,EAX,esi ;read jpg
MOV splashscreen_hBmp,EAX
INVOKE GetObject,splashscreen_hBmp,sizeof BITMAP,addr bitmap

;---Get Desktopsize---
INVOKE GetDesktopWindow
                MOV ecx,EAX
                INVOKE GetWindowRect,ecx,addr DesktopRect
                ;---set window size&position---
                PUSH FALSE ;bRepaint
                PUSH bitmap.bmHeight ;nHeight
                PUSH bitmap.bmWidth ;nWidth
                MOV  EAX,DesktopRect.bottom ;calculate middle...
                SUB  EAX,bitmap.bmHeight
                SHR  EAX,1
                PUSH EAX ;y position
                MOV  EAX,DesktopRect.right ;calculate middle...
                SUB  EAX,bitmap.bmWidth
                SHR  EAX,1
                PUSH EAX ;x position
                PUSH hwnd ;dialog handle
                call MoveWindow

;---Set time to show the window---
INVOKE SetTimer,hwnd,1,3000,0 ;3 seconds
.ELSEIF EAX==WM_TIMER
JMP @close ;time to close...
.ELSEIF EAX==WM_PAINT
;---draw bitmap---
INVOKE BeginPaint,hwnd,addr ps
MOV hdc,EAX
INVOKE CreateCompatibleDC,hdc
MOV hMemoryDC,EAX
INVOKE SelectObject,EAX,splashscreen_hBmp
MOV esi,EAX ;esi=hOldBmp
INVOKE GetObject,splashscreen_hBmp,sizeof BITMAP,addr bitmap ;get info about bitmap
INVOKE BitBlt,hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemoryDC,0,0,SRCCOPY ;draw bitmap
INVOKE SelectObject,hMemoryDC,esi ;esi=hOldBmp
INVOKE DeleteDC,hMemoryDC
INVOKE EndPaint,hwnd,addr ps
.ELSEIF EAX==WM_CLOSE
@close:
INVOKE EndDialog,hwnd,0 ;bye bye...
.endif
xor EAX,EAX
ret                          
DialogProc endp

end main
Title: Re: Loading JPEG as splash
Post by: ToutEnMasm on July 27, 2006, 02:54:21 PM
Hello,
Bad declare for the resource,
"INVOKE FindResource,0,chr$("SPLASH"),RT_RCDATA"
follow winhelp and you see that
named resource = SPLASH
type of resource = RT_RCDATA
;
This set of fonctions are explain in the masm32 library help file
see Image files functions
              ToutEnMasm
Title: Re: Loading JPEG as splash
Post by: p0wder on July 27, 2006, 04:07:40 PM
What is odd, is that the person on the board who supplied the code in an older post, included .asm source, .res, and .exe and all work. however no .rc file ...

Anyways, masm32.hlp and masm32lib.hlp have no ref of findresource. win32api.hlp does, however.
I have changed to :

INVOKE FindResource, NULL, 1000, RT_BITMAP

The splash does not load, but I believe that it is assembled with the file [being now 14+kb]. No errors...
Title: Re: Loading JPEG as splash
Post by: ToutEnMasm on July 27, 2006, 05:56:41 PM

I am not the person who write this,but i can give you the complete code.

declare the resource like that in the .rc file,

800   IMAGE  DISCARDABLE "texture.jpg" // or other jpg

modify the code like this
replace
QuoteMOV edi,EAX
      INVOKE SizeofResource,0,EAX
      MOV esi,EAX
      INVOKE LoadResource,0,edi
      INVOKE BitmapFromMemory,EAX,esi   ;read jpg
      MOV splashscreen_hBmp,EAX

by
Quoteinvoke BitmapFromResource,hInstance,800
      mov splashscreen_hBmp,eax
you can replace hInstance by NULL or 0
Following is the same code
      INVOKE GetObject,splashscreen_hBmp,sizeof bitmap,addr bitmap
      .....
                                ...
When you have such a problem look at the source code of the function at
                    \masm32\M32LIB\BitmapFromResource.ASM
                             
                                        ToutEnMasm










Title: Re: Loading JPEG as splash
Post by: p0wder on July 27, 2006, 07:52:10 PM
Here is my code, its still a no go, no errors and still no jpeg loading :/


;******************************************************************************
;* ASM STUFF                                                                  *
;******************************************************************************
.586p
.model flat, stdcall
option casemap :none

;******************************************************************************
;* INCLUDES (better too much...)                                              *
;******************************************************************************
include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include advapi32.inc
include gdi32.inc
include comctl32.inc
include comdlg32.inc
include ole32.inc
include oleaut32.inc
include masm32.inc
include C:\masm32\macros\macros.asm

includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib advapi32.lib
includelib gdi32.lib
includelib comctl32.lib
includelib comdlg32.lib
includelib ole32.lib
includelib oleaut32.lib
includelib masm32.lib

include    wsock32.inc
includelib wsock32.lib
includelib wininet.lib
include    wininet.inc

DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data?

splashscreen_hBmp dd ?

;******************************************************************************
;* 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
LOCAL ps:PAINTSTRUCT
        LOCAL hdc:HDC
        LOCAL hMemoryDC:HDC
        LOCAL bitmap:BITMAP
LOCAL DesktopRect:RECT

MOV EAX,message
.IF EAX==WM_INITDIALOG
;---load bitmap (jpg) from resource---
        INVOKE FindResource, NULL, 1000, RT_BITMAP
INVOKE BitmapFromResource, NULL, 800
      MOV splashscreen_hBmp, EAX
INVOKE GetObject, splashscreen_hBmp, SIZEOF BITMAP, ADDR bitmap

;---Get Desktopsize---
INVOKE GetDesktopWindow
                MOV ecx,EAX
                INVOKE GetWindowRect,ecx,addr DesktopRect
                ;---set window size&position---
                PUSH FALSE ;bRepaint
                PUSH bitmap.bmHeight ;nHeight
                PUSH bitmap.bmWidth ;nWidth
                MOV  EAX,DesktopRect.bottom ;calculate middle...
                SUB  EAX,bitmap.bmHeight
                SHR  EAX,1
                PUSH EAX ;y position
                MOV  EAX,DesktopRect.right ;calculate middle...
                SUB  EAX,bitmap.bmWidth
                SHR  EAX,1
                PUSH EAX ;x position
                PUSH hwnd ;dialog handle
                call MoveWindow

;---Set time to show the window---
INVOKE SetTimer,hwnd,1,3000,0 ;3 seconds
.ELSEIF EAX==WM_TIMER
JMP @close ;time to close...
.ELSEIF EAX==WM_PAINT
;---draw bitmap---
INVOKE BeginPaint,hwnd,addr ps
MOV hdc,EAX
INVOKE CreateCompatibleDC,hdc
MOV hMemoryDC,EAX
INVOKE SelectObject,EAX,splashscreen_hBmp
MOV esi,EAX ;esi=hOldBmp
INVOKE GetObject,splashscreen_hBmp,sizeof BITMAP,addr bitmap ;get info about bitmap
INVOKE BitBlt,hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemoryDC,0,0,SRCCOPY ;draw bitmap
INVOKE SelectObject,hMemoryDC,esi ;esi=hOldBmp
INVOKE DeleteDC,hMemoryDC
INVOKE EndPaint,hwnd,addr ps
.ELSEIF EAX==WM_CLOSE
@close:
INVOKE EndDialog,hwnd,0 ;bye bye...
.endif
xor EAX,EAX
ret                          
DialogProc endp

end main

Title: Re: Loading JPEG as splash
Post by: PBrennick on July 27, 2006, 07:58:33 PM
p0wder.
Would it be possible for you to post the original assembly source file with no mods and the .res file (really need this).

Paul
Title: Re: Loading JPEG as splash
Post by: p0wder on July 27, 2006, 08:02:34 PM
here are all of the original unedited files from the 'splashscreen.zip' file.
Title: Re: Loading JPEG as splash
Post by: ToutEnMasm on July 27, 2006, 08:55:22 PM
I have tested the code in a SDI none in a dialog box,I don't see the .rc in your source.
I join the sample I have write,it is the full source.
See splash.asm and splash.rc,splash.exe to see the result.
                       ToutEnMasm


[attachment deleted by admin]
Title: Re: Loading JPEG as splash
Post by: p0wder on July 27, 2006, 09:54:31 PM
Thanks for the help, but I am just interested in getting the code that i have now working :/
Title: Re: Loading JPEG as splash
Post by: asmfan on July 28, 2006, 07:59:00 AM
I always thought that GDI cannot handle jpg but handles bmp...
Why can we treat a jpg as bitmap? I know GDI+ can handle... Am i right?
Title: Re: Loading JPEG as splash
Post by: zooba on July 28, 2006, 10:31:32 AM
Quote from: asmfan on July 28, 2006, 07:59:00 AM
I always thought that GDI cannot handle jpg but handles bmp...
Why can we treat a jpg as bitmap? I know GDI+ can handle... Am i right?

That's correct. GDI cannot handle a compressed JPEG file.

Either attach it as a bitmap (possibly at a lower colour depth) or use a decompression library. Raymond has posted one here (http://www.masm32.com/board/index.php?topic=4266.0), though personally I haven't tried it.

Cheers,

Zooba :U
Title: Re: Loading JPEG as splash
Post by: p0wder on July 28, 2006, 01:46:53 PM
masm32 examples include 3 examples using jpegs instead of bitmaps. this code is something that i have without the resource file, thats the issue. you can load a jpeg without a third party library.
Title: Re: Loading JPEG as splash
Post by: p0wder on July 28, 2006, 03:53:43 PM

.386
.model flat,stdcall
option casemap:none

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\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\oleaut32.lib

DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data
DlgName DB "DlgBox",0

.data?
hBitmap DD ?
hModule DD ?

.code

DlgProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ps:PAINTSTRUCT
LOCAL hdc:HDC
LOCAL hMemDC:HDC
.IF uMsg==WM_INITDIALOG
INVOKE CoInitialize, NULL
INVOKE BitmapFromResource, hModule, 10000
MOV hBitmap, EAX
.ELSEIF uMsg==WM_PAINT
INVOKE BeginPaint, hWnd, ADDR ps
MOV hdc, EAX
INVOKE CreateCompatibleDC, EAX
MOV hMemDC, EAX
INVOKE SelectObject, EAX, hBitmap
INVOKE BitBlt, hdc, 0, 0, 102, 100, hMemDC, 0, 0, SRCCOPY
INVOKE DeleteDC, hMemDC
INVOKE EndPaint, hWnd, ADDR ps
.ELSEIF uMsg==WM_CLOSE
INVOKE DeleteObject, hBitmap
INVOKE CoUninitialize
INVOKE EndDialog, hWnd, NULL
.ELSE
MOV EAX, FALSE
RET
.ENDIF
MOV EAX, TRUE
RET
DlgProc ENDP

start:
INVOKE GetModuleHandle, NULL
MOV hModule,EAX
INVOKE DialogBoxParam, EAX,1000,NULL,addr DlgProc,NULL
INVOKE ExitProcess,EAX
END start

Title: Re: Loading JPEG as splash
Post by: Mark Jones on July 28, 2006, 05:43:26 PM
Quote from: p0wder on July 28, 2006, 01:46:53 PM
you can load a jpeg without a third party library.

Are you saying it IS possible, or are you asking if it is possible?
Title: Re: Loading JPEG as splash
Post by: p0wder on July 28, 2006, 08:19:07 PM
 i was just saying that it is possible, there is the code above.
Title: Re: Loading JPEG as splash
Post by: zooba on July 28, 2006, 10:36:54 PM
BitmapFromResource is actually from a 3rd party library, the Masm32 library.

I should've realised that from the first section of code. Looking back at your code, I'm wondering why you have different values in the BitmapFromResource command (800) and the resource file (1000); AFAIK these must be the same. Also, you seems to be trying to select the bitmap attached to the bitmap, which doesn't work. Just select the bitmap returned straight into a memory DC, then BitBlt it, much like the example you posted.

Cheers,

Zooba :U