|
Hi all ,
I want to get the pointer of the document and traverse thr u all views of the document and bring into active state one of those views..How can i do it?I tried using GetFirstDocTemplatePosition() in the CWinApp derived class but its giving me runtime error...What to do??Do help me
|
|
|
|
|
Did you try :
CWinApp *pApp = AfxGetApp();
if(pApp)
{
POSITION pos = pApp->GetFirstDocTemplatePosition();
while(pos != NULL)
{
CDocTemplate *pDocTemplate = pApp->GetNextDocTemplate(pos);
if(pDocTemplate )
{
POSITION pos2 = pDocTemplate->GetFirstDocPosition();
while(pos2 != NULL)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(pos2);
}
}
}
}
the other option, is if you are in a view already,
you can just called GetDocument
CDocument *pDoc = GetDocument();
|
|
|
|
|
Hi,
Thanks for ur interest in helping me.I tried the code u have given but its giving runtime Assertion Errors.Can u send me any working sample which uses these functions?
Thanks
|
|
|
|
|
I don't know if it would work, but you can try searching on:
EnumChildWindows, EnumWindows, ...
these can give you the handle you need.
Note: this will cycle through all windows on your desktop, you'll have to figure out which is which.
Good luck,
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
How to get memory info of a process not using PSAPI
I want to get memory information of a process, include stack, heap, all memory the process used.
My Program must support Win98, Win2000, WinXp,
So I can't depend on PSAPI to do these.
thanks...
|
|
|
|
|
You mean like ReadProcessMemory() , and Process32First() /Process32Next() ? If so, see if this article is of any help.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
use CreateWin32SnapShot() api function a
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
How to improve on Genetic Algorithms by using Fusion operator?
Change the codes please, thank you!
My English is poor
Codes:
#include<iostream.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#define maxgen 500
#define POPSIZE 500
#define PopSize 100
#define kind -2
#define NVARS 9
#define Umin -1
#define Umax 1
#define Cmax 100
#define Cmin 0
double pxover= 0.75;
double pmutation = 0.2;
int gen,j;
int best_val = 0;
double m_A0,m_B0,m_A1,m_B1,m_A2,m_B2;
double A0,A1,A2,A3,A4,B1,B2,B3,B4;
long double x[100],y[100],z[100],a[100];
struct Individual{
double chrom[NVARS];
long double value;
long double fitness;
};
struct Individual population[POPSIZE];
struct Individual bestindividual;
struct Individual currentbest;
#define rd(i) (rand()%(int)(i))
#define rdf() ((float)rd(1000)/(1000.0))
void produce()
{
srand((unsigned)time(NULL));
for(int i=0;i<PopSize;i++)
{
population[i].chrom[0] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[1] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[2] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[3] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[4] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[5] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[6] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[7] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[8] =m_A0 +rdf()*(m_B0-m_A0);
}
for(int j=0;j<100;j++)
{
x[j]=m_A0+rdf()*(m_B0-m_A0);
y[j]=x[j];
}
}
void evaluation()
{
long double l;
l=(m_B0-m_A0)/2;
for(int i=0;i<PopSize;i++){
A0=population[i].chrom[0];
A1=population[i].chrom[1];
B1=population[i].chrom[2];
A2=population[i].chrom[3];
B2=population[i].chrom[4];
A3=population[i].chrom[5];
B3=population[i].chrom[6];
A4=population[i].chrom[7];
B4=population[i].chrom[8];
for(j=0;j<100;j++)
{
z[j]=A0/2+A1*cos(atan(1)*4*x[j]/l)+B1*sin(atan(1)*4*x[j]/l)+A2*cos(atan(1)*8*x[j]/l)+B2*sin(atan(1)*8*x[j]/l)+A3*cos(atan(1)*12*x[j]/l)+B3*sin(atan(1)*12*x[j]/l)+A4*cos(atan(1)*16*x[j]/l)+B4*sin(atan(1)*16*x[j]/l);
//z[j]=A0/2+A1*cos((atan(1)*4*x[j])/l)+B1*sin((atan(1)*4*x[j])/l)+A2*cos((atan(1)*8*x[j])/l)+B2*sin((atan(1)*8*x[j])/l)+A3*cos((atan(1)*12*x[j])/l)+B3*sin((atan(1)*12*x[j])/l)+A4*cos((atan(1)*16*x[j])/l)+B4*sin((atan(1)*16*x[j])/l);
}
for(j=0;j<100;j++)
{
a[j]=0.5*(z[j]-y[j])*(z[j]-y[j]);
population[i].value+=a[j];
}
}
}
void fitness()
{
for(int i=0;i<PopSize;i++)
{
if(kind>0)
{
population[i].fitness = population[i].value-Cmin;
}
else
{
population[i].fitness = Cmax - population[i].value;
}
}
}
void findbest()
{
bestindividual=population[0];
for(int i=1;i<PopSize;i++)
{
if(population[i].fitness > bestindividual.fitness)
{
bestindividual = population[i];
best_val = i;
}
}
if(gen==0)
{
currentbest = bestindividual;
}
else if( currentbest.fitness<bestindividual.fitness)
{
currentbest = bestindividual;
}
}
void select()
{
double cfitness[POPSIZE];
double sum = 0;
double p;
int index=0;
struct Individual newpopulation[POPSIZE];
for(int i=0;i<PopSize;i++)
{
sum +=population[i].fitness;
}
for(i =0;i<PopSize;i++)
{
cfitness[i] = population[i].fitness / sum;
}
for(i=1;i<PopSize;i++)
{
cfitness[i] = cfitness[i-1] + cfitness[i];
}
srand((unsigned)time(NULL));
for(i=0;i<PopSize;i++)
{
p = rdf();
while(p > cfitness[index])
{
index++;
}
newpopulation[i] = population[index];
}
for(i =0;i<PopSize;i++)
{
population[i] = newpopulation[i];
}
}
void crossover()
{
int index[POPSIZE];
int point,temp,i=0;
long double p;
struct Individual newpopulation[POPSIZE];
for(i=0;i<PopSize;i++)
{
index[i] = i;
newpopulation[i] = population[i];
}
srand((unsigned)time(NULL));
for(i=0;i<PopSize;i++)
{
point=(int)rand()/1000;
point+=i;
while(point>=PopSize)
{
point/=2;
}
temp = index[i];
index[i] = index[point];
index[point] = temp;
}
while(i<PopSize-1)
{
for(int j=0;j<NVARS;j++)
{
p = rdf();
if(p<pxover)
{
newpopulation[index[i]].chrom[j]= p*population[index[i+1]].chrom[j] + (1-p)*population[index[i]].chrom[j];
newpopulation[index[i+1]].chrom[j]= p*population[index[i]].chrom[j] + (1-p)*population[index[i+1]].chrom[j];
}
}
i=i+2;
}
for(i=0;i<PopSize;i++)
{
population[i] = newpopulation[i];
}
}
void mutate()
{
int p = 2;
double r;
double ytemp;
double temp;
double T;
double a[NVARS],b[NVARS];
srand((unsigned)time(NULL));
for(int i=0;i<POPSIZE;i++)
{
for(int j=0;j<NVARS;j++)
{
a[0]=m_A0;
b[0]=m_B0;
a[1]=m_A1;
b[1]=m_B1;
a[2]=m_A2;
b[2]=m_B2;
r = rdf()-0.5;
if(r<pmutation)
{
if(r<0)
r = -r;
T = 1-population[i].fitness/100;
if(rand()%2==0)
{
ytemp = b[j]- population[i].chrom[j];
temp = ytemp*( 1-pow(r,pow( T,p)));
population[i].chrom[j] = population[i].chrom[j] + temp;
}
else if(rand()%2==1)
{
ytemp = population[i].chrom[j] - a[j];
temp = ytemp*( 1-pow(r,pow( T,p)));
population[i].chrom[j] = population[i].chrom[j] - temp;
}
}
}
}
}
void replace()
{
if(bestindividual.fitness>currentbest.fitness)
{
currentbest = population[best_val];
}
}
void main()
{
m_A0=-atan(1)*4,m_B0=atan(1)*4;
produce();
cout<<"A0="<<A0<<'\n';
cout<<"A1="<<A1<<'\t'<<"B1="<<B1<<'\n';
cout<<"A2="<<A2<<'\t'<<"B2="<<B2<<'\n';
cout<<"A3="<<A3<<'\t'<<"B3="<<B3<<'\n';
cout<<"A4="<<A4<<'\t'<<"B4="<<B4<<'\n';
for(int i=0;i<maxgen;i++)
{
evaluation();
fitness();
findbest();
select();
crossover();
mutate();
replace();
}
cout<<"m_A0="<<m_A0<<'\t'<<"m_B0="<<m_B0<<'\n';
cout<<bestindividual.fitness<<'\n';
cout<<currentbest.value<<'\n';
cout<<"kind="<<kind<<'\n';
//cout<<"A0="<<population[PopSize-1].chrom[0]<<'\n';
//cout<<"A1="<<population[PopSize-1].chrom[1]<<'\t'<<"B1="<<population[PopSize-1].chrom[2]<<'\n';
//cout<<"A2="<<population[PopSize-1].chrom[3]<<'\t'<<"B2="<<population[PopSize-1].chrom[4]<<'\n';
//cout<<"A3="<<population[PopSize-1].chrom[5]<<'\t'<<"B3="<<population[PopSize-1].chrom[6]<<'\n';
//cout<<"A4="<<population[PopSize-1].chrom[7]<<'\t'<<"B4="<<population[PopSize-1].chrom[8]<<'\n';
cout<<"A0="<<A0<<'\n';
cout<<"A1="<<A1<<'\t'<<"B1="<<B1<<'\n';
cout<<"A2="<<A2<<'\t'<<"B2="<<B2<<'\n';
cout<<"A3="<<A3<<'\t'<<"B3="<<B3<<'\n';
cout<<"A4="<<A4<<'\t'<<"B4="<<B4<<'\n';
//for(int j=0;j<100;j++){
// cout<<x[j]<<'\t'<<y[j]<<'\t'<<z[j]<<'\t';
//}
}
|
|
|
|
|
*shrug* Fusion operator? whats that ?
|
|
|
|
|
It's a kind of operator which can prevent the fuction from converging.
|
|
|
|
|
I want to get the rect's area of the MinimizeBox,MaximizeBox,CloseBox,what should I do?
|
|
|
|
|
You might want to check SystemParametersInfo with the constant SPI_GETNONCLIENTMETRICS .
|
|
|
|
|
|
As far as I'm aware, you can't - that's why it's the 'everything else' clause. Most exceptions derive from std::exception, so if you catch that then you should be covered, but it's a real pain if a library throws an exception you don't handle and isnt documentated. I think if you run the program through a debugger it should tell you the exception.
|
|
|
|
|
I'm not sure, but GetLastError function could help maybe?
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
no, GetLastError() work for the system, not for your own error codes.
if you want to catch an error ans determine which one has been thrown, the throwing function must send a class per exception...
this way, you test the class, and so determine which exception was thrown...
TOXCCT >>> GEII power
|
|
|
|
|
Hi!
i'm used to sending messages from a view class (in mfc), so first i get the window
HWND *viewhandle = new HWND;
*viewhandle = GetSafeHwnd();
copy the viewhandle to a variable of the object, and in a function, when i want to send a message, i call:
::PostMessage(*viewhandle, WM_ONWHATEVER, 0, 0);
That works fine. Now, i want to send a message from a class to another, and there are no windows involved.
I want to do this: class AA includes class BB. And i want to use a function of class AA from class BB, but class BB doesn't see class AA. So i want to send a message
But now i can't use GetSafeHwnd. How could i do that?
thanks!
|
|
|
|
|
First of all you should just be able to do
HWND viewhandle = GetSafeHwnd();
I don't see the need for the "new HWND;" line.
Second. If you want to send a message from one class to another, you will need to have a message loop somewhere to capture the message.
What exactly are you trying to do? Can you not get a pointer to the other object and call a function?
|
|
|
|
|
Yes, the new line was useless.
I can't do
HWND viewhandle = GetSafeHwnd();
it gives me this error: 'GetSafeHwnd' : undeclared identifier
even though i include <afxwin.h>
.
What i'm trying to do is, from an object(O1), with new, create an instance of an object(O2). And from that object(O2), i want to send a message to the O1 so it can delete the O2 which was a member of O1.
|
|
|
|
|
alright,
that sounds a little bizarre. Is the source in O2 running in another thread?
If you call a function O1::SomeFunc()
and it create the object of type O2,
then do you call a function O2::OtherFunc from a function of O1 ??
If so your return value frmo OtherFunc can tell O1 to delete the O2 object.
Otherwise you could post a message to the applications main thread handle, and capture it there, and call a function that tells O1 to delete O2.
|
|
|
|
|
Maybe you can create a custom message && || custom message handler?
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
how could i create a custom message?
|
|
|
|
|
#ifndef WM_LOCK<br />
#define WM_LOCK WM_APP + 0x100<br />
#endif<br />
<br />
#define MY_LOCKMESSAGE(message, memberFxn) \<br />
{ message, 0, 0, 0, AfxSig_lwl, \<br />
(AFX_PMSG)(AFX_PMSGW) \<br />
(static_cast< LRESULT (AFX_MSG_CALL CWinApp::*)(WPARAM, LPARAM) > \<br />
(memberFxn)) },
OK first note, I do not understand everything they did here.
I normally copy/paste a bit and adapt it a little.
The first #indif is a custom message. The #define is a custom message handler. Read first some stuff about messages and handling them before you try to do something!!!!
(WM_APP was last message so + 0x100 if you want another again last message + 0x100 ...)
Good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
|
Hi,
I've got this code for the OnSetcursor function:
BOOL CVentanaPizarra::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
BOOL resultado=TRUE;
if (this->m_MouseManoMover)
{
if (SetCursor(CursorManoMover))
resultado=TRUE;
}
else
resultado = CDialog::OnSetCursor(pWnd, nHitTest, message);
return resultado;
}
the following function changes the boolean which is seen to change the cursor in the abovementioned function.
LONG CVentanaPizarra::MouseManoMoverTrue(WPARAM wParam, LPARAM lParam)
{
this->m_MouseManoMover=true;
return 0;
}
I call this function from a 'CWnd derived' custom control in the dialog (that i use for drawing). The message works, when i click on something on the control , the message is sent, but the OnSetCursor function doesn't get called, perhaps because i'm hovering the mouse over the custom control, and not over the dialog. But the custom control is in the dialog.
Any ideas?
thanks!!
|
|
|
|
|