Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

I create button and I try the change the font but does not work.

You can help me.

Thanks

What I have tried:

VB
Dim rhWnd As IntPtr = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0))
        Dim lhWnd As IntPtr = lhWnd = CreateWindowEx(0, "BUTTON", "Import plans", WS_VISIBLE Or WS_CHILD, 60, 90, 140, 40, h4, 0, rhWnd, 0)
        Dim hWndFont As IntPtr = CreateFont(25, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Edwardian Script ITC")

        SendMessage(lhWnd, WM_SETFONT, hWndFont, True)
Posted
Updated 1-Jul-21 6:01am
v2
Comments
Richard Deeming 1-Jul-21 4:37am    
"Does not work" tells us nothing.

Is there something wrong with one or more of your P/Invoke function declarations, or the constants?
Is one of the P/Invoke calls failing?
Is the font not available on your system?

You need to debug your code to find out where the problem is before you can try to fix it.
Member 13907800 1-Jul-21 11:47am    
May by yes but the debugger do not show me a any error. The font is installed. I try to use different fonts but does not change. But change only height of the font but not type of the font.
Member 13907800 1-Jul-21 11:48am    
Declaration
Public Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W2 As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As IntPtr

Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As Boolean) As IntPtr

1 solution

Quote:
VB.NET
Public Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W2 As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As IntPtr
As per my response to your previous question[^], your P/Invoke declaration is wrong.
VB.NET
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (_
    ByVal nHeight As Integer, ByVal nWidth As Integer, _
    ByVal nEscapement As Integer, ByVal nOrientation As Integer, _
    ByVal fnWeight As Integer, ByVal fdwItalic As Integer, _
    ByVal fdwUnderline As Integer, ByVal fdwStrikeOut As Integer, _
    ByVal fdwCharSet As Integer, ByVal fdwOutputPrecision As Integer, _
    ByVal fdwClipPrecision As Integer, ByVal fdwQuality As Integer, _
    ByVal fdwPitchAndFamily As Integer, ByVal lpszFace As String _
    ) As IntPtr
CreateFontA function (wingdi.h) - Win32 apps | Microsoft Docs[^]
pinvoke.net: CreateFont (gdi32)[^]

You are almost consistently using Long - a 64-bit integer - when you should be using Integer - a 32-bit integer.

That suggests to me that you are trying to convert code from VB6, where Integer was 16-bit and Long was 32-bit.

(The SendMessage declaration looks OK to me.)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900