PDA

View Full Version : تغییر فونت و سایز فونت Notepad , MsDos Prompt از vb6



zehs_sha
دوشنبه 27 مرداد 1382, 21:27 عصر
بچه ها من می خواهم از داخل برنامه خودم فونت و سایز فونت Notepad , MsDos Prompt را تغییر بدهم چگونه می توانم 8)

S.Azish
سه شنبه 28 مرداد 1382, 13:53 عصر
من نمونه انجام این کار رو در Notepad درآوردم, میتونید با کمی تغییر برای برنامه های دیگر هم استفاده کنید




Option Explicit
Private hNewFont As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const FW_BOLD = 700
Private Const GW_CHILD = 5
Private Const WM_SETFONT = &H30
Private Const WM_GETFONT = &H31
Private Const LF_FACESIZE As Byte = 32

Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type

Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long

Private Declare Function CreateFontIndirect Lib "gdi32" _
Alias "CreateFontIndirectA" _
(lpLogFont As LOGFONT) As Long

Private Sub Form_Load()
'

Dim hNotePad As Long
Dim hTextBox As Long
Dim objectTemp As Object
Dim hCurrFont As Long
Dim LF As LOGFONT

hNotePad = FindWindow("notepad", vbNullString)
hTextBox = GetWindow(hNotePad, GW_CHILD)
hCurrFont = SendMessage(hTextBox, WM_GETFONT, Len(LF), LF)
LF.lfWeight = FW_BOLD
hNewFont = CreateFontIndirect(LF)
Call SendMessage(hTextBox, WM_SETFONT, hNewFont, ByVal True)
'
End Sub

Private Sub Form_Unload(Cancel As Integer)
'
If hNewFont Then
Call DeleteObject(hNewFont)
End If
'
End Sub