Print Bitmap from Printing Class Library
-
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.
-
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.
wrote:
I use this class to print: Printing Class Library[^]
Then why don't you want to ask the author of this article? :confused:
-
wrote:
I use this class to print: Printing Class Library[^]
Then why don't you want to ask the author of this article? :confused:
Because he passed away. Im hoping someone can help.
-
Because he passed away. Im hoping someone can help.
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.
-
Because he passed away. Im hoping someone can help.
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.
-
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.
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
-
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
Richard Deeming wrote:
NB: "He passed away" means "er ist tot".
I am sorry... :( Please forgive my very poor English...
-
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.
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