|
Sorry, but I have to say I do not know the best method to do this.
But this is what i can think of.
Create a CMetaFileDC.
Call PlayMetaFile on this dc.
Write all the stuff from the legend using GDI functions.
Save Metafile to a disk file
Reload the metafile to clipboard.
There may be a better way to get the metafile data to clipboard from the DC though. This is all I could come up with instantly
Thomas
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
thanx. I'll let you know what I come up with if you're interested...
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
|
I hope someone can figure this one out for me!
I have a simple function that takes 400 double values and graphs them in the client area. I run this about 25 times per second to give 25 FPS. This works fine however it uses up all the memory in my computer after about ten minutes!!! In the "Windows Task Manager" the mem usage just keeps increasing until my computer crashes. I'm sure it is this function that is causing the problem because when I leave it out this doesn't happen.
Any ideas?
void function3 (HWND hwnd, double a[], int iLength)
{
HDC hdc;
PAINTSTRUCT ps;
int i;
hdc = GetDC(hwnd);
Rectangle(hdc, 0, 0, 400, 256);
MoveToEx(hdc, 0, 256, NULL);
for (i=1; i< 400; i = i++)
{
int p = (int)a[i];
LineTo(hdc, i, 255-p);
}
EndPaint (hwnd, &ps) ;
}
Thanks in advance,
Paddy
|
|
|
|
|
Paddy wrote:
hdc = GetDC(hwnd);
You have to call ReleaseDC() if you've called GetDC()
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Thanks thats makes a big difference, I'm only losing a couple of Kb per minute now.
|
|
|
|
|
Paddy wrote:
void function3 (HWND hwnd, double a[], int iLength)
{
How often do you call this fcn? the double a[] with no bounds checking seems kinda shady... If I can recall, every time you call this fcn, you will make a copy of a[]. I would get the for loop out of this fcn, and pass a as a const reference. Also, why even use a double if you're casting to int And also, where do you set the size of a[]? I'm not a guru, but the whole thing looks a little shady.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I'm calling this function about 25 times per second, I know the code is a bit of a mess but I'm just worried about the increasing memory problem. I have included ReleaseDC(hwnd, hdc); now and it has made a significant difference but I'm still losing a bit of memory! I can't actually get rid of the for loop because I'm using this to draw lines between each point on the graph.
Thanks for the help.
|
|
|
|
|
Try:
void function3 (HWND hwnd, <code>double& a[400]</code>, int iLength)
{
HDC hdc;
PAINTSTRUCT ps;
int i <code>= 0</code>;
hdc = GetDC(hwnd);
Rectangle(hdc, 0, 0, 400, 256);
MoveToEx(hdc, 0, 256, NULL);
for (i=1; i< 400; <code>i++</code>) <code>
{
<code>
<code>LineTo(hdc, i, (255 - static_cast<int>(a[i]));</code>
}
EndPaint (hwnd, &ps) ;
}
It may not solve all the memory issues, but may speed you up some and maybe ease it a little.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Thanks I have it fixed now, there was another part in my app where I was creating a colored pen over and over again using
hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
and not deleting it when I was finished. Just stuck in
DeleteObject(hPen);
and it's all sorted now!
Thanks for the help,
Paddy
|
|
|
|
|
My product MemWatcher[^] will help identify if you're leaking resources.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I am using C++ Builder and want to create a window like the propertis windows in Visual Basic or the Object Inspector in C++ Builder. Thanks!
|
|
|
|
|
Hi All,
A brief about the prob I am facing. We have a dialog being displayed (has got property pages)... In one particular property page.. we have 2 radio buttons... (other controls not in question)... we display a dialog whenever the user tries to change the selection of the radio control. Say from "radio1" to "radio2"... It's basically a simple Yes/No question messagebox. If the the user selects "yes" the user is allowed to select the other radio button, otherwise not.
"radio1" is selected by default. User changes to radio2. after selection... dialog appears (asking for confirmation). If the user says "yes" then we continue as it is, otherwise we progra-matically restore the first radio controls state (selected=true) by setting m_nFirstRadio=1. this is the variable controlling the state of these two controls.
We are hadling the OnRadioButton() message handler for both of these controls.
Till now it works perfectly.
but when we change the property page to some other at runtime.. I don't know why.. but the message handler for the radioButton is being called (about 18 times). In effect displaying the conformation dialog about 18 times...
Any idea why this is happening??? I am not calling the OnRadioButton message handler manually. One more thing.. this happens only when the user selects "no".. thus we had to restore the state programatically.
Is there any rule as to when to use the radio button's member variable to change the state...
Regards,
Mohit
|
|
|
|
|
Your are already sitting on the answer.
Your change the state of the other radio buttons manually, therefore you generate
OnRadioButton messages.
As a workaround You could set a flag when You are changing the state of the buttons manually
and check for this flag in the OnRadioButton handler.
Yours,
Alois Kraus
|
|
|
|
|
Hi Alois,
But the message shoudl be generated only once if at all. Since I click on the radio button only once, and then say "no" in the confirmation dialog. So the state is restored. Below is the code in the handlers "Locked" and "UnLocked" both are radio buttons. m_nRadLocked controls the state.
Why the handler is being called 18 times.. and that too when I am changing to a different property page using the tab control.
Somebody told me that this is a BUG with VC++/MFC. And happens when we use AfxMessageBox/and radio buttons. But I really don't think so. So thats why I had mailed the forum.
property page looks somewhat like this:
/----------------------------------------\
| |
| O Locked O Unlocked |
| |
| some other controls ------ |
\----------------------------------------/
void CSDT12ConfigDCCPage::OnRadUnlocked()
{
UpdateData();
// If Board Admin State locked,
// We shoul not allow to change Admin State of Port to Unclocked state
if(((CSDT12ParentDialog*)m_pParent)->GetAdminState() == 1)
{
m_nRadLocked = 0;
UpdateData(FALSE);
}
}
void CSDT12ConfigDCCPage::OnRadLocked()
{
UpdateData();
/* this condition is to avoid the handler to be called un-neccesarily */
/* if this condition is not present.. dialog is called 18 times while */
/* changing property page to another */
if (m_nRadLocked == 0) /* Check if this msg handler is really being called*/
{
if (AfxMessageBox(IDS_SDT12_BOARD_LOCKED_WARNING,
MB_YESNO | MB_DEFBUTTON2 |MB_ICONQUESTION) == IDNO)
{
m_nRadLocked = 1;
UpdateData(FALSE);
}
}
}
Regards,
Mohit
|
|
|
|
|
HI
I have some buttons that I am linking to ShellExecutes, but in this program the parameters to some of the ShellExec are an unknown filename. Also, some of the files to Exec are unknown filenames.
I know the directory and extension of the files I want to exec, but the actual names of the files changes.
Also, there will only be max of one file of each extension to Exec.
If the file does not exist, I want the button to be greyed out.
Does anyone have any insight in how to go about any of this, or what functions to look at? Is there an "anything" character, or is FileFind someplace I should be looking?
Thanks!
|
|
|
|
|
just use ShellExecutes and "open" to "execute" file,windows can lookup register and find proper program to open it
use :
BOOL PathFileExists(
LPCTSTR pszPath
);
to test the does the fileexisted
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
I have the following situation:
Class A:
{
public:
virtual void getValue (float& val) const
{val = 5.0f;}
virtual void getValue(bool& val) const
{ val = true;}
virtual void getValue(string& val) const
{ val= "abcd";}
}
class FloatA: public A
{
public:
virtual void getValue (float& val) const
{val = 10.0f;}
}
class BoolA: public A
{
public:
virtual void getValue (float& val) const
{val = true);
}
I figured out that calling the float function take 20 times time than the bool function !
Any idea ???
Is it the float type (it is happened also with double) ?
Is it the overloading order ?
|
|
|
|
|
bool was prodess as short int
process speed of float is slowly than int
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
|
|
hi
i m makg a windows browser based applction with 2 panes :
left derived from CTreeView and right from CHtmlView.
iwant to access object of CHtml derived class from CleftView
can any hlp me out
|
|
|
|
|
Use their common ancestor (probably it's the MainFrame, or a ChildFrame for MDI apps)
A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a Cathedral[^].
Antoine de Saint-Exupery (1900-1944)
|
|
|
|
|
This is the common case of the document view architecture. In the doc should the data-objects (very good for serialization) and with pointers/interfaces to them you get the data which you can disaply in the views.
PS: Editing and modifying functions are best implemented in the mainframe so EACH view can access them.
Try this @ home. (B&B)
|
|
|
|
|
use global pointer
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|