flat assembler
Message board for the users of flat assembler.

Index > Windows > Drawing pixel using GDI

Author
Thread Post new topic Reply to topic
ghst



Joined: 09 Feb 2007
Posts: 8
Location: Lusitania
ghst 09 Feb 2007, 19:49
Does anyone know a simple example showing how to draw a pixel in a window specific area? I'm trying to plot a graphic using binary data from a rs232 conection..
No OpenGL or DX, just simple GDI.

Thank you!
Post 09 Feb 2007, 19:49
View user's profile Send private message Reply with quote
MichaelH



Joined: 03 May 2005
Posts: 401
MichaelH 09 Feb 2007, 23:56
Madis731 posted some examples in a thread but deleted the src.

Also check out madmatt thread example

http://board.flatassembler.net/topic.php?t=4619

Here is the code from one of the examples. Use Alt F4 to end the program.



Code:
format PE GUI 4.0
entry start

include 'win32a.inc'
include 'macro\if.inc'

section '.data' data readable writeable

  _class db 'Sipelgas',0

  mainhwnd dd ?
  hinstance dd ?
  hdc dd ?
  x dd 200h
  y dd 180h
  v dd 1

  msg MSG
  wc WNDCLASS

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        mov     [wc.style],0
        mov     [wc.lpfnWndProc],WindowProc
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     eax,[hinstance]
        mov     [wc.hInstance],eax
        mov     [wc.hbrBackground],2
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],_class
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,0,90000000h,0,0,400h,300h,NULL,NULL,[hinstance],NULL
        mov     [mainhwnd],eax
        invoke  GetDC,eax
        mov     [hdc],eax
        invoke  Rectangle,[hdc],0-1,0-1,1024+1,768+1
  msg_loop:
        invoke  PeekMessage, msg, 0, 0, 0, PM_REMOVE
        .if eax,ne,0
            invoke  TranslateMessage,msg
            invoke  DispatchMessage,msg
            cmp     [msg.message],WM_QUIT
            je      end_loop
        .endif
mov [v+4],512
agn:
    invoke  GetPixel,[hdc],[x],[y],eax
    xor     eax,000FFFFFFh
    invoke  SetPixel,[hdc],[x],[y],eax
    pop ecx ;eax ei tohiks return värvi saada!
    mov ebx,[v]
    mov ecx,[x]
    mov edx,[y]

    sub eax,0
    jnz nxt12
      add ebx,1
      cmp ebx,4
      jle nxt21
        mov ebx,1
      jmp nxt21
    nxt12:
      sub ebx,1
      cmp ebx,1
      jae nxt21
        mov ebx,4
    nxt21:

    sub ebx,1
    jz trn1
    sub ebx,1
    jz trn2
    sub ebx,1
    jz trn3
        sub edx,2
        add ebx,1
    trn2:add edx,1
        add ecx,1
        sub ebx,1
    trn3:sub ecx,2
        add ebx,2
    trn1:add ecx,1
        add ebx,1

    cmp ecx,400h
    jz nxt31
    cmp edx,300h
    jz nxt32
    cmp edx,-1
    jz nxt33
    cmp ecx,-1
    jz nxt34
    jmp nxt35
    nxt34: add ecx,400h
           sub edx,300h
    nxt33: add edx,600h
    nxt32: sub edx,300h
           add ecx,400h
    nxt31: sub ecx,400h
    nxt35:

    mov [y],edx
    mov [x],ecx
    mov [v],ebx
    sub [v+4],1
jnz agn
        ;invoke Sleep,40
        jmp     msg_loop

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          gdi,'GDI32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess',\
         Sleep,'Sleep'

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         PeekMessage,'PeekMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         PostQuitMessage,'PostQuitMessage',\
         GetDC,'GetDC'

  import gdi,\
         GetPixel,'GetPixel',\
         SetPixel,'SetPixel',\
         Rectangle,'Rectangle'
    
Post 09 Feb 2007, 23:56
View user's profile Send private message Reply with quote
ghst



Joined: 09 Feb 2007
Posts: 8
Location: Lusitania
ghst 12 Feb 2007, 11:21
Hum.. I didn't search properly.. This helps alot, thank you very much!
Post 12 Feb 2007, 11:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.