|
You may also use some other code to print out the bitmap.
For instance, get this one: Print a bitmap full page and just change the parameters of LoadImage to load form resources rather than the file.
|
|
|
|
|
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 <olectl.h>
HBITMAP HBMPFromJPGFile (char* filename, int* returnWth, int* returnHt){
const int HIMETRIC_PER_INCH = 2540;
int Wth, Ht;
HRESULT hr;
WCHAR OlePathName[512];
HBITMAP bmp;
HDC MemDC;
SIZE sizeInHiMetric;
IPicture *Ipic = NULL;
MultiByteToWideChar(CP_ACP, 0, filename,
(int)strlen(filename)+1, &OlePathName[0], 512);
hr = OleLoadPicturePath(OlePathName, NULL, 0, 0,
IID_IPicture, (LPVOID*) &Ipic);
if ((hr == S_OK) & (Ipic != 0)){
HDC Dc = GetDC(NULL);
int nPixelsPerInchX = GetDeviceCaps(Dc, LOGPIXELSX);
int nPixelsPerInchY = GetDeviceCaps(Dc, LOGPIXELSY);
ReleaseDC(NULL, Dc);
Ipic->get_Width(&sizeInHiMetric.cx);
Ipic->get_Height(&sizeInHiMetric.cy);
Wth = (nPixelsPerInchX * sizeInHiMetric.cx +
HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;
Ht = (nPixelsPerInchY * sizeInHiMetric.cy +
HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;
MemDC = CreateCompatibleDC(0);
int P2Width = Wth >> 2;
if ((P2Width << 2) < Wth) P2Width++;
P2Width = P2Width << 2;
BITMAPINFO bi = {0};
DWORD *pBits = 0;
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biWidth = P2Width;
bi.bmiHeader.biHeight = Ht;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biPlanes = 1;
bmp = CreateDIBSection(MemDC, &bi, DIB_RGB_COLORS,
(void**)&pBits, 0, 0);
Ipic->Release();
if (returnWth) (*returnWth) = Wth;
if (returnHt) (*returnHt) = Ht;
return bmp;
}
return 0;
}
In vino veritas
modified 1-Nov-18 0:17am.
|
|
|
|
|
Hi
When have the following code
class a
{
int a;
LPCTSTR b;
c d;
}
where "c" is defined
class c
{
…
}
so if class a is in a.h and class c is in c.h
what is the difference between #include "c.h' in a.h or declaring class c; or as a better question what is the way to resolve the unresolved reference in a.h for the type "c" which is a class
is it to "include "c.h" or declare class c; that c is of type class and I guess in that case "c" will get resolved by the linker
Hope this question makes sense
thanks
|
|
|
|
|
Did you try to add the forward declaration
class c; in the a.h? Does it compile? If Yes - then use it.
Otherwise put
#include "c.h" in a.h
|
|
|
|
|
the forward declaration worked #include didn't was just wondering about the difference I guess the linker will resolve class a ? right thanks
|
|
|
|
|
No, the linker connects object code, it has no knowledge of classes. Classes are purely a mechanism used in source languages and converted into object code by the compiler.
|
|
|
|
|
In the code you posted, the forward declaration can not work. If it worked in your code, it may be including c.h without your knowing, maybe indirectly through another header.
If #include doesn't work, read the error message. The only reasons for #include not working that I can think of is that either the code in your c.h has a syntax error, or you forgot to add an Include guard[^], causing a duplicate definition.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
In this case, a.h needs to include c.h since the former needs to know the full definition of c.
|
|
|
|
|
Well, Well, Well!
This question is the result of too much abstraction in education of computer scientists!
A bit of learning of how a compiler works, Things like Bits and Bytes, the underlying mechanisms, and what it cannot do would help you here. This is an insolvable problem! Ultimately, a compiler lays out code, reserves blocks of memory of a certain size, etc.
The compiler needs to know how much memory is needed for each user defined type (in C(++)) that is a union, structure or a class!
When you Declare a class, you tell the compiler to take note of the name of the class! The Linker may than be able to find that class properly defined in another file, and hence in another .obj file! The compiler cannot at that stage know anything about the size of the object, so, all you can use is either a pointer of an object of that type, or, a reference to it! A Reference to an object is very similar to a pointer, it is a compiler guaranteed pointer, that cannot be null, and always points at an object of the type!
In Your code class 'c' needs to be defined in the file before class a in which it is used! Otherwise your compiler cannot calculate the size of class a!
Best of luck learning more,
There may be rules around this conundrum in synthetic languages such as C#,Java etc. I would know nothing of these! There are no such shortcuts in C or CPP!
I encourage anyone to take up C or CPP! It are the base languages on which all others are built! A knowledge of Machine Code, and how it translates in ASM, would also help you
Bram van Kampen
|
|
|
|
|
The question was-[![Go to the link][1]][1]
[1]: https:
My code-
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int r,c,i,j,t=0;
scanf("%d",&r);
scanf("%d",&c);
int a[r][c];
int counter=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
for(i=1;i<(r-1);i++)
{
for(j=1;j<(c-1);j++)
{
t=t+1;
int count=0;
if(a[i][j-1]==0)
count+=1;
if(a[i][j+1]==0)
count+=1;
if(a[i-1][j]==0)
count+=1;
if(a[i+1][j]==0)
count+=1;
if(count==3)
printf("%d\n",a[i][j]);
else
counter+=1;
}
}
if (counter ==t)
{
printf("No peninsular elements");
}
}
My logic is to take each inner element and then find its surrounding element. If the surrounding element is 0, then I am increasing my count by 1 otherwise I am increasing counter by 1. If my count equals 3 at the end of the loop, then I am printing that element.
I am getting a private test case failed error when I am running it on my university site. Is there any flaw in my logic that I can rectify to overcome this error.
|
|
|
|
|
You need to find out what the error message is telling you. We cannot guess what your teacher had in mind.
|
|
|
|
|
wrote: int a[r][c]; You need a constant expression here. What compiler are you using (that didn't catch this)?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Is there possible to catch inside CHtmlView a javascript event (I mean when a dropdown menu is down) ? In a site, on a searching box, if I type some letters, there is a dropdown menu which show me the result of my search ... and I have to programmatically select a link there... but if I put this site inside my CHtmlView, how can I know if this dropdown menu is down, and so the searching has been complete ?
|
|
|
|
|
Message Closed
modified 29-Oct-18 13:11pm.
|
|
|
|
|
This is not good idea, because when the app doesn't have the focus, this trick doesn't work ...
|
|
|
|
|
|
double a = -60 ;
double b = -7500
bool flag;
if (a < b)
{
flag = true;
}
For the above check flag is getting true, it is not supposed to, how can I make the double negative comparison?
|
|
|
|
|
Comparison of double values behaves as expected, of course (and, as it stands, your code doesn't compile): the program
#include <iostream>
int main()
{
double a = -60 ;
double b = -7500;
bool flag = false;
if (a < b)
{
flag = true;
}
std::cout << std::boolalpha << flag << std::endl;;
}
ouptus
false
|
|
|
|
|
It is because your Quote: bool flag; was NOT initialized and contains garbage that is treated as true just because it is not zero.
Try:
double a = -60 ;
double b = -7500
bool flag = (a < b);
|
|
|
|
|
Am trying to use the clistctrl class using c++/MFC and Microsoft Visual studio 2017. I have designed a report style control with four columns. I am unable to display columns two through four. Am using InsertColumn method to establish the columns, the insertItem method to display the first column and the SetItem method to display columns two through four. I have followed the examples from all around the internet. Only the column headers & the first column are displayed. Is there anyone out there that has gotten this to work? If so could you reference the successful code.
|
|
|
|
|
I use CListCtrl since two decades and never had any problem with the report style...
Could you post your code?
|
|
|
|
|
Are you calling SetItemText for each column?
|
|
|
|
|
Do you need to adjust the column width? Without showing your relevant code, it's anybody's guess.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
hello i have a project of creating a 2D game with the c but i do not know how to start anyone can help me please
the game name is block puzzle
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|