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. Print Bitmap from Printing Class Library

Print Bitmap from Printing Class Library

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicsquestionlearning
8 Posts 4 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.
  • U Offline
    U Offline
    User 14007200
    wrote on last edited by
    #1

    I use this class to print: Printing Class Library[^] I can print bitmaps if there are in a separate file. How can I print a bitmap which I added to my resource. That is, the bitmap is IDB_SAMPLE and I want to use this code

    pPage->PrintBitMap(top, left, top + 0.89, left + 0.29, "test.bmp");

    where "test.bmp" is LPCSTR variable. How can I convert IDB_SAMPLE which is a bitmap I added to my resource to a LPCSTR variable so that I can print using this function PrintBitmap(). Please any response any one can give me will be greatly appreciated.

    V L 2 Replies Last reply
    0
    • U User 14007200

      I use this class to print: Printing Class Library[^] I can print bitmaps if there are in a separate file. How can I print a bitmap which I added to my resource. That is, the bitmap is IDB_SAMPLE and I want to use this code

      pPage->PrintBitMap(top, left, top + 0.89, left + 0.29, "test.bmp");

      where "test.bmp" is LPCSTR variable. How can I convert IDB_SAMPLE which is a bitmap I added to my resource to a LPCSTR variable so that I can print using this function PrintBitmap(). Please any response any one can give me will be greatly appreciated.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      wrote:

      I use this class to print: Printing Class Library[^]

      Then why don't you want to ask the author of this article? :confused:

      U 1 Reply Last reply
      0
      • V Victor Nijegorodov

        wrote:

        I use this class to print: Printing Class Library[^]

        Then why don't you want to ask the author of this article? :confused:

        U Offline
        U Offline
        User 14007200
        wrote on last edited by
        #3

        Because he passed away. Im hoping someone can help.

        V 2 Replies Last reply
        0
        • U User 14007200

          Because he passed away. Im hoping someone can help.

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          wrote:

          Because he passed away.

          But did you try to ask him? Anyway, you should investigate/debug his code to understand how the method CPage::PrintBitMap works. Then you perhaps will be able to modify or add some code to use the bitmap resource ID rather than the bitmap pathname.

          Richard DeemingR 1 Reply Last reply
          0
          • U User 14007200

            Because he passed away. Im hoping someone can help.

            V Offline
            V Offline
            Victor Nijegorodov
            wrote on last edited by
            #5

            You may also use some other code to print out the bitmap. For instance, get this one: [Print a bitmap full page](https://www.codeproject.com/Articles/12391/Print-a-bitmap-full-page) and just change the parameters of LoadImage to load form resources rather than the file.

            1 Reply Last reply
            0
            • V Victor Nijegorodov

              wrote:

              Because he passed away.

              But did you try to ask him? Anyway, you should investigate/debug his code to understand how the method CPage::PrintBitMap works. Then you perhaps will be able to modify or add some code to use the bitmap resource ID rather than the bitmap pathname.

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Victor Nijegorodov wrote:

              Because he passed away.

              But did you try to ask him?

              Well, I guess tonight would be the right night to try. Ouija boards at the ready! NB: "He passed away" means "er ist tot".


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              V 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Victor Nijegorodov wrote:

                Because he passed away.

                But did you try to ask him?

                Well, I guess tonight would be the right night to try. Ouija boards at the ready! NB: "He passed away" means "er ist tot".


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                V Offline
                V Offline
                Victor Nijegorodov
                wrote on last edited by
                #7

                Richard Deeming wrote:

                NB: "He passed away" means "er ist tot".

                I am sorry... :( Please forgive my very poor English...

                1 Reply Last reply
                0
                • U User 14007200

                  I use this class to print: Printing Class Library[^] I can print bitmaps if there are in a separate file. How can I print a bitmap which I added to my resource. That is, the bitmap is IDB_SAMPLE and I want to use this code

                  pPage->PrintBitMap(top, left, top + 0.89, left + 0.29, "test.bmp");

                  where "test.bmp" is LPCSTR variable. How can I convert IDB_SAMPLE which is a bitmap I added to my resource to a LPCSTR variable so that I can print using this function PrintBitmap(). Please any response any one can give me will be greatly appreciated.

                  L Offline
                  L Offline
                  leon de boer
                  wrote on last edited by
                  #8

                  The PrintBitMap code is likely just calling the standard windows API call LoadImage. LoadImageA function | Microsoft Docs[^] If you read the documentation the fix will be obvious, you need to not set the LR_LOADFROMFILE flag when passing in a resource ID in the string. Down the bottom in the remarks you will find reference to a neat macro IS_INTRESOURCE(lpszName). IS_INTRESOURCE macro | Microsoft Docs[^] So Microsoft gives you a macro to work out if a string is actually an INTRESOURCE. So basically a one line fix in the code find the LR_LOADFROMFILE and set it only if IS_INTRESOURCE returns false. It is the always setting of that flag that is fouling the LoadImage working properly because you want the extended behaviour that is spelled out in this statement

                  Quote:

                  The image to be loaded. If the hinst parameter is non-NULL and the fuLoad parameter omits LR_LOADFROMFILE, lpszName specifies the image resource in the hinst module. If the image resource is to be loaded by name from the module, the lpszName parameter is a pointer to a null-terminated string that contains the name of the image resource. If the image resource is to be loaded by ordinal from the module, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function.

                  As an extended answer you may want to consider adding a few lines of code to test the string extension for known types JPG etc not just resource ID and use IPicture to add that support. As an example this will take a filename string and convert a jpg to a bitmap handle. You would use this function in place of LoadImage in the situation you had a jpeg filename and you could then print jpegs. The disadvantages of using classes and frameworks is you never learn the Windows API and how it is designed to work. Anyhow the small code block follows, I gave you the option of returning the wth, ht of the jpeg loaded but you can use NULL if you don't want them returned.

                  #include
                  HBITMAP HBMPFromJPGF

                  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