From: Aegis Delacour on
hi guys i need some urgent help here..could someone help me fix this
code..it compiles fine but just doesnt show up as i want it to..i need
to display a jpg on screen

void CLowerEicasDlg::screeny()
{
HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcC = CreateCompatibleDC(hdc);

int dest_x, dest_y, width, height;
dest_x=0;
dest_y=0;
width=800;
height=900;

FIBITMAP *fibmp_img = FreeImage_Load(FIF_JPEG, "screen1.JPG",
JPEG_DEFAULT);
StretchDIBits(hdcC, dest_x, dest_y, width, height, 0, 0, width,
height, FreeImage_GetBits(fibmp_img), FreeImage_GetInfo(fibmp_img),
DIB_RGB_COLORS, SRCCOPY);
FreeImage_Unload(fibmp_img);

DeleteDC(hdc);
DeleteDC(hdcC);

}
From: Joseph M. Newcomer on
THere are some deeper problems here.

But a superficial question: "just doesn't show up as I want it to" is not a really good
description of what you are seeing. Are you seeing nothing? Something that doesn't look
right? What?

The deeper problem is that you are drawing something on the main display, and at any
instant, any other app is free to redraw its pixels at any place on the screen, erasing
whatever your image is. So whatever you do, it will gradually degrade as other apps do
redrawing.

If your goal is to create a window that covers the screen for some duration while your
program does something else, that's a different question, but in that case you would not
be doing a CreateDC("Display") [note: the correct form is CreateDC(_T("Display")) so you
are Unicode-aware, and the file is _T("screen1.jpg"), and so on]; you would have a window
that is the size of the screen [be aware that "the screen" might mean "the user's primary
monitor" or "the user's current monitor"; you have to assume a multi-monitor environment],
and in that case you would using the CPaintDC of the OnPaint handler to draw. But the
code shown below is not really a good idea because it just splats some pixels onto some
piece of the screen, which then will be whimsically redrawn by windows underneath them.

I presume the magical values for destination and width shown here are just for
illustration, since on a real machine these numbers are meaningless noise. For example,
my primary monitor is 1920x1600 and my secondary monitor is 1280x1024, so numbers like 0,0
for the origin means "on the primary monitor" and the other two numbers do not correspond
to any monitor size I have ever known.

So what are you trying to accomplish with this code? There is probably a better way to do
it, but we need to know both your intended goal and what is wrong.
joe

On Wed, 4 Nov 2009 03:30:24 -0800 (PST), Aegis Delacour <eloquent1(a)gmail.com> wrote:

>hi guys i need some urgent help here..could someone help me fix this
>code..it compiles fine but just doesnt show up as i want it to..i need
>to display a jpg on screen
>
>void CLowerEicasDlg::screeny()
>{
>HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
>HDC hdcC = CreateCompatibleDC(hdc);
>
>int dest_x, dest_y, width, height;
>dest_x=0;
>dest_y=0;
>width=800;
>height=900;
>
>FIBITMAP *fibmp_img = FreeImage_Load(FIF_JPEG, "screen1.JPG",
>JPEG_DEFAULT);
>StretchDIBits(hdcC, dest_x, dest_y, width, height, 0, 0, width,
>height, FreeImage_GetBits(fibmp_img), FreeImage_GetInfo(fibmp_img),
>DIB_RGB_COLORS, SRCCOPY);
>FreeImage_Unload(fibmp_img);
>
>DeleteDC(hdc);
>DeleteDC(hdcC);
>
>}
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Giovanni Dicanio on


"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
news:6r03f5pfqupojtaknqktbukputjman2oa6(a)4ax.com...

>[note: the correct form is CreateDC(_T("Display")) so you
> are Unicode-aware, and the file is _T("screen1.jpg"), and so on];

OK regarding CreateDC, but I think that is not correct regard the file name.
In fact, if I understood right, the OP is using the open source "freeimage"
library, which has two different functions for loading the files.
One is FreeImage_Load, which takes a const char* as input, and another one
is FreeImage_LoadU, which takes a const wchar_t *.
So, the usual Win32 _T() pattern cannot be applied in this particular case.

For the OP: there is an article on CodeProject showing the use of freeimage
in MFC context:

http://www.codeproject.com/KB/graphics/graphicsuite.aspx?msg=628753

Giovanni



From: Joseph M. Newcomer on
OK, I was not familiar with the library interface. I assumed this was some Microsoft
class I had previously not encountered.
joe

On Wed, 4 Nov 2009 18:52:39 +0100, "Giovanni Dicanio"
<giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:

>
>
>"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
>news:6r03f5pfqupojtaknqktbukputjman2oa6(a)4ax.com...
>
>>[note: the correct form is CreateDC(_T("Display")) so you
>> are Unicode-aware, and the file is _T("screen1.jpg"), and so on];
>
>OK regarding CreateDC, but I think that is not correct regard the file name.
>In fact, if I understood right, the OP is using the open source "freeimage"
>library, which has two different functions for loading the files.
>One is FreeImage_Load, which takes a const char* as input, and another one
>is FreeImage_LoadU, which takes a const wchar_t *.
>So, the usual Win32 _T() pattern cannot be applied in this particular case.
>
>For the OP: there is an article on CodeProject showing the use of freeimage
>in MFC context:
>
>http://www.codeproject.com/KB/graphics/graphicsuite.aspx?msg=628753
>
>Giovanni
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Aegis Delacour on
Ok i think i was not very clear.
Here is what i need.
The entire program is very long, when a physical button is pressed..it
will go to the function screeny();
when it does that, it will load and display an image(Jpg) on full
screen...there is no need to stretch it out or anything as the image
WILL be
in the exact resolution of the monitor.

currently with that code, it just doesnt work..the program that was
running before i pessed the button is still running.

im really not sure why im finding it this hard to just display a
jpg..surely theres an easy way as this seems quite basic?