flat assembler
Message board for the users of flat assembler.

Index > Windows > Draw Rectangle directly on the screen without a window?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
How can I draw a rectangle directly on the screen without a window?
Post 26 Jul 2014, 19:44
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
You can use GetDesktopWindow and GetWindowDC then the usual drawing functions - SetPixel/LineTo & MoveTo, BitBlt etc but these will not persist without trapping/forcing redraw.
Post 26 Jul 2014, 20:01
View user's profile Send private message Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
Thank you very much, cod3b453!

Here my first try

Code:
include "win32ax.inc"

.data
  cnt dd 1000

.code 
start:

@@:
  dec [cnt]
  jz @f

  invoke GetDesktopWindow
  invoke GetWindowDC,eax

  invoke BitBlt,eax,100,100,250,100,0,0,0,BLACKNESS

  invoke Sleep,10
  jmp @b
@@:

finish:
  invoke ExitProcess,0

.end start 
    
Post 26 Jul 2014, 21:17
View user's profile Send private message Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
How can I remove the rectangle and how can I define the color? *confused*

If I move the rectangle to a new position, the old rectangle still exists for some time.

Code:
include "win32ax.inc" 

.data 
  cnt dd 1000 

.code  
start: 

@@: 
  dec [cnt] 
  jz @f 

  invoke GetDesktopWindow 
  invoke GetWindowDC,eax 

  invoke BitBlt,eax,[cnt],[cnt],250,100,0,0,0,BLACKNESS 

  invoke Sleep,10 
  jmp @b 
@@: 

finish: 
  invoke ExitProcess,0 

.end start 
    
Post 26 Jul 2014, 21:25
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
The problem here is you are effectively hijacking the screen and overwriting the display area; if you really want to do this without creating a proper window you'll either need to enumerate all the open windows using EnumWindows* or save a copy of the screen under the region you're colouring in and put it back when you move it (though this is less reliable).

*You can get their regions using GetWindowRect. For every window that is under your box, you'll probably need to trap drawing using SetWindowLong to subclass the WM_PAINT or similar messages to redraw over the top or use SendMessage WM_PAINT or similar to force a redraw when you want to move it and restore the proper drawing.
Post 26 Jul 2014, 21:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
You could also force all other windows to redraw the portion under the rectangle by sending an InvalidateRect message. That way you don't need to manage the pixels yourself, each window will handle its own drawing in the usual fashion.
Post 26 Jul 2014, 21:59
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
revolution wrote:
...InvalidateRect...
I knew it existed! Just couldn't remember the name Cool
Post 26 Jul 2014, 22:05
View user's profile Send private message Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
Thank you, guys! You're awesome!
Post 27 Jul 2014, 08:46
View user's profile Send private message Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
AndreyT wrote:

InvalidateRect does not immediately redraw the window. It simply "schedules" a future redraw for a specific rectangular area of the window. Using InvalidateRect you may schedule as many areas as you want, making them accumulate in some internal buffer. The actual redrawing for all accumulated scheduled areas will take place later, when the window has nothing else to do. (Of course, if the window is idle at the moment when you issue the InvalidateRect call, the redrawing will take place immediately).

You can also force an immediate redraw for all currently accumulated invalidated areas by calling UpdateWindow. But, again, if you are not in a hurry, explicitly calling UpdateWindow is not necessary, since once the window is idle it will perform a redraw for all currently invalidated areas automatically.

RedrawWindow, on the other hand, is a function with a much wider and flexible set of capabilities. It can be used to perform invalidation scheduling (i.e. the same thing InvalidateRect does) or it can be used to forcefully perform immediate redrawing of the specified area, without doing any "scheduling". In the latter case calling RedrawWindow is virtually equivalent to calling InvalidateRect and then immediately calling UpdateWindow.


Source: http://stackoverflow.com/questions/2325894/difference-between-invalidaterect-and-redrawwindow
Post 28 Jul 2014, 14:06
View user's profile Send private message Reply with quote
badc0de02



Joined: 25 Nov 2013
Posts: 216
Location: %x
badc0de02
you have to make a screen shot and copy from the image the rect and set it in like a puzzle to remove it --
Post 28 Jul 2014, 16:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
A screen shot is not a good option IMO because the applications running can be dynamic and have different data to display. If you simply overwrite it with some previous capture then you get old pixels mixed with new pixels and the user says "WTF is this mess?".
Post 28 Jul 2014, 16:39
View user's profile Send private message Visit poster's website Reply with quote
badc0de02



Joined: 25 Nov 2013
Posts: 216
Location: %x
badc0de02
so just simply use window hook to update every windows SIMPLY?
Post 28 Jul 2014, 17:20
View user's profile Send private message Reply with quote
badc0de02



Joined: 25 Nov 2013
Posts: 216
Location: %x
badc0de02
or just simply get A new Screenshot to every drawing cycle and REPLACE IT SIMPLY?
Post 28 Jul 2014, 17:22
View user's profile Send private message Reply with quote
badc0de02



Joined: 25 Nov 2013
Posts: 216
Location: %x
badc0de02
we have now to opinions Revolution wich is the simplest wich no?
Post 28 Jul 2014, 17:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
badc0de02 wrote:
or just simply get A new Screenshot to every drawing cycle and REPLACE IT SIMPLY?
A new screen shot would have the rectangle on it thus defeating the purpose.
Post 28 Jul 2014, 17:46
View user's profile Send private message Visit poster's website Reply with quote
badc0de02



Joined: 25 Nov 2013
Posts: 216
Location: %x
badc0de02
whats with the next OPINION?
Post 28 Jul 2014, 17:55
View user's profile Send private message Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
I thought also about screenshots ... but wasn't sure about the overhead/data while making a mass of screenshots.

And by the way, how would I paint the rectangle part of the image to the screen?
The code I've right now draws only a black rectangle. And I don't know how to change the color.
I guess it should also be able to draw a circle ... without painting every single by my self.
Post 28 Jul 2014, 18:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
upsurt wrote:
And by the way, how would I paint the rectangle part of the image to the screen?
If you want to transfer an image then you can use the BitBlt API.

BTW: I can't image why you want to avoid using a window. Things become much simpler when you use the OS tools for their intended purpose. The OS can also use the GPU to accelerate various functions. If you bypass all that stuff then you probably only end up creating a headache for yourself by duplicating all the OS code.
Post 28 Jul 2014, 18:55
View user's profile Send private message Visit poster's website Reply with quote
upsurt



Joined: 14 Jan 2014
Posts: 51
upsurt
upsurt wrote:
AndreyT wrote:

InvalidateRect does not immediately redraw the window. It simply "schedules" a future redraw for a specific rectangular area of the window. Using InvalidateRect you may schedule as many areas as you want, making them accumulate in some internal buffer. The actual redrawing for all accumulated scheduled areas will take place later, when the window has nothing else to do. (Of course, if the window is idle at the moment when you issue the InvalidateRect call, the redrawing will take place immediately).

You can also force an immediate redraw for all currently accumulated invalidated areas by calling UpdateWindow. But, again, if you are not in a hurry, explicitly calling UpdateWindow is not necessary, since once the window is idle it will perform a redraw for all currently invalidated areas automatically.

RedrawWindow, on the other hand, is a function with a much wider and flexible set of capabilities. It can be used to perform invalidation scheduling (i.e. the same thing InvalidateRect does) or it can be used to forcefully perform immediate redrawing of the specified area, without doing any "scheduling". In the latter case calling RedrawWindow is virtually equivalent to calling InvalidateRect and then immediately calling UpdateWindow.


Source: http://stackoverflow.com/questions/2325894/difference-between-invalidaterect-and-redrawwindow


by the way, these to options work, but only around 80%

invoke InvalidateRect,rc,TRUE
invoke UpdateWindow,[hwnd]

and

invoke RedrawWindow,[hwnd],NULL,NULL,RDW_FRAME+RDW_INVALIDATE+RDW_UPDATENOW+RDW_ALLCHILDREN

But they don't clean the whole rectangle, only a part. So they will be a black part left. Sad

WHY??
Post 28 Jul 2014, 18:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
upsurt wrote:
<snip>

But they don't clean the whole rectangle, only a part. So they will be a black part left. Sad

WHY??
Because the OS uses a lot of optimisations to make things more efficient. But when you do thing manually without informing the OS about changes then things get out of sync.

BTW: If you used a formal window then you won't have this problem.
Post 28 Jul 2014, 18:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.