|
Well, you could always send a registered message to your parent window and it can respond with a different return value depending upon which one it is.
Or, you can set a global variable containing the parent window's 'type when the parent is created and then the child can read it.
Or you can use GetParent and then call RealGetWindowClass.
There are other ways, but these came to mind pretty quickly.
|
|
|
|
|
CString str;
GetParent()->GetWindowText(str);
TOXCCT >>> GEII power [VisualCalc] | [toxcct]
|
|
|
|
|
|
There are two threads:
//thread_one:
{
HANDLE hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
SetEvent(hEvent);
// do sth
// ...
AfxBeginThread(thread_two,this);
WaitForSingleObject(hEvent,INFINITE);
// continue to do sth...
}
thread_two:
{
ResetEvent(hEvent);
// do sth
// ...
SetEvent(hEvent);
}
I want thread_one to wait at WaitForSingleObject until thread_two passing SetEvent.
But the fact is thread_one wait at WaitForSingleObject for ever!!
|
|
|
|
|
After CreateEvent the only place you need to do anything with the event is at the end of thread_two. Remove the SetEvent in thread_one and ResetEvent in thread_two. Also make sure that the SetEvent in thread_two really sets the event that the WaitForSingleObject is waiting for. Mind local variable scope. I.e. if you have and event handle in your class called hEvent, and you do:
HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
the class (or object really) hEvent (having the same name as above) will not be set and the WaitForSingleObject will wait for a non-initialized event, thus holding execution indefinitely.
Hope this helps.
|
|
|
|
|
The reason I call ReSetEvent is that WaitForSingleObject at thread_one is not always waiting for when thread_two sets the event, so I set the event to nonsignaled state by using ReSetEvent to make sure thread_one should wait at WaitForSingleObject when thread_two is running.
What's wrong with the ReSetEvent function I called could cause 'waiting for ever' ?
BTW. Assume there is no variable scope problem.
Thanks
|
|
|
|
|
Theres no problem per se. But the first reason thread_one is not waiting is because of the SetEvent (after the CreateEvent method). This means that when you get to the WaitForSingleObject, it will just continue right on. So as I said, you should remove it.
The second reason is multithreading. When you start thread_two, don't assume that the ResetEvent in thread_two will get executed before you get to the WaitForSingleObject in thread_one (it is less probable than not that that will ever happen). So this is why thread_one does not wait sometimes, all at the mercy of Windows thread scheduling.
So, remove the SetEvent in thread_one and the ResetEvent in thread_two (optionally of course, because it doesn't do anything) and the code as it stands should work A OK.
|
|
|
|
|
Thanks for help.
But I found sth strange.
When thread_one is waiting at WaitForSingleObject() and at the same time thread_two was also suspended instead of running as I supposed before.
I use a counter in thread_two to caculated how many steps passed by when thread_one is waiting for it, but the fact is that the counter remains the same between WaitForSingleObject(hEvent,1000); that is to say thread_two was suspended when thread_one call WaitForSingleObject, but why????
|
|
|
|
|
That does indeed sound strange. Are you linking with the multithreaded runtime libraries? Because that kind of odd behavior could arise from linking with the single threaded ones.
|
|
|
|
|
Your hEvent in Thread one is a local variable which never gets set. Make it a class member or a global variable and then set that global variable from outside thread one.
Stuck to Programming through an unbreakable bond
My Articles
|
|
|
|
|
How to save the bmp file?
the data is YUYV format.
Give me a sample ,thanks !
could I first convert the data from YUV format to RGB format?
.
|
|
|
|
|
http://www.codeproject.com/bitmap/[^]
Articles:
CxImage // LARGE: handles multiple images formats
CDibData // SMALL: load, save, access (NEEDS UPDATING)
CDIBsectionLite // SMALL: load, save, access
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
hi, i was developing a plug-in for IE regarding image. I'm looking for event handler which will get fired whenever a image is found, or downloaded/loaded, or by user's command.(e.g. by IE itself will display email to fren etc whenever u right click on a image, and only on a image)
may be i can make use of DWebBrowserEvent2 , e.g. BeforeNavigate2,DownloadBegin,DownComplate etc, but how to i specify it so it only works to a image file ?
any help is much appreciated, thx a lot
|
|
|
|
|
Hi All,
I am fairly new to C++ (but don't hold that against me) and I am trying to manually load a 32-bit bitmap into memory from a file. By manually I mean reading each structure (BITMAPFILEHEADER, BITMAPINFOHEADER, etc.) and bitmap bits using ReadFile. I am pretty confused about how the bitmap bits are stored... are they stored BGR or RGB? and where is the alpha bit stored? If after reading the bits into memory and have an UCHAR* to the bits, how do I extract the blue, green, red and alpha color intensities?
Thanks.
Robert
|
|
|
|
|
I have a simple MFC custom control which extends CWnd.
It has a CButton member, nothing more.
I want to create the Custom control at run time in my main dialog (i.e. Without using Resource editor)
And I want to use the following code in the OnInitDialog() to create the Custom control at run time:
m_MyCustomControl.Create(...);
It sounds simple, but I was failed to do it. Can somebody try out it or gives me some help?
|
|
|
|
|
Hey! I've been floating around in here for a while now, doing my thing, helping out where I can. Now I got another request from you all. I need/want to assign an icon to my CMD-LINE programs. I know it can be done, the guys over at FoundStone do it all the time. Requesting suggestions and/or code from you all.
Cheers!
|
|
|
|
|
Simply add an icon resource to your .exe. Visual Studio does not automatically create resources and icons for console apps, as it does with dialog based ones, which is why the have no icon by default.
Windows uses the first icon in the resources as the app icon by default.
Cheers,
Nick
|
|
|
|
|
Background: I have a standard win32 application. The application doesn't have a user interface and behaves somewhat like a service. However I can't run it as a service because I sometimes need to use the desktop.
I need to make sure that my program exists gracefully on any error. I need to illiminate absolutely all error message boxes like "Runtime error" "Abnormal termination" message boxes. How can this be done??
|
|
|
|
|
To begin use
try
{
}
catch(...)
{
}
or catch every error you might know
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
I've used the catch(...) but that doesn't garantee that "Runtime Error! .... This application has requested the Runtime to terminate it in an unusual way." message box doesn't show up.
|
|
|
|
|
>>However I can't run it as a service because I sometimes need to use the desktop.
You can make a service to display user interfaces and receive user inputs by setting SERVICE_INTERACTIVE_PROCESS attribute of a service.
There is no spoon.
suhredayan
|
|
|
|
|
Hello,
Does anyone know where to find a reference to a large calendar control? I would like it to look more like a standard wall-hanging calendar (not the date picker in MFC) in which I'll write/paint words and icons and colors.
thanks in advance,
JennyP
|
|
|
|
|
This is tne final step in my program and I cannot figure it out. Where do I enter the line with the slashes next to them? I changed the number to amount in the program. In the posoiton they are in I get 19 errors.Below is what was given:
string input;
int number;
int pos = input.find(',');
while (pos != -1)
{
////input.replace(pos, 1, "");
////pos = input.find(',');
}
number = atoi(input.c_str());
cout << number<< endl;
This is what I done.
int main()
{
int c;
float fee;
double total;
char a ='y', ans;
////string input;
//// int amount;
while(a =='y'|| a =='Y')
{
cout << "\nChoose from options below.\n";
cout << "\nEnter A to calculate total RWA cost.\n";
cout << "\nEnter B to calculate RWA base estimate.\n";
cout << "\n\t\tEnter your choice, then press the enter key:";
cin >> ans;
cin.ignore();
if (ans == 'A' || ans == 'a' ){
cout << "\nEnter RWA Base Estimate, then press the enter key:$";
cin >> amount;
////int pos = input.find(',');
////while (pos != -1)
////{
////input.replace(pos, 1, "");
////pos = input.find(',');
////}
////amount = atoi(input.c_str());
////cout << amount<< endl;
cout << fixed;
cout.precision(2);
fee = amount * 0.04;
cout << "4% Management Fee:$" << fee <<"\n";
total = amount + fee;
cout << fixed;
cout.precision(2);
cout << "Total:$" << total <<"\n";
|
|
|
|
|
You have everything in the correct place. Just change the line
cin >> amount; to
cin >> input;
I ran the code as posted here (added missing closing braces) and it ran fine.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
hi
I want to know how to extract element symbols using recursion from string like "4H2SO4". Also tell me how to learn recursion and string manipulation "some good books".
|
|
|
|