Results 1 to 9 of 9

Thread: Drawing/Overlaying Text Directly to screen

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Drawing/Overlaying Text Directly to screen

    Hey guys,

    Ok Ill cut straight to the point I know this could be to do with DirectX or something but ill post it here for now. What I would like to know is how to Draw text directly to the screen - effectively overlapping anything underneath it - but have it out side a form area! I would really like to have no user interface at all if possible I know what I wanted after recently using FRAPs. To get an Idea of what i need here is a screen shot of it in action (FRAPs):

    (See the top left corner).

    Thanks for any help what so ever xD

    -Josh

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Drawing/Overlaying Text Directly to screen

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim gr As Graphics = Graphics.FromHwnd(New IntPtr(0))
    3.     gr.DrawString("text on screen", New Font(Me.Font.FontFamily, 25, FontStyle.Regular), Brushes.Red, 50, 50)
    4. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Drawing/Overlaying Text Directly to screen

    Hmmm this code seems to do nothing :O

    -Josh

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Drawing/Overlaying Text Directly to screen

    Quote Originally Posted by jduncanator View Post
    Hmmm this code seems to do nothing :O

    -Josh
    Hm, I had that trouble too. Paul, is there something we missed here?

    Meanwhile, Josh, there is an alternative that might suit your purposes -- show a transparent, borderless form with the text on it. Here's an example which you could code on a form with a button Button1:

    Code:
    	Private WithEvents TextForm As New Form
    	Private Zipper As New FontFamily("Zipper")
    
    	Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    		With TextForm
    			.BackColor = Color.DimGray
    			.TransparencyKey = Color.DimGray
    			.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    			.ShowInTaskbar = False
    			.WindowState = FormWindowState.Maximized
    			.Opacity = 0
    			.Show(Me)
    		End With
    	End Sub
    
    	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    		Static showText As Boolean
    		showText = Not showText
    		If showText Then TextForm.Opacity = 0.99 Else TextForm.Opacity = 0
    	End Sub
    
    	Private Sub TextForm_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles TextForm.Paint
    		e.Graphics.DrawString("text on screen 12345", New Font(Zipper, 30, FontStyle.Bold), Brushes.Red, 50, 50)
    	End Sub
    A few notes:
    1. You could also use your main form this way. Many of the properties shown here in the Load sub could be set in Designer.
    2. It's a good idea to make the transparent form an Owned Form of the one underneath. In the example above, it's done by the argument in TextForm.Show(Me). You can also set the Form.Owner property in code. Making the transparent form TopMost is not a good substitute.
    3. Anti-aliasing is a problem with transparent forms. The smoothing pixels show up in the form's TransparencyKey colour on curves and diagonals of the text where the colour contrasts with the background. One way to deal with this is to choose a font without curves or diagonals - for example Zipper which I downloaded free from www.FontRiver.com. Alternatively, set Graphics.TextRenderingHint to SingleBitPerPixelGridFit.
    4. Form Opacity is my favourite way to switch visibility. Using 0.99 instead of 1 for the maximum opacity gives a smoother result.

    BB

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Drawing/Overlaying Text Directly to screen

    thanks someone told me about this, and yes its a possability but not ideal as some of the programs it will be running over will be full screened

    -Josh

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Drawing/Overlaying Text Directly to screen

    Quote Originally Posted by jduncanator View Post
    Hmmm this code seems to do nothing :O

    -Josh
    on my PC it writes directly on the screen, but it's erased as soon as the desktop refreshes. that's probably the problem...

  7. #7

    Re: Drawing/Overlaying Text Directly to screen

    Quote Originally Posted by jduncanator View Post
    Hey guys,

    Ok Ill cut straight to the point I know this could be to do with DirectX or something but ill post it here for now. What I would like to know is how to Draw text directly to the screen - effectively overlapping anything underneath it - but have it out side a form area! I would really like to have no user interface at all if possible I know what I wanted after recently using FRAPs. To get an Idea of what i need here is a screen shot of it in action (FRAPs):
    -image snipped-
    (See the top left corner).

    Thanks for any help what so ever xD

    -Josh
    What I think FRAPS is doing is injecting some code to write the FPS of the program in a specified corner (which is configurable in the application), so they're probably using some DirectX and hooking code to do so...just a bit of possible insight for you.

  8. #8
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Drawing/Overlaying Text Directly to screen

    To confirm, drawing over a full screen DirectX overlay is a very different kettle of fish to drawing onto the desktop. To handle a DirectX overlay you really need access to that process and do it from there. I don't know how but I imagine it will involve a certain amount of hacky API such as WriteProcessMemory and luck.

    Edit: directX overlays in windowed mode are much easier, see advice above.
    Last edited by Milk; May 14th, 2011 at 07:32 PM. Reason: if only I could construct a english sentance
    W o t . S i g

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Drawing/Overlaying Text Directly to screen

    Ok heres the deal, I need to write a program that will overlay on top of all the windows, I'm stuffing the full screen crap, this program will mainly be used for writing information over the top of a flash game running in a browser, makeing a transparent form, at the moment, is out of the picture, and would really love for something that is able to do it either running in the background or not... Also I have a question, if a program has a transparent form running over a flash game (running around 30-40fps) surely this would have a hit on the system??

    -Josh

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width