用win32汇编画 8卦图

 

  汇编图:

  这几天在学习汇编语言图形操作于是想起以前用C#画过个小 8卦图

  半径R自己给……

Graphics g = e.Graphics;
            Brush fillWhiteBrush = Brushes.White;
            Brush fillBlackBrush = Brushes.Black;
            g.FillPie(fillWhiteBrush, 0, 0, r, r, -90, -180);//左半圆
            g.FillPie(fillBlackBrush, 0, 0, r, r, 90, -180);//右半圆
            g.FillEllipse(fillWhiteBrush, r/4, 0, r / 2, r / 2);//上中型圆
            g.FillEllipse(fillBlackBrush, r / 4, r / 2, r / 2, r / 2);//下中型圆
            g.FillEllipse(fillBlackBrush, 9*r/20, r/5, r / 20, r / 20);//左小圆
            g.FillEllipse(fillWhiteBrush, 9 * r / 20, 7*r/10, r / 20, r / 20);//右小圆


  win32汇编实现

  中需要GDIAPI来实现……

  包括:画笔(CreatePen)、画刷(GetStockObject)、坐标定位(MoveToEx)、画直线(LineTo)、画椭圆(Ellipse)、画扇形(Pie)……

  注释已经很清楚了我就不废话了……

  绘图核心源码:

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;画太极 8卦
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_PaTaiJi proc
         LOCAL hBrush:HBRUSH;黑色笔刷
         LOCAL wBrush:HBRUSH;白色笔刷
         LOCAL hPen:HPEN;白色画笔
         ;LOCAL lpPo:LPPOINT
         invoke  Ellipse,hDc,  0,0,200,200;大圆
         invoke  GetStockObject,BLACK_BRUSH;
         mov hBrush,eax;获取黑色笔刷并保存起来
         invoke  GetStockObject,DC_BRUSH;
         mov wBrush,eax;获取白色笔刷并保存起来
         invoke SelectObject,hDc,hBrush;选择黑色笔刷
         invoke Pie,hDc,0,0,200,200,100,0,100,200;左半个扇形
         invoke  Ellipse,hDc,  50,100,150,200;右半小扇形
        
        
         invoke SelectObject,hDc,wBrush;选择白色笔刷
         invoke Pie,hDc,50,0,150,100,100,0,100,100;左半小扇形
         invoke Ellipse,hDc,  95,145,105,155;上小圆
        
         ;将画上小圆留下黑色线条擦去
         invoke MoveToEx,hDc,100,1,0;起始坐标移动到(100,1)处
         ;将白色(RGB值为:255 255 255)填充到eax
         xor eax,eax
         mov ah,255
                 mov al,255
                 shl eax,8
                 mov al,255;
                
         invoke CreatePen,PS_SOLID,2,eax;
         mov hPen,eax;
         invoke SelectObject,hDc,hPen;
         invoke LineTo,hDc,99,99;
         ;
        
          invoke SelectObject,hDc,hBrush;选择黑色笔刷
         invoke  Ellipse,hDc,  95,45,105,55;上小圆
         
    ret

_PaTaiJi endp


  整个源码:

汇编整个代码(在RadASM调试通过)
.386

.model flat,stdcall
option map:none

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

; Include 文件定义
;

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

; MyFirstApp.inc

  windows.inc
  user32.inc
lib user32.lib
  kernel32.inc
lib kernel32.lib
  Gdi32.inc
lib Gdi32.lib

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

; 数据段

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

   .data?

hInstance dd ?;模块句柄
hWinMain dd ?;窗口句柄

stPs   PAINTSTRUCT <>;
stRect   RECT <>;
hDc  dd ?;
     .const

szClassName      db    'MyTaiJi',0;类名

szCaptionMain    db    '汇编画 8卦',0;窗口标题


;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

; 代码段

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                 .code

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

; 窗口过程

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_ProcWinMain     proc  uses ebx edi esi,hWnd,uMsg,wParam,lParam


 

                 mov   eax,uMsg

;********************************************************************

                 .      eax     WM_PAINT

                          invoke    BeginPa,hWnd,addr stPs

                          mov       hDc,eax

                          invoke    GetClientRect,hWnd,addr stRect
     call _PaTaiJi;

                          invoke    EndPa,hWnd,addr stPs

;********************************************************************

                 .  eax     WM_CLOSE

                          invoke    DestroyWindow,hWinMain

                          invoke    PostQuitMessage,NULL

;********************************************************************

                 .

                          invoke    DefWindowProc,hWnd,uMsg,wParam,lParam

                                   ret

                          .end

;********************************************************************

                 xor      eax,eax

                 ret

 

_ProcWinMain     endp

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;构建窗口

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain         proc

                 local    @stWndClass:WNDCLASSEX

                 local    @stMsg:MSG

 

                 invoke   GetModuleHandle,NULL

                 mov                hInstance,eax

                 invoke   RtlZeroMemory,addr @stWndClass, @stWndClass

;********************************************************************

; 注册窗口类

;********************************************************************

                 invoke   LoadCursor,0,IDC_ARROW

                 mov      @stWndClass.hCursor,eax

                 push     hInstance

                 pop      @stWndClass.hInstance

                 mov      @stWndClass.cbSize, WNDCLASSEX

                 mov      @stWndClass.style,CS_HREDRAW or CS_VREDRAW

                 mov      @stWndClass.lpfnWndProc,off _ProcWinMain

                 mov      @stWndClass.hbrBackground,COLOR_WINDOW + 1

                 mov      @stWndClass.lpszClassName,off szClassName

                 invoke   RegisterClassEx,addr @stWndClass

;********************************************************************

; 建立并显示窗口

;********************************************************************

                 invoke   CreateWindowEx,WS_EX_CLIENTEDGE,

                          off szClassName,off szCaptionMain,

                          WS_OVERLAPPEDWINDOW,

                          100,100,600,400,

                          NULL,NULL,hInstance,NULL

                 mov      hWinMain,eax

                 invoke   ShowWindow,hWinMain,SW_SHOWNORMAL

                 invoke   UpdateWindow,hWinMain

;********************************************************************

; 消息循环

;********************************************************************

                 .while   TRUE

                          invoke    GetMessage,addr @stMsg,NULL,0,0

                          .    . eax  0

                          invoke    TranslateMessage,addr @stMsg

                          invoke    DispatchMessage,addr @stMsg

                 .endw

                 ret

 

_WinMain         endp

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;画太极 8卦
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

_PaTaiJi proc
   LOCAL hBrush:HBRUSH;黑色笔刷
   LOCAL wBrush:HBRUSH;白色笔刷
   LOCAL hPen:HPEN;白色画笔
   ;LOCAL lpPo:LPPOINT
   invoke  Ellipse,hDc,  0,0,200,200;大圆
   invoke  GetStockObject,BLACK_BRUSH;
   mov hBrush,eax;获取黑色笔刷并保存起来
   invoke  GetStockObject,DC_BRUSH;
   mov wBrush,eax;获取白色笔刷并保存起来
   invoke SelectObject,hDc,hBrush;选择黑色笔刷
   invoke Pie,hDc,0,0,200,200,100,0,100,200;左半个扇形
   invoke  Ellipse,hDc,  50,100,150,200;右半小扇形
  
  
   invoke SelectObject,hDc,wBrush;选择白色笔刷
   invoke Pie,hDc,50,0,150,100,100,0,100,100;左半小扇形
   invoke Ellipse,hDc,  95,145,105,155;上小圆
  
   ;将画上小圆留下黑色线条擦去
   invoke MoveToEx,hDc,100,1,0;起始坐标移动到(100,1)处
   ;将白色(RGB值为:255 255 255)填充到eax
   xor eax,eax
   mov ah,255
                 mov al,255
                 shl eax,8
                 mov al,255;
                
   invoke CreatePen,PS_SOLID,2,eax;
   mov hPen,eax;
   invoke SelectObject,hDc,hPen;
   invoke LineTo,hDc,99,99;
   ;
  
    invoke SelectObject,hDc,hBrush;选择黑色笔刷
   invoke  Ellipse,hDc,  95,45,105,55;上小圆
   
 ret

_PaTaiJi endp


;入口
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:

                 call     _WinMain

                 invoke   ExitProcess,NULL

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                 end      start


Tags: 

延伸阅读

最新评论

发表评论