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. C / C++ / MFC
  4. GetTextMetrics

GetTextMetrics

Scheduled Pinned Locked Moved C / C++ / MFC
c++
8 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.
  • N Offline
    N Offline
    Nyarlatotep
    wrote on last edited by
    #1

    I'm experiencing an odd behaviour with GetTextMetrics() (used sooo many times). I've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works. I'm using VC++ 6.0.

    L 1 Reply Last reply
    0
    • N Nyarlatotep

      I'm experiencing an odd behaviour with GetTextMetrics() (used sooo many times). I've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works. I'm using VC++ 6.0.

      L Offline
      L Offline
      Laxman Auti
      wrote on last edited by
      #2

      Nyarlatotep wrote:

      've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works.

      You may need to select the font again so that the device context gets new tmHeight and tmExternalLeading values that you updated.:~ Knock out 't' from can't, You can if you think you can :cool:

      N 1 Reply Last reply
      0
      • L Laxman Auti

        Nyarlatotep wrote:

        've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works.

        You may need to select the font again so that the device context gets new tmHeight and tmExternalLeading values that you updated.:~ Knock out 't' from can't, You can if you think you can :cool:

        N Offline
        N Offline
        Nyarlatotep
        wrote on last edited by
        #3

        uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006

        L A 2 Replies Last reply
        0
        • N Nyarlatotep

          uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006

          L Offline
          L Offline
          Laxman Auti
          wrote on last edited by
          #4

          Nyarlatotep wrote:

          SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2);

          I have tested that when you create the font and retrive the external leading it returns '0' mostly. why you don't try using the tmHeight parameter of the CreateFont when tmExternalLeading is 0 without making call for GetTextMetrics repeatlly. Knock out 't' from can't, You can if you think you can :cool:

          N 1 Reply Last reply
          0
          • N Nyarlatotep

            uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006

            A Offline
            A Offline
            Arvind Bharti
            wrote on last edited by
            #5

            please try the following code: --------------------------------------- hOldFont = SelectObject(hfont1); GetTextMetrics(hdc,tm1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; // Do not forget to clean up. SelectObject(hdc, hOldFont); DeleteObject(hfont1); hOldFont = SelectObject(hfont2); GetTextMetrics(hdc,tm2); ---------------------------------------

            N 1 Reply Last reply
            0
            • L Laxman Auti

              Nyarlatotep wrote:

              SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2);

              I have tested that when you create the font and retrive the external leading it returns '0' mostly. why you don't try using the tmHeight parameter of the CreateFont when tmExternalLeading is 0 without making call for GetTextMetrics repeatlly. Knock out 't' from can't, You can if you think you can :cool:

              N Offline
              N Offline
              Nyarlatotep
              wrote on last edited by
              #6

              I could. But GetTextMetrics() is called only at the beginning of the code and not every time TextOut is called. The question is why GetTextMetrics hangs. Never happened before !!! :)

              L 1 Reply Last reply
              0
              • A Arvind Bharti

                please try the following code: --------------------------------------- hOldFont = SelectObject(hfont1); GetTextMetrics(hdc,tm1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; // Do not forget to clean up. SelectObject(hdc, hOldFont); DeleteObject(hfont1); hOldFont = SelectObject(hfont2); GetTextMetrics(hdc,tm2); ---------------------------------------

                N Offline
                N Offline
                Nyarlatotep
                wrote on last edited by
                #7

                Selecting the old font and destroyng hfont1 works. :) But in this way i've to re-create hfont1 each time (i use it in many places along with hfont2).

                1 Reply Last reply
                0
                • N Nyarlatotep

                  I could. But GetTextMetrics() is called only at the beginning of the code and not every time TextOut is called. The question is why GetTextMetrics hangs. Never happened before !!! :)

                  L Offline
                  L Offline
                  Laxman Auti
                  wrote on last edited by
                  #8

                  Nyarlatotep wrote:

                  The question is why GetTextMetrics hangs. Never happened before !!!

                  This may due to following. -You have taken the device context of the printer where lots of jobs may pending -When you get the device context of printer and textout the text the device context is in use while jobs may pending or your process is not scheduled. -and you are trying to get/set the information of the device context which may denied as exclusive access to device context:~ Hope you got the issue. Knock out 't' from can't, You can if you think you can :cool:

                  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