Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. LOGFONT structure

LOGFONT structure

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnsGe
    wrote on last edited by
    #1

    Hai All, In my application i want to set the lfHeight of the text using the LOGFONT structure. How can i use the LOGFONT structure and Font::FromLogFont in MC++? . I simply redefined the LOGFONT structure and uses it FromLogFont method. But runtime exception occures. Anyone have any idea?? Thanks in Advance Anish

    U 1 Reply Last reply
    0
    • A AnsGe

      Hai All, In my application i want to set the lfHeight of the text using the LOGFONT structure. How can i use the LOGFONT structure and Font::FromLogFont in MC++? . I simply redefined the LOGFONT structure and uses it FromLogFont method. But runtime exception occures. Anyone have any idea?? Thanks in Advance Anish

      U Offline
      U Offline
      ursus zeta
      wrote on last edited by
      #2

      The function takes a pointer to a System::Object. You must cast the LOGFONT structure to a System::Object, using either __try_cast or reinterpret_cast. The other overload also takes a pointer to the device context in addition to the Object pointer.

      A 1 Reply Last reply
      0
      • U ursus zeta

        The function takes a pointer to a System::Object. You must cast the LOGFONT structure to a System::Object, using either __try_cast or reinterpret_cast. The other overload also takes a pointer to the device context in addition to the Object pointer.

        A Offline
        A Offline
        AnsGe
        wrote on last edited by
        #3

        Hai, I couldn't get it. Also runtime exception occures even i type caste the LOGFONT structure. Can you show a simple piece of code using LOGFONT structure and Font::FromLogFont method thank u

        G 1 Reply Last reply
        0
        • A AnsGe

          Hai, I couldn't get it. Also runtime exception occures even i type caste the LOGFONT structure. Can you show a simple piece of code using LOGFONT structure and Font::FromLogFont method thank u

          G Offline
          G Offline
          george ivanov
          wrote on last edited by
          #4

          you needn't use FromLogFont, you can set it as this: LOGFONT lf; CFont* pFont; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 20; lf.lfWeight = 900; strcpy(lf.lfFaceName, _T("Tahoma")); pFont = CFont::FromHandle(::CreateFontIndirect(&lf)); SetFont(pFont); were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?

          U 1 Reply Last reply
          0
          • G george ivanov

            you needn't use FromLogFont, you can set it as this: LOGFONT lf; CFont* pFont; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 20; lf.lfWeight = 900; strcpy(lf.lfFaceName, _T("Tahoma")); pFont = CFont::FromHandle(::CreateFontIndirect(&lf)); SetFont(pFont); were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?

            U Offline
            U Offline
            ursus zeta
            wrote on last edited by
            #5

            I came across this over at the MSDN site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp[^] It's written for C# programmers, but, you use the same attribute in C++. Also, if you just want to set only the Font height, and leave all the other LOGFONT structure members in their default settings (except for the Face Name), you can just use the appropriate Font constructor from the .NET Framework class library (without calling the FromLogfont method). This is the simplest approach. You instantiate with the new operator, the same way you do for all Form controls. It occurred to me that the GDI LOGFONT structure is unmanaged code, and the Interop Marshaler makes the data conversions from managed to unmanaged and back again (if necessary). The problem with the LOGFONT struct, is that the original definition takes the lfFaceName mamber as an array of type TCHAR. Since this could be either ANSI or Unicode, the size of the array is not known at compile time. I assume the Interop Marshaler does not convert these values correctly (and, you'd think they'd note that in the documentation for the FromLogfont method). And, so you must specify this explicitly with the MarshalAs pseudo-custom attribute. There are lengthy explanations of the inner workings of Interop marshaling in Adam Nathan's book, ".NET and COM: The Complete Interoperability Guide".

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups