 |
|
 |
How to clear the png image without making background white when new image is displayed?
|
|
|
|
 |
|
 |
I loaded a .jpg image from resource like this, it works for me.
m_picCtrl.LoadFromResource(NULL,_T("#130"),_T("IMAGE"));
|
|
|
|
 |
|
 |
Hello there, since some years I have been searching for MFC Drawing Control to view and draw simple constructions elements. I’m looking for following functionality: 0) View Picture/EMF (like this sample) 1) Draw something from code 1) Copy Content to Clipboard 2) Save Content as EMF All free and commercial CAD are ActiveX, and too big for my use. If somebody reads this mail and can give me some advice, I would be very grateful. Maybe there is also a commercial MFC Drawing Control with an appropriate price? Best Regards, J.O.
|
|
|
|
 |
|
 |
Hey everybody,
The Projekt works great..... until todays morning. I dont know what i have done and i don´t find the mistake. If i click the button to open the dialog and show my image the programm freez. The debugger told me that he stuck in this loop in the PictureCtrl.cpp
I use the loadfromFile funktion
while(UINT dwRead = cFile.Read(pBuffer, 1024))
{
dwResult = m_pStream->Write(pBuffer, dwRead, NULL);
if(dwResult != S_OK)
{
SetLastError(dwResult);
SAFE_RELEASE(m_pStream);
cFile.Close();
return FALSE;
}
}
Can anyone help me please?
Here my code
void CMainFrame::OnPreviewButton()
{
CPreviewDLG dlg1;
dlg1.DoModal();
}
void CPreviewDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC_0711, picControl);
CString filename ("current.bmp");
picControl.LoadFromFile(filename);
}
thanks in advance
bawe
ps: sry for my bad english
|
|
|
|
 |
|
 |
Ok i have the solution.
The pictures size was to big. 32MB is not suitable to show in an dialog.
|
|
|
|
 |
|
 |
Any updates on Load From Resource, I noticed commented out
|
|
|
|
 |
|
 |
Hi,
Can you please provide a sample on how to use it? Or can I use it without GDI+? Don't really undersand how to add GDI+....sorry I am newbie...Thanks
|
|
|
|
 |
|
 |
Dear Sir,
Your piece of code helps me to accomplish my final year project.
In fact, I am programming a trojan horse for academic purpose and I would love
to have approval before submitting my work.
I would gratefully reference you within my project.
Thank you in advance.
|
|
|
|
 |
|
 |
My program is dialog based.
I use MFC and VS2010.
To display pictures I use your class "PictureCtrl".
on static work fine.
but in dynamic i have problems...
I update my static controls in loop.
And depend of situation I load one or other picture I need.
loop work OnTimer one time in sec.
problem1:
after ~1500 loops my program go out and become no answer.
this happend if i use png with bmp OK.
problem2:
if I use fileopen dialog and I select file and click OK all my images that I update in loop becames invisible and do not restore after.
How can I get all work fine?
|
|
|
|
 |
|
 |
Hi, Could you explain how can I use this control in VC++ 6.0? Thanks
|
|
|
|
 |
|
 |
Hi,
Most difficult part of using this in VC6 is getting GDIPlus (GDI+) set up.
Set your project settings to make use of the required header and lib files for compile purposes.
Refer to Starting with GDI+[^]
If you use the control in a CFormview, take note of the requirements in the comments to do this - see end of this.
In stadfx.h - add the following lines:
// GDIPlus specifics
#define ULONG_PTR ULONG
#include "gdiplus.h"
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
In your class header file, you need to manually change your control variables from e.g. CStatic to CPictureCtrl
//{{AFX_DATA(CScan)
enum { IDD = IDD_SCA };
CPictureCtrl m_MainPic; // This was a CStatic and manually changed to CPictureCtrl
CPictureCtrl m_Ex1Pic;
CPictureCtrl m_Ex2Pic;
//}}AFX_DATA
Then in your class .cpp file you use commands such as:
m_MainPic.LoadFromFile(FileName);
The picturectrl header and cpp files must be modified for a formview:
Ensure header file contains these lines:
protected:
virtual void PreSubclassWindow();
//Draws the Control
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_MESSAGE_MAP()
And that cpp file contains:
BEGIN_MESSAGE_MAP(CPictureCtrl, CStatic)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
END_MESSAGE_MAP()
|
|
|
|
 |
|
 |
Looked allover and finally found this. A simple static image viewer that can be adapted as a thumbnail image in a vc6 wallpaper changer
|
|
|
|
 |
|
 |
Hi,
first thank you for the create class.
Now finally...is there a way to load a resource also?
For your quick answer I'll thank you
Greetings
|
|
|
|
 |
|
 |
I am not able to get the double click event on the class wizard.
|
|
|
|
 |
|
 |
Hi,
I have another problem (unfortunatelly).
If i use PictureCtrl class in Single Dialog Based application it works perfect.
But when I create a Dialog in SDI (Single Document Interface) application the picture is loading but when PictureCtrl is trying to run theese functions:
Invalidate();
RedrawWindow();
return TRUE;
error message window apears. "Debug Assertin Failed"
When I click Ignore it starts to work OK
Please help.
modified on Monday, July 27, 2009 9:09 AM
|
|
|
|
 |
|
 |
The following code makes this work
in header after
virtual BOOL OnEraseBkgnd(CDC* pDC);
a
DECLARE_MESSAGE_MAP()
in cpp file before
CPictureCtrl::CPictureCtrl(void)
add
BEGIN_MESSAGE_MAP(CPictureCtrl, CStatic)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
END_MESSAGE_MAP()
This maps the messages to the handler and it displays images correctly in CFormView it also probably fixes many other modes where it wasnt working.
Tested with VST2005 /MTd and static MFC.
|
|
|
|
 |
|
 |
Hi,
This also allows CFormView to work under VC6 on XP - thanks for the tip.
|
|
|
|
 |
|
 |
In VC6 there is no Owner Drawn setting in the Resource Editor for the Static Text box, is there any solution to this, as this is what would prevent most VC6 users to use CPictureCtrl correctly?
|
|
|
|
 |
|
 |
This function does not seem to exist. I need to clear an image; how do I go about doing it? Is there an updated version of PictureCtrl?
|
|
|
|
 |
|
 |
Did you find a way to freeimage??? I have been struggling to do it. I don't think that there is a method written explicitly for clearing an image.
I would appreciate any response.
thanks,
Nilesh
|
|
|
|
 |
|
 |
You can do by implement this function as follow...
void CPictureCtrl::FreeImage()
{
FreeData();
Graphics graphics( GetDC()->GetSafeHdc() );
graphics.Clear(Color::WhiteSmoke); // or any other color ; see Gdiplus..
}
Cheers
|
|
|
|
 |
|
 |
This CPictureCtrl is great!
What about the new version with ratio management ^^
Whatever, thanks for it
|
|
|
|
 |
|
 |
use this lines of code on DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
// clear the control first
Graphics graphics( GetDC()->GetSafeHdc() );
graphics.Clear(Color::White);
// scale and draw the picture
int nHeight = (rc.bottom-rc.top);
int nWidth = (rc.right-rc.left);
double XScale = (double) nWidth / (double)image.GetWidth();
double YScale = (double) nHeight / (double)image.GetHeight();
double Scale;
if ( XScale < YScale )
Scale = XScale;
else
Scale = YScale;
nHeight = image.GetHeight() * Scale;
nWidth = image.GetWidth() * Scale;
graphics.DrawImage(&image, (INT)rc.left, (INT)rc.top, (INT)nWidth, (INT) nHeight );
Have fun
|
|
|
|
 |
|
 |
hi,
the project is not showing any error but not showing image also.
the style of Static control is set in your code
void CPictureCtrl::PreSubclassWindow()
{
CStatic::PreSubclassWindow();
ModifyStyle(0, SS_OWNERDRAW);
}
is there any more setting for control from resource editor
pl. explain
modified on Thursday, October 16, 2008 8:13 AM
|
|
|
|
 |
|
 |
Hi,
yes, there is. In the Resourceeditor is a propertie called "OwnerDrawn". This must also be set to "true". (at least there is with Visual Studio 2005 xD)
|
|
|
|
 |