CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    27

    How to access object from its pointer

    In a VB application, I want to add all symbol TrueType font facename to a combobox in a form. I use EnumFontFamiliesEx API function and
    EnumFontFamExProc callback function to implement it. My code is like:
    In form:

    Dim udtLogFont as LOGFONT
    udtLogFont.lfCharSet = SYMBOL_CHARSET
    udtLogFont.lfPitchAndFamily = 0
    EnumFontFamiliesEx me.hdc, udtLogFont, AddressOf EnumFontFamExProc, ObjPtr(cboFont), 0




    In module:

    public Function EnumFontFamExProc(udtElfe as ENUMLOGFONTEX, udtNtme as NEWTEXTMETRICEX, byval nFontType as Integer, lParam as ComboBox) as
    Integer
    Dim sFaceName as string, sFontName as string

    on error resume next

    If nFontType = TRUETYPE_FONTTYPE then
    sFaceName = StrConv(udtElfe.elfLogFont.lfFaceName, vbUnicode)
    sFontName = Left(sFaceName, InStr(sFaceName, vbNullChar) - 1)
    'Now how I can get the combobox object from lParam?
    '..................
    End If
    EnumFontFamExProc = 1
    End Function




    In EnumFontFamExProc, lParam just is ObjPtr(cboFont). How I can call AddItem method of cboFont Object? In other words, How I can get the
    combobox object from lParam? I read the article "Not reference counting" in MSDN, it has some code to get object by CopyMemory, I do so but illegal operation is caused. Any help or suggestions is appreciated.


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: How to access object from its pointer

    Instead of trying to pass an object pointer, pass the window handle of the combobox and use the sendmessage API to add the fontnames....


    private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Any) as Long

    private Const CB_ADDSTRING = &H143

    public Function EnumFontFamExProc(udtElfe as ENUMLOGFONTEX, udtNtme as NEWTEXTMETRICEX, byval nFontType as Integer, byval lParam as Long) as Integer
    Dim sFaceName as string, sFontName as string
    on error resume next
    If nFontType = TRUETYPE_FONTTYPE then
    sFaceName = StrConv(udtElfe.elfLogFont.lfFaceName, vbUnicode)
    sFontName = Left(sFaceName, InStr(sFaceName, vbNullChar) - 1)
    'Now how I can get the combobox object from lParam?
    '..................
    SendMessage lParam, CB_ADDSTRING, 0, sFontName
    End If
    EnumFontFamExProc = 1
    End Function





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

Featured