Osd function (on screen display)

Description

J'ai fait une fonction qui permet d'afficher du texte en premier plan sur l'écran et de le placer ou l'on veut (avec fonction d'alignement verticale / horizontale...) On peut choisir la couleur du texte, la taille et la police.. J'ai aussi fait un exemple d'utilisation
Marche très bien... C'est très rapide ! Beaucoup plus rapide que la fonction consistant a faire un PictureBox.Print et ensuite de faire un fenetre "non-standard" en fonction de la picturebox (Cf. fonction MakeRegion)
Voilà j'espère que ça pourra vous aidé...
Si j'ai la motivation :) pour continuer ce proje, je vais faire un éditeur permettant de créé des fichier *.osd qui pourront être lu avec un viewer "osd" ce qui permettra de ne pas se faire "ch****" avec les pixel etc... Il suffira de dessiner son rond son carré son text et le prog fait tout le reste... Pour l'instant le prog supporte que le texte mais pour dessiner un rond ou carré etc... c'est d'une simplicité extrême !
Voilà j'espère une fois de plus que ça pourra vous aider

PS: mise à jour effectuée le 8.03.2003: Lorsque l'on affiche l'OSD, la fenêtre ayant précédemment le focus, perd le focus. Ce problème a été résolu ! (Pour plus de détail voir les commentaires)

Bonne progz a tous

Bye

Cyberdevil

Source / Exemple :


Public Function show_osd_text(frm As Form, txt As String, align_h As String, align_v As String, Optional top As Long, Optional left As Long, Optional font As String, Optional font_size As Long, Optional text_color As ColorConstants) As Boolean
Dim frmOSD As Form
Dim hRgn As Long
Dim hwnd_act As Long
On Error GoTo err:
If align_h <> "right" And align_h <> "left" And align_h <> "center" And left = 0 Then show_osd_text = False: Exit Function
If align_v <> "up" And align_v <> "down" And align_v <> "center" And top = 0 Then show_osd_text = False: Exit Function
If txt = "" Then show_osd_text = False: Exit Function
If font = "" Then font = "Arial"
If font_size = 0 Then font_size = 50
If text_color = 0 Then text_color = &HFF00&
Set frmOSD = frm
hwnd_act = GetActiveWindow()
Select Case align_h
Case "right":
With frmOSD
    .FontName = font
    .FontSize = font_size
    .BackColor = text_color
    .Width = .TextWidth(txt)
    .Height = .TextHeight(txt)
    BeginPath .hdc
    TextOut .hdc, 0, 0, txt, Len(txt)
    EndPath .hdc
    hRgn = PathToRegion(.hdc)
    SetWindowRgn .hWnd, hRgn, True
    DeleteObject hRgn
    Select Case align_v
    Case "down":
    .top = Screen.Height - .Height
    Case "up":
    .top = 0
    Case "center":
    .top = (Screen.Height - .Height) / 2
    Case Else:
    .top = top
    End Select
    .left = Screen.Width - .Width
    .Show
End With
RendreFormTjsVisible frmOSD
Case "left":
With frmOSD
    .FontName = font
    .FontSize = font_size
    .BackColor = text_color
    .Width = .TextWidth(txt)
    .Height = .TextHeight(txt)
    BeginPath .hdc
    TextOut .hdc, 0, 0, txt, Len(txt)
    EndPath .hdc
    hRgn = PathToRegion(.hdc)
    SetWindowRgn .hWnd, hRgn, True
    DeleteObject hRgn
    Select Case align_v
    Case "down":
    .top = Screen.Height - .Height
    Case "up":
    .top = 0
    Case "center":
    .top = (Screen.Height - .Height) / 2
    Case Else:
    .top = top
    End Select
    .left = 0
    .Show
End With
RendreFormTjsVisible frmOSD
Case "center":
With frmOSD
    .FontName = font
    .FontSize = font_size
    .BackColor = text_color
    .Width = .TextWidth(txt)
    .Height = .TextHeight(txt)
    BeginPath .hdc
    TextOut .hdc, 0, 0, txt, Len(txt)
    EndPath .hdc
    hRgn = PathToRegion(.hdc)
    SetWindowRgn .hWnd, hRgn, True
    DeleteObject hRgn
    Select Case align_v
    Case "down":
    .top = Screen.Height - .Height
    Case "up":
    .top = 0
    Case "center":
    .top = (Screen.Height - .Height) / 2
    Case Else:
    .top = top
    End Select
    .left = (Screen.Width - .Width) / 2
    .Show
End With
RendreFormTjsVisible frmOSD
Case Else:
With frmOSD
    .FontName = font
    .FontSize = font_size
    .BackColor = text_color
    .Width = .TextWidth(txt)
    .Height = .TextHeight(txt)
    BeginPath .hdc
    TextOut .hdc, 0, 0, txt, Len(txt)
    EndPath .hdc
    hRgn = PathToRegion(.hdc)
    SetWindowRgn .hWnd, hRgn, True
    DeleteObject hRgn
    .left = left
    .top = top
    .Show
End With
RendreFormTjsVisible frmOSD
End Select
Call SetActiveWindow(hwnd_act)
show_osd_text = True
Exit Function
err:
show_osd_text = False
Exit Function
End Function

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.