|
Maybe Rex Fong's Thumbnail Picture Control[^] could be a good starting point.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In a UI thread..
I was wondering if I am doing this correctly... In run() I call a function.. at the end of that function I call AfxEndThread(0,TRUE); Is this what I am supposed to do to close the thread from with-in it's self? If I do it this way how can I tell if ExitInstance() is being called?
BOOL CMyThread::InitInstance()
{
return TRUE;
}
int CMyThread::Run()
{
SomeFunction();
return CWinThread::Run();
}
void CMyThread::SomeFunction()
{
AfxEndThread(0,TRUE);
}
int CMyThread::ExitInstance()
{
return CWinThread::ExitInstance();
}
Thanks!
Rob
|
|
|
|
|
I think UI is the wrong thread model to use it here, and probably you're better off launching a worker thread. CWinThread::Run is almost never overriden, as it implements by default a message pump: UI threads are expected to do whatever stuff they're required in message handlers just the same way as regular CWnd objects in the main thread. If all you want to do is run some task involving no UI and then exit, use a worker thread like this:
UINT SomeFunction()
{
}
...
AfxBeginThread(SomeFunction,NULL);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I use winsockets in my UI thread.. I need the message pump (I think).. Should I call the SomeFunction() in my OnInit instead of run? If so whats the best way to have the thread self terminate?
|
|
|
|
|
Yes, CSocket s need to be used inside UI threads, but your approach won't work (IMHO) for the following reason: if all the processing is to be done inside SomeFunction (as it seems your intention since you mean to terminate the thread when SomeFunction exits), the message pump implemented by the thread won't have a chance to process any message, thus CSocket s just won't do anything.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have a server setup like this already and everything seems to be working fine.. listening, accepting, sending, receiving etc.. It's a little more complicated that what I posted.. I was basically just wondering how to close the thread properly so that all my clean up code runs on the ExitInstance()..
I have read that AfxEndThread is the way to go and I have also read that you are not supposed to use it.. I'm just a little confused.
|
|
|
|
|
Well, if you say your scheme is working, I guess I'm missing something Anyway, AfxEndThread is the perfect way to end the thread. ExitInstance should be called: to make sure, just put a breakpoint there and check it out.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for taking the time to respond
I really appreciate it.
Rob
|
|
|
|
|
Wait wait. Seems I've given advice too carelessly. After googling around, the subject is not entirely clear to me either. My (tentative) conclusion is that AfxEndThread should be called if CWinThread::Run has not run yet (i.e. in InitInstance ) and PostQuitMessage should be called otherwise. I think this could be ascertained by looking at the source code for CWinThread , alas I don't have it handy right now. I'll check it out tomorrow morning (CET). Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have an application running on a different virtual desktop than the default one. Somehow, I need to open a browser on the default virtual desktop to a URL.
I can get a handle to the default desktop by doing this:
HDESK hdesk = OpenDesktop("default",0,FALSE,DESKTOP_ENUMERATE);
if( hdesk )
{
CloseDesktop(hdesk);
} I'm wondering if there is something I can do with hdesk to accomplish this. Or if there is another method that might work better (short of writing a desktop taskbar tray application, and posting a custom message to it)?
Any ideas appreciated!
|
|
|
|
|
Not sure if this will work but you could try..
ShellExecute(hDesk->GetSafeHwnd(),NULL,"www.yahoo.com",NULL,NULL,SW_SHOW);
Rob
|
|
|
|
|
Hi all.
I'm working on a large project that does two things I wouldn't do, it if were up to me:
1 -- Radio buttons remain enabled even when conditions exist that prevent the selection of the corresponding option
2 -- When users select an enabled radio button and the corresponding option is not available, a message box is genereated from within the radio button handler, informing the user that he/she cannot make that choice. After this, selection is returned to the previous radio button.
Although non-standard, this works fine when the user CLICKS the radio button in question. If, however, the user uses an arrow key to move from an adjacent radio button, the action sets off a recursive loop. Strangely, this loop repeats a limited number of times (14, in the case I'm working on).
Using breakpoints to step through the code, I can see that the flow goes directly from the dismissal of the message box to the top of the radio button handler, without executing the rest of the handler code. The recursion has nothing to do with the code that re-selects the previous radio button.
Again -- this happens ONLY when using an arrow key to select the radio button. It does NOT happen with a mouse click on the radio button.
Any ideas on what is causing this, or how I can prevent it?
Thanks!
David
|
|
|
|
|
Hmmmm, I find it tough to decipher what's causing the problem without looking at your code. Any chance you can post it?
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
|
|
|
|
|
I just tried out your scenario on a "doodle" dialog box I have and amazingly was able to reproduce your problem exactly! .
I don't have an answer as to why it's happening, but my guess is that it has to do with the fact that when you use the arrow key the focus is also changed and that also causes the handler to be called. After you click OK on the message box, the focus goes back to the radio button and it causes the handler to be called again...
Anyway, the way I fixed it is:
void CDoodleDlg::OnRadio2()
{
UpdateData();
if (m_nRadioTest == 1)
{
m_nRadioTest = 0;
UpdateData(FALSE);
MessageBox("Hey, isn't it obvious that you shouldn't click on Radio 2?");
}
}
Note that I assigned m_nRadioTest inside the Class Wizard for Radio1 and Radio2 (which are grouped together).
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
|
|
|
|
|
Hi Alvaro.
Thanks! You put me on the right track.
I had already tried returning the button selection before popping the message, but your example reminded me that the established routine for this resets the "check" without using a member variable for the radio button group (ah, legacy code!). When I do it your way, the handler repeats once, but not recursively, so I can use a static variable and GetTickCount() to filter out the second call. Kludgy, but it will do.
At least three good-karma credits for you!
David
|
|
|
|
|
Can anyone tell me how to go about resizing a static control according to text size dynamically? Thanks in advance...btw using SDK and not MFC.
|
|
|
|
|
Use DrawText() with DT_CALCRECT to determine the required dimensions.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I have about 20 property pages in a property sheet. They
all just look like a long line of property pages, but it
cuts off the 17th page and the scrolling just doesn't appear on the screen. I tried almost everything to get it to stack the property pages or scroll to see the other pages. Nothing works. Any ideas? Any code?
Please, any response any one can give me will be greatly appreciated.
|
|
|
|
|
DanYELL wrote:
I have about 20 property pages in a property sheet.
My condolences to your poor users
Your incessant rantings indicate you have a brain the size of a pea, and the mental capacity of a bag of hammers. - John Simmons
|
|
|
|
|
I strongly urge you to not use a property sheet. Instead use Chris Losinger's SAPrefs[^] class.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
Hi, I am not good at programming. So, I hope somebody can help me to solve my problem. I already think it for a long time.
My question is I have 2 set of datas. They are stored in variable no[i] and result[i].
no[0]=0.12 result[0]=medium
no[1]=0.27 result[1]=medium
no[2]=0.67 result[2]=short
no[3]=0.43 result[3]=medium
no[4]=0.98 result[4]=high
no[i] and result[i] will combined together( i.e. 0.12 medium, 0.27 medium....)
And my expected result is "0.12medium, 0.67 short and 0.98 high."
How can I program it such that the computer know there have a three type of data, medium, short and high respectively.
The question is so long!!!
Thank you very much!!!
|
|
|
|
|
I would declare an enumeration in one of your header files that the "result" set can see the enumeration like this:
enum {short = 1, medium = 2, long = 3};
Then you can use that code in your array. When you need to make your combined string or output, you will just need to decode a 1 to mean "short", 2 for "medium" and 3 for "high".
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
As has been said, an enum is the obvious answer. The other thing is that if your two values are really one complex type, declare it as such with a struct.
enum Result {short, medium, long}; // can use short = 0, medium =1, etc. with whatever values you want, but unless you use the values directly, it does not really matter what they are and they should be 0, 1, 2 by default.
struct myType
{
float no;
Result result;
}
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
In an MDI application ( well, not really, it's an MDI with only 1 "view" definition )
On my mouse move, I need to hilight items in the view, so I can either draw in the ON_WM_MOUSEMOVE ( in the CView derived class ), or mark item to be drawn, and wait till an Invalidate (WM_PAINT to trigger the OnDraw of the view )comes in to draw it ?
Now, if I want to highlight the item in all the views (frames ? ), with the first option, I'd have to call the Document UpdateAllViews( this ) ( this is the current view ) ?
Ok, I think I get it, the UpdateAllViews call an update on the DIFFERENT views, not the same VIEW in different FRAMES ... Is there a better way to loop true the different "frames" than with a loop on CWnd and check for CWnd::GetWindow(GW_CHILD) ?
and I had a check somewhere that checked only the active view !
And now it's working ... I started writting this 2 hours ago ...
Max.
|
|
|
|
|