iczelion tut25[2]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

if this function succeeds, it returns the handle of the memory device context in eax. hdc is the handle to the device context that you want the memory dc to be compatible with.

  • now that you got a hidden drawing surface, you can draw on it by selecting the bitmap into it. this is done by calling selectobject with the handle to the memory dc as the first parameter and the bitmap handle as the second parameter. selectobject has the following definition:
      1. selectobject   proto  hdc:hdc, hgdiobject:dword
    1. the bitmap is drawn on the memory device context now. all we need to do here is to copy it to the actual display device, namely the true device context. there are several functions that can perform this operation such as bitblt and stretchblt. bitblt just copies the content of one dc to another so it's fast while stretchblt can stretch or compress the bitmap to fit the output area. we will use bitblt here for simplicity. bitblt has the following definition:
        bitblt  proto  hdcdest:dword, nxdest:dword, nydest:dword, nwidth:dword, nheight:dword, hdcsrc:dword, nxsrc:dword, nysrc:dword, dwrop:dword
         
      hdcdest is the handle of the device context that serves as the destination of bitmap transfer operation
      nxdest, nydest are the coordinate of the upper left corner of the output area
      nwidth, nheight are the width and height of the output area
      hdcsrc is the handle of the device context that serves as the source of bitmap transfer operation
      nxsrc, nysrc are the coordinate of the upper left corner of the source rectangle.
      dwrop is the raster-operation code (hence the acronym rop) that governs how to combine the color data of the bitmap to the existing color data on the output area to achieve the final result. most of the time, you only want to overwrite the existing color data with the new one.
    1. when you're done with the bitmap, delete it with deleteobject api call.
    that's it! to recapitulate, you need to put the bitmap into the resource scipt. then load it from the resource with loadbitmap. you'll get the bitmap handle. next you obtain the handle to the device context of the area you want to paint the bitmap on. then you create a memory device context that is compatible with the device context you just obtained. select the bitmap into the memory dc then copy the content of the memory dc to the real dc.

    example code:

    .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
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\gdi32.lib

    winmain proto :dword,:dword,:dword,:dword
    idb_main   equ 1

    .data
    classname db "simplewin32asmbitmapclass",0
    appname  db "win32asm simple bitmap example",0

    .data?
    hinstance hinstance ?
    commandline lpstr ?
    hbitmap dd ?

    .code
    start:
     invoke getmodulehandle, null
     mov    hinstance,eax
     invoke getcommandline
     mov    commandline,eax
     invoke winmain, hinstance,null,commandline, sw_showdefault
     invoke exitprocess,eax

    winmain proc hinst:hinstance,hprevinst:hinstance,cmdline:lpstr,cmdshow:dword
     local wc:wndclassex
     local msg:msg
     local hwnd:hwnd
     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
     mov   wc.hbrbackground,color_window+1
     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,cw_usedefault,cw_usedefault,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

    本文关键:iczelion asm
      相关方案
    Google
     

    本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

    go top