Is there a way I can draw pixels on a screen without any need of OpenGL or other third party library, using just the native SDK built in Windows NT 10 Kernel?
I got quite comfortable using HLA even though I have problem on Windows 10 probably the HIDE IDE is no longer maintained for quite some time.
Any way I can draw pixels on a surface or a window?
Hi luciddreamer,
You can try the SetPixel API function to draw pixels :
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpixel
A quick example :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
RGB MACRO red,green,blue
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red
ENDM
.data
DlgBox db 1,0,255,255,0,0,0,0,0,0,0,0,64,0,207,16
db 0,0,6,0,6,0,147,0,136,0,0,0,0,0,71,0
db 114,0,97,0,112,0,104,0,0,0,8,0,0,0,0,0
db 77,0,83,0,32,0,83,0,65,0,78,0,83,0,32,0
db 83,0,69,0,82,0,73,0,70,0,0,0
.data?
hDC dd ?
color dd ?
.code
start:
RGB 0,0,0
mov color,eax
invoke GetModuleHandle,0
xor ecx,ecx
invoke DialogBoxIndirectParam,eax,\
ADDR DlgBox,ecx,ADDR DlgProc,ecx
invoke ExitProcess,0
DlgProc PROC USES ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_CLOSE
invoke EndDialog,hWnd,NULL
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd,ADDR ps
mov hDC,eax
xor ebx,ebx
@@:
mov eax,ebx
shl eax,1
inc eax ; symmetrical graph of
; y = 2x + 1
invoke SetPixel,hDC,ebx,eax,color
inc ebx
cmp ebx,110
jnz @b
invoke EndPaint,hWnd,ADDR ps
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
DlgProc ENDP
END start
Quote from: Vortex on March 14, 2021, 11:55:07 PM
Hi luciddreamer,
You can try the SetPixel API function to draw pixels :
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpixel
A quick example :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
RGB MACRO red,green,blue
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red
ENDM
.data
DlgBox db 1,0,255,255,0,0,0,0,0,0,0,0,64,0,207,16
db 0,0,6,0,6,0,147,0,136,0,0,0,0,0,71,0
db 114,0,97,0,112,0,104,0,0,0,8,0,0,0,0,0
db 77,0,83,0,32,0,83,0,65,0,78,0,83,0,32,0
db 83,0,69,0,82,0,73,0,70,0,0,0
.data?
hDC dd ?
color dd ?
.code
start:
RGB 0,0,0
mov color,eax
invoke GetModuleHandle,0
xor ecx,ecx
invoke DialogBoxIndirectParam,eax,\
ADDR DlgBox,ecx,ADDR DlgProc,ecx
invoke ExitProcess,0
DlgProc PROC USES ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_CLOSE
invoke EndDialog,hWnd,NULL
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd,ADDR ps
mov hDC,eax
xor ebx,ebx
@@:
mov eax,ebx
shl eax,1
inc eax ; symmetrical graph of
; y = 2x + 1
invoke SetPixel,hDC,ebx,eax,color
inc ebx
cmp ebx,110
jnz @b
invoke EndPaint,hWnd,ADDR ps
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
DlgProc ENDP
END start
Thanks Vortex for the Example Zip :biggrin: :greenclp: :greenclp: , this is what I was looking for!