Load Picture to DC

Started by Farabi, April 22, 2009, 12:34:51 AM

Previous topic - Next topic

Farabi

Quote
mAlloc proc nSize:dword
   
   invoke GlobalAlloc,GMEM_ZEROINIT or GMEM_FIXED,nSize
   .if eax==0
      invoke MessageBox,NULL,CADD("Memory Allocation Error"),NULL,MB_OK
   .endif
   
   ret
mAlloc endp

Open proc lpBuffer:dword,lpFileName:dword,lpSize:dword,_size:dword
  LOCAL hfile:dword
 
invoke CreateFile,lpFileName,GENERIC_READ ,FILE_SHARE_READ ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hfile,eax
invoke ReadFile,hfile,lpBuffer,_size,lpSize,NULL 
invoke CloseHandle,hfile   

ret
Open endp

PERR   PROC uses ebx edi esi   ;, _API : DWORD
LOCAL   szMsgBuf[500]:BYTE

   INVOKE GetLastError
   mov   ebx, eax
   INVOKE FormatMessage, \
      FORMAT_MESSAGE_FROM_SYSTEM,\
      NULL, \
      ebx, \               ;Message Id
      LANG_NEUTRAL + SUBLANG_DEFAULT*1024, \   ;Message language
      ADDR szMsgBuf, \         ;Buffer to store message
      500, \               ;Buffer size
      NULL               ;No more arguments
   INVOKE   MessageBox, NULL, ADDR szMsgBuf, NULL, MB_OK

   ;INVOKE   ExitProcess, -1

   ret

PERR   ENDP


fLoadPicture proc lpFileName:dword,DC:dword
   LOCAL buff[512],hMemDC,hBitmap,mptr,err_code:dword
   LOCAL file_size:dword
   LOCAL bm:BITMAP
   LOCAL tmpDC:dword
      
      mov err_code,0
      invoke exist,lpFileName
      .if eax!=1
         invoke GetAppPath,addr buff
         invoke lstrcat,addr buff,lpFileName
         invoke exist,addr buff
         .if eax!=1
            xor eax,eax
            dec eax
            ret
         .endif
      .endif
      
      invoke filesize,lpFileName
      mov file_size,eax
      invoke mAlloc,eax
      mov mptr,eax
      invoke Open,mptr,lpFileName,addr err_code,file_size
      invoke BitmapFromMemory,mptr,file_size
      .if eax==0
         invoke PERR
         invoke MessageBox,NULL,lpFileName,NULL,MB_OK
         xor eax,eax
         dec eax
         ret
      .endif
      mov   hBitmap,eax
      invoke GlobalFree,mptr
      
      invoke CreateCompatibleDC,0
      mov tmpDC,eax
      push eax
      invoke SelectObject,tmpDC,hBitmap
      invoke DeleteObject,eax
      
      invoke GetObject,hBitmap,sizeof BITMAP,addr bm
      
      invoke BitBlt,DC,0,0,bm.bmWidth,bm.bmHeight,tmpDC,0,0,SRCCOPY
      invoke DeleteDC,tmpDC
      invoke DeleteObject,hBitmap
      pop eax
      xor eax,eax
      
   
   ret
fLoadPicture endp

I took the PERR function from one of the member here. I cant remember.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Onan,

You used the PERR function in your winsock code. Does it give you a clue?

Farabi

Quote from: Vortex on April 23, 2009, 09:34:27 AM
Hi Onan,

You used the PERR function in your winsock code. Does it give you a clue?

I cant remember.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"