|
Hi,
I am trying to use a Dialog as a Control in another Dialog. MFC Documentation vaguely suggests this as something that can be done (you can set the 'Control' Property in the dialog you want to use as source. The help files and examples become 'thin on the ground' when it comes to how to actually do this. Anybody any ideas?
Bram van Kampen
|
|
|
|
|
I do this a lot in one of my older applications. Suppose your two dialogs are IDD_MAIN and IDD_SUB, with corresponding MFC classes CMainDlg and CSubDlg. The resource for the sub dialog should have the following styles set: Border=None, Style=Child, and Control=True. This will let the sub dialog visually blend into the main dialog.
The basic approach is to use the sub as a modeless dialog whose parent is the main dialog. You then need something like this to get it going:
BOOL CMainDlg::OnInitDialog()
{
CSubDlg *sub = new CSubDlg(CSubDlg::IDD,this);
sub->Create(CSubDlg::IDD,this);
sub->MoveWindow(10,10,100,100);
sub->ShowWindow(SW_SHOW);
} Obviously, there are lots of ways this needs to be fancied up. You probably want this sub-dialog positioned relative to other controls. What I usually do is place a static control where I want the sub-dialog to go, and then position the sub-dialog using logic like this:
CSubDlg *sub = new CSubDlg(CSubDlg::IDD,this);
sub->Create(CSubDlg::IDD,this);
CRect sub_rect;
GetDlgItem(IDC_SUB_DIALOG)->GetWindowRect(&sub_rect);
ScreenToClient(&sub_rect);
GetDlgItem(IDC_SUB_DIALOG)->DestroyWindow();
sub->SetDlgCtrlID(IDC_SUB_DIALOG);
sub->MoveWindow(&sub_rect);
This logic does several things: it gets the position of the static control, destroys it, and then places the sub dialog in the same position. As a final refinement, it assigns the control ID to the sub dialog.
Note that, for completeness, you really should save the pointer to the sub dialog instance as a member of the main dialog class, and delete it in that class' PostNcDestroy().
|
|
|
|
|
|
Glad to be of help .
|
|
|
|
|
Hi! I have to do a project for my studies. It is a insertion algorithm.
I'm reading data from file with using vector.
then I'm copying vector to a normal array (the reason is simple: I don't know how to send vector to function, but this is not a main problem).
After copying, I'm sending (with using pointers) array to sorting function.
Everything is good, algorithm is working but! (yep, there is always but...
When I save a lot of data to file, program just after start crashes.
The numbers in file are written in that way:
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
So there are 40 numbers in one line. I have 4.000 lines, so after simple math we have 160.000 numbers. The main problem: when I add some new numbers for example 40.000 program crashes
I must have more numbers because the task is to compare few sorting algorithms with minimum 15 minutes of sorting. (160.000 digits is sorting in ~1 minute)
Here's the code. Maybe it is poor written, but I did my best.
#include <QtCore/QCoreApplication>
#include <iostream>
#include <time.h>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
void insertion_sort(int *wsk, unsigned long size);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
vector <int> array_vector;
ifstream plik ("numbers.txt",ios::in);
unsigned long single_number;
while(plik >> single_number)
{
array_vector.push_back(single_number);
}
int array_nonsorted[array_vector.size()];
for (unsigned long a = 0; a < array_vector.size(); a++)
{
array_nonsorted[a] = array_vector[a];
}
time_t start,end; double long dif;
cout << "START\n";
time(&start);
insertion_sort(array_nonsorted,array_vector.size());
time(&end);
cout << "STOP\n";
dif = difftime(end,start);
cout << "Array sorted in " << setprecision(5) << dif << "sec"; dif = dif/60; cout << " = " << dif << "minutes";
return a.exec();
}
void insertion_sort(int *wsk, unsigned long size)
{
int tab_sorted[size];
for(unsigned long i = 0; i < size; i++)
{
tab_sorted[i] = wsk[i];
}
for (unsigned long a = 1; a < size; a++)
{
if (a == 1)
{
if (tab_sorted[0] > tab_sorted[1])
{
unsigned long temp = tab_sorted[0];
tab_sorted[0] = tab_sorted[1];
tab_sorted[1] = temp;
}
}
else
{
for (unsigned long b = 0; b <= a-1; b++)
{
if (tab_sorted[a] < tab_sorted[b])
{
unsigned long temp = tab_sorted[a];
for (unsigned long c = a; c > b; c--)
{
tab_sorted[c] = tab_sorted[c-1];
}
tab_sorted[b] = temp;
}
}
}
}
}
So why the program crashes? I don't have a clue Something with memory (but I have 3.0GB and OS works normally when program is starting). Please help!
Luk.
|
|
|
|
|
Have you built a debug version and used the debugger to see where it crashes? That's what I'd to as a starting point.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
hmm, I didn't thought about this, because algorithm works fine, but I did it as you said, and just after debugger started error message came out
<br />
Process stoped. Process was stopped because it received signal from operating system.<br />
Name of signal :SIGSEGV<br />
Meaning of singal : Segmentation fault<br />
Now it is coming to be more interesting.....
I can only click <ok>. After click nothing happened. Even debugging is still on, but do nothing.
I read about SIGSEGV on wiki, but how to avoid it?
|
|
|
|
|
Sounds like you have a wild pointer somewhere. Or have managed to corrupt the heap.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Maybe someone in the future will be searching solution for similar problem so I wrote it here.
So the problem is with stack array. Array is so large that it overflows the stack.
Solution is to use dynamically sized array. It can be vector class. In this example, it is sufficient to send pointer to function and in the sorting function working on vector. That's all.
//
Thanks to helios for helping me out
(from other cplusplus forum)
|
|
|
|
|
vonpik wrote: int array_nonsorted[array_vector.size()];
1.2MB in size, perhaps?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
No, exact size doesn't matter. Just more than approximately 400.000 numbers.
|
|
|
|
|
You missed my subtlty. If you have 160,000 numbers and each is 4 bytes in size, that would require 1.28MB of stack space, obviously more than the default size of 1MB. Using the stack, I'd be surprised if you could get any more than 130,000 numbers.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
So, you are saying that default and maximum size of stack size is 1 MB?
I solved this problem with using vector, but still I want to know a C++ mechanisms
|
|
|
|
|
vonpik wrote: So, you are saying that default...size of stack size is 1 MB?
Yes.
vonpik wrote: I solved this problem with using vector,
Which gets its memory from the heap, not the stack.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I've been trying to use the Boost serialization library to make some data persistent. Nothing particularly fancy but I have some objects from the wxWidgets library included. What a PITA!
Ok, I admit I may be a bit late to the party. I've dabbled a little with my own template classes over the years but nothing extensive as I've just not had the need. So I'm not nearly as facile with them as I am with the rest of the language.
But when the compiler generates an error on a template, it would be nice if it gave you a half way decipherable description of the real problem. It also appears that the compiler doesn't even parse some of the stuff in the template declarations until it actually decides to instantiate it. You're down to one error in the compile and think you've got it knocked and her comes another cascade of a page of errors. Or actually one more error with a page of crap not telling you what's wrong.
The Boost serialization library, IMNSHO, needs considerably more documentation and more extensive examples.
Thanks, I needed that.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
...to the jungle.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Finally! Guess I missed a const declaration on one of the templated member functions. Maybe if it had told me it had problems converting beteen const T& and T& rather than const T and T& or something like that, I might have tumbled to it. And left out some of the other garbage along the way. I guess the moral of the story is to unit test templated classes or classes with templated functions incrementally as you go and make sure they each work before you barge ahead because the compiler said everything is ok. Guess when I noticed that it wasn't warning me about an unused parameter, I should have been suspicious that it didn't really care.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You're seeing one of the fundamental defects in programming with templates. Implementing them to the standard is just so freaking complicated that compiler designers don't seem to be able to issue decent diagnostics for them. The point at which they detect problems is so far removed from the original source that they can't associate the two. VC6 was notoriously bad about it (its template support was incomplete), and VS2003 wasn't a whole lot better.
My main source of never-ending grief is ">>" versus ">{space}>". In some cases, the compiler will handle the first token as a shift operator, in others it's the tail end of a templated argument to a template.
One issue with Boost is that it's pretty much all-or-nothing. Most of the Boost libraries do not like to be mixed with other libraries such as MFC or ATL. I've successfully used Boost.RegEx in an MFC app, but that's it. I would imagine Boost requires that your wxWidget objects have certain Boost-specified characteristics, and they don't. You might need to encapsulate them in your own objects for serialization purposes.
|
|
|
|
|
Gary R. Wheeler wrote: Implementing them to the standard is just so freaking complicated that compiler designers don't seem to be able to issue decent diagnostics for them. The point at which they detect problems is so far removed from the original source that they can't associate the two.
I think that's a big reason I sat on the bench about them for so long. When I played with them in the past, I didn't really need them so it was more of an academic exercise. Then I just got frustrated with them and bagged it. I'm using VC++ 20008 now and it doesn't choke as much but diagnostics aren't much better.
Gary R. Wheeler wrote: My main source of never-ending grief is ">>" versus ">{space}>".
I got bit on that one early and now, if I'm on my game, remember to look for it. Part of the whole finicky somewhat arcane notation which has to be just so or you're scratching your head again about compiler errors.
Gary R. Wheeler wrote: Most of the Boost libraries do not like to be mixed with other libraries such as MFC or ATL.
Gary R. Wheeler wrote: I would imagine Boost requires that your wxWidget objects have certain Boost-specified characteristics, and they don't. You might need to encapsulate them in your own objects for serialization purposes.
Yes, ran into that one but fortunately so far I'm only serializing two, wxColor and wxString. I first tried deriving serializable classes from them but ran into problems. Now I just have a data container to shadow wxColor and create an instance to do the serialization at the point it's needed. For wxString, I convert it to an std::string and go from there. I'm sure as time goes on, I'll be building up the repetoire but that's a bridge that can be double crossed later. On top of that, I'm using OpenCV, too, with its own set of simple primitives but since it's a C API, it will be a bit easier as the data is public for most of it.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi all,
i want to set service center number so i m using AT+CSCA command.
AT+CSCA="Service center no",145
but its not set succssfully,return a string with addition of ERROR.
but in some mobiles its working fine.
please help me for this.
|
|
|
|
|
I am using c++. In one method (subroutine) I need to implement three independent random number generators. I do not know how to isolate them from each other. I am using a subroutine ran1(ikum) from Numerical Recipes. I other words, the seed of the random generator must be independent.
Thanks
|
|
|
|
|
Here it is
int rand1()
{
srand(time(NULL));
return rand() % 100 + 11;
}
Now similarly u can create a few other one srand(time(NULL)) will generate different sequence on startup.
Just refer
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks a lot.
In fact, I have to generate three indenpendent random numbers with the same for loop.
For (int i=0;i
|
|
|
|
|
Just check this.
int rand1( int nData)
{
return rand() % 100 + nData;
}
int main(int argc, char *argv[])
{
int Temp;
srand(time(NULL));
for( int i = 0; i< 11; i++)
{
Temp = rand1(1) ;
cout<<"Num1=="<<temp<<endl;
temp="rand1(2);
" cout<<"num2="="<<Temp<<endl;
" cout<<"num3="="<<Temp<<endl;
" }
="" return="" 0;
}
<div="" class="signature">Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks.
I am using a different random number generator which generates a normal distribution of a random number generator - N(0,1). This function is from a book called: Numerical Recipes.
When I call it, I call gasdev(int &idum); For example: t=time[i]+sd_error*gasdev(int &idum);
In one subroutine, I need to call gasdev(int &idum) three times, but I want each time it is independent.
int idum1=-1;
int idum2=-1;
int idum3=-1;
//
date=time[i]+t_sd_error*gasdev(idum1);
money=t_sd_error*gasdev(idum2);
force=force_sd_error*gasdev(idum3);
date, money, and force are totally independent variables. Do you think I am OK to make the three calls independent with above idum1, idum2, and idum3 ?
Here is it:
//
double C_procDlg::ran1(int &idum)
{
const int IA=16807,IM=2147483647,IQ=127773,IR=2836,NTAB=32;
const int NDIV=(1+(IM-1)/NTAB);
const double EPS=3.0e-16,AM=1.0/IM,RNMX=(1.0-EPS);
static int iy=0;
static int iv[100];
int j,k;
double temp;
if (idum<=0||!iy) { //initialize
if(-idum<1) idum=1;
else idum=-idum;
for(j=NTAB+7;j>=0;j--){
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if(idum<0) idum+=IM;
if(j<NTAB) iv[j]=idum;
//
}
iy=iv[0];
}
k=idum/IQ;
idum=IA*(idum-k*IQ)-IR*k;
if (idum<0) idum+=IM;
j=iy/NDIV;
iy=iv[j];
iv[j]=idum;
if((temp=AM*iy)>RNMX) return RNMX;
else return temp;
}
//
double CBlast_vib_procDlg::gasdev(int &idum)
{
static int iset=0;
static double gset;
double fac,rsq,v1,v2;
//
if(idum<0) iset=0;
if (iset==0){
do{
v1=2.0*ran1(idum)-1.0;
v2=2.0*ran1(idum)-1.0;
//
rsq=v1*v1+v2*v2;
}
while(rsq>=1.0||rsq==0.0);
fac=sqrt(-2.0*log(rsq)/rsq);
gset=v1*fac;
iset=1;
return v2*fac;
}
else{iset=0;
return gset;
}}
modified on Saturday, April 10, 2010 1:58 AM
|
|
|
|
|