首页 > 其他分享 >win32asm制作像素画画布

win32asm制作像素画画布

时间:2023-07-16 16:00:15浏览次数:29  
标签:addr invoke 画画 mov 像素 eax stWndClass hDC win32asm

 

类似于像素画软件中鼠标点击便绘制出一个小方块。

可以对窗口DC使用PatBlt函数。

1 invoke PatBlt,hDC,xDest,yDest,dwWidth,dwHeight,dwROP

dwWidth和dwHeight作为绘制的小方块的宽和高。dwROP决定方块图案。

在对WM_LBUTTONDOWN消息的处理中,获取此时鼠标的位置,根据鼠标的位置求出应该传给PatBlt函数的xDest和yDest参数的值。

例如:当鼠标点击的位置是(x+10,y+4),我们需要的(xDest,yDest)应该是(x,y)。

选取方块区域的左上角是因为PatBlt函数是将当前画刷的图案拷贝到hDC中以(xDest,yDest)为左上角坐标,dwWidth为宽度,dwHeight为高度的区域中。

不对鼠标位置进行处理的话,就不能绘制出规则排列的小方块。

还可以在窗口DC上画出网格,同样可以使用PatBlt函数,不过这次绘制的是宽度为1,高度为画布长度的竖线 和 宽度为画布长度,高度为1的横线。每隔相同距离绘制一次。

 一个简单的例子:

  1 .386
  2 .model flat,stdcall
  3 option casemap:none
  4 
  5 include         windows.inc     
  6 include         gdi32.inc
  7 includelib      gdi32.lib
  8 include         user32.inc      
  9 includelib      user32.lib
 10 include         kernel32.inc
 11 includelib      kernel32.lib
 12 ;================================================
 13         .const
 14 szClassName     db      'canvas',0
 15 szCaptionMain   db      'Can I draw Pixel?',0
 16 
 17         .data
 18 dwPixelSize     dd        16
 19         .data?
 20 hInstance       dd      ?
 21 hWinMain        dd      ?
 22 hDC             dd        ?
 23 dwPosx          dd        ?
 24 dwPosy          dd        ?
 25 ;================================================
 26         .code
 27 ;================================================
 28 _DrawGrid        proc    _hDC
 29                 local    @count
 30                 mov      @count,0
 31         ;========
 32         ;竖线
 33         ;========
 34         vertical:
 35                 invoke    PatBlt,_hDC,@count,0,1,320,BLACKNESS
 36                 add       @count,16
 37                 cmp      @count,320
 38                 jng      vertical
 39                 
 40                 mov       @count,0
 41         ;========
 42         ;横线
 43         ;========
 44         horizontal:
 45                 invoke    PatBlt,_hDC,0,@count,320,1,BLACKNESS
 46                 add       @count,16
 47                 cmp      @count,320
 48                 jng      horizontal
 49                 
 50                 ret
 51 _DrawGrid        endp
 52 ;================================================
 53 _AdjustPos        proc    _xPos,_yPos
 54                 push    eax
 55                 push    edx
 56                 xor        eax,eax
 57                 xor        edx,edx
 58                 mov        eax,_xPos
 59                 idiv      dwPixelSize
 60                 shl        eax,4
 61                 mov        dwPosx,eax
 62                 
 63                 xor        eax,eax
 64                 xor        edx,edx
 65                 mov        eax,_yPos
 66                 idiv      dwPixelSize
 67                 shl        eax,4
 68                 mov        dwPosy,eax
 69                 
 70                 pop        edx
 71                 pop        eax
 72                 ret
 73 _AdjustPos        endp
 74 ;================================================
 75 _ProcWinMain    proc    uses ebx edi esi,hWnd,uMsg,wParam,lParam
 76                 local   @stPs:PAINTSTRUCT
 77                 local   @stRect:RECT
 78                 local   @stPos:POINT
 79                 local   @hDc
 80 
 81                 mov     eax,uMsg
 82 ;*********************************************************************
 83                .if     eax ==  WM_PAINT
 84                         invoke  BeginPaint,hWnd,addr @stPs
 85                         mov     @hDc,eax
 86                         invoke    _DrawGrid,@hDc
 87                         invoke  EndPaint,hWnd,addr @stPs
 88 ;*********************************************************************
 89                 .elseif eax ==    WM_LBUTTONDOWN
 90                         invoke    GetCursorPos,addr @stPos
 91                         invoke    ScreenToClient,hWnd,addr @stPos
 92                         invoke    GetDC,hWnd
 93                         mov        hDC,eax
 94                         invoke    _AdjustPos,@stPos.x,@stPos.y
 95                         invoke    PatBlt,hDC,dwPosx,dwPosy,16,16,BLACKNESS
 96                         invoke    ReleaseDC,hWnd,hDC
 97 ;*********************************************************************
 98                 .elseif eax ==  WM_CLOSE
 99                         invoke  DestroyWindow,hWinMain
100                         invoke  PostQuitMessage,NULL
101 ;*********************************************************************
102                 .else
103                         invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
104                         ret
105                 .endif
106 
107                 xor     eax,eax
108                 ret
109 
110 _ProcWinMain    endp
111 ;================================================
112 _WinMain        proc
113                 local   @stWndClass:WNDCLASSEX
114                 local   @stMsg:MSG
115 
116                 invoke  GetModuleHandle,NULL
117                 mov     hInstance,eax
118                 invoke  RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
119                                                       
120                 invoke  LoadCursor,0,IDC_ARROW
121                 mov     @stWndClass.hCursor,eax
122                 push    hInstance
123                 pop     @stWndClass.hInstance
124                 mov     @stWndClass.cbSize,sizeof WNDCLASSEX
125                 mov     @stWndClass.style,CS_HREDRAW or CS_VREDRAW or CS_CLASSDC
126                 mov     @stWndClass.lpfnWndProc,offset _ProcWinMain
127                 mov     @stWndClass.hbrBackground,COLOR_WINDOW + 1
128                 mov     @stWndClass.lpszClassName,offset szClassName
129                 invoke  RegisterClassEx,addr @stWndClass
130         ;Create MainWindow
131                 invoke  CreateWindowEx,NULL,\
132                         offset szClassName,offset szCaptionMain,\
133                         WS_OVERLAPPED or WS_SYSMENU,\
134                         100,100,336,352,\
135                         NULL,NULL,hInstance,NULL
136                 mov     hWinMain,eax
137 
138                 invoke  ShowWindow,hWinMain,SW_SHOWNORMAL
139                 invoke  UpdateWindow,hWinMain
140                 
141                 .while  TRUE
142                         invoke  GetMessage,addr @stMsg,NULL,0,0
143                         .break  .if eax == 0
144                         invoke  TranslateMessage,addr @stMsg
145                         invoke  DispatchMessage,addr @stMsg
146                 .endw
147                 ret
148 
149 _WinMain        endp
150 ;================================================
151 start:
152     call    _WinMain
153     invoke  ExitProcess,NULL
154 end start

标签:addr,invoke,画画,mov,像素,eax,stWndClass,hDC,win32asm
From: https://www.cnblogs.com/heaxng/p/17557929.html

相关文章

  • UE5 像素流问题记录
    基本理论流送优化指南|虚幻引擎5.2文档(unrealengine.com)UE4像素流(PixelStreaming)应用场景-知乎(zhihu.com)D:\PixelStreaming\Windows\ZhongHuaHuaFei.exe-AuditMixer-forceres-ResX=1920-ResY=1080-PixelStreamingIp=localhost-PixelStreamingPort=8900-RenderOff......
  • 上传图片分辨率,像素大小限制
    原文//上传图片handleBeforeUploadCompanyLogo(file){//企业logobefoevarthat=thisconst_URL=window.URL||window.webkitURLconstisSize=newPromise((res,rej)=>{constimage=newImage()......
  • 图扑智慧地下采矿,“像素游戏”智能呈现
    在这个像素世界里,我们需要一个智能地下采矿可视化综合管理平台,来帮助我们管理和监控地下采矿全流程。图扑软件依托自主研发的HTforWeb产品,结合三维定制化渲染、动态模拟、物理碰撞、5G、物联网、云计算及大数据等先进技术,围绕地下采矿相关的实时监控、数据分析、人工智能等......
  • Flex中进行像素级碰撞检测
    Flex中判断两个obj之间是否碰撞很容易,调用hitTestObject只能做外接正矩形区域的检测,调用hitTest则可以做像素级检测。hitTest方法参考: http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/......
  • 给你的 Discord 接入一个既能联网又能画画的 ChatGPT
    如果有这样一款Discord机器人,它既能访问互联网,又能绘画,还能给YouTube视频提供摘要。最重要的是,它是完全免费的,不需要提供OpenAI的APIKey,我就问你香不香?现在就有这样一款机器人,你用还是不用?DiscordAIChatbot上链接:https://github.com/mishalhossin/Discord-AI-Chatbot......
  • ico文件修改像素点
    #include<QApplication>#include<QPixmap>#include<QImage>#include<QRgb>#include<QDebug>intmain(intargc,char*argv[]){QApplicationapp(argc,argv);QPixmappixmap("D:\\Code\\Qt\\popup\\logo.i......
  • 像素与颜色
    一.像素的概念我们在电脑或者电视上能看到色彩斑斓的图像,其实这些图像都是由一个一个像素点构成的,那么就首先要知道什么是像素以及什么是颜色。在内存中,每个像素点由4字节构成,这4个字节的代表的含义如下:  (1)第一个字节决定像素的红色值  (2)第二个字节决定像素的绿色值  (3......
  • react 滚动到指定位置上方100像素的位置
    /*使用方法:import{useRef}from'react';constanchor=useRef<HTMLDivElement>(null);<divref={anchor}>test</div><buttononClick={()=>{scrollWithAnimation(anchor.current?.offsetTop||0);}}>jump</b......
  • cartographer代码——世界坐标系点和像素坐标系点的转换
    构建栅格地图,要弄清楚坐标之间的关系。本篇根据代码,画出了坐标转换的关系。如下图:cartographer中的代码如下://Returnstheindexofthecellcontainingthe'point'whichmaybeoutside//themap,i.e.,negativeortoolargeindicesthatwillreturnfalsefo......
  • 基于前景和背景的图像分割,流行排序模型 MATLAB代码 将图像像素
    基于前景和背景的图像分割,流行排序模型MATLAB代码将图像像素分为前景类和背景类。基于图的流形排序模型的交互式图像分割框架,该模型是一种基于图的半监督学习技术,可以根据输入数据显示的内在结构学习非常光滑的函数。通过克服传统模型中图构造的两个核心问题:图的结构和图的边缘权......