|
I'm trying to get a handle (no pun) on threads.
I've got a function that calls two functions one after the other then returns. I'd like to multithread it because the functions lock up the UI in my App.
So...Question #1: When multithreading a function are the actions performed in the functions called from that function also performed in the new thread?
Question #2: Whats the easiest way to implement something like this?
Frank
|
|
|
|
|
#1. Yes. The whole function is executed in the new thread, which exits when the function exits. For instance:
DWORD WINAPI MyThread(LPVOID arg){
function1();
function2();
return 0;
}
DWORD dwThreadId;
HANDLE hThread=CreateThread(
NULL,
0,
MyThread,
NULL,
0,
&dwThreadId
);
#2: The code above just answer this. For production level code you'll need some more stuff (to control when the thread exists, for instance) but this piece of code should get you started.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Great! Thanks for the info.
Frank
|
|
|
|
|
I never want any scrollbars to show up in my MDI. Any way? I tried tthe cs but it want realy responsive. MAybe I didnt try enough? ?
Thanks,
ns
|
|
|
|
|
I am going to have to abandon my oh-so-cool MDI approach since I cant get around a movewindow issue which I'll describe in a bit. SO I am thinking SDi. But I need two views. Can an SDI handle two views?
The MDI dilemma:
Four edit boxes are supposed to hug the right edge always, even on resize. SO onsize I did movewindow setting the top y value to 10, 50, etc....
Fine. But if I scroll without resize, and some are off the visible part, then resize, they immediately pop back at 10, 50 etc from the top edge, leaving a big blank space above in the scrolled off portion. No matter whats the visible screen area, they alwyas show up at 10,50 etc from the top, on resize, leaving gaps where they should have been....
Any solution to this? I do like the MDI otherwise. LOts of hard work ahead if SDi wont do two views....
Thanks,
ns
|
|
|
|
|
Not sure exactly haw you are doing your scrolling, but when you do a resize, it seems to me you are not taking the scrolled distance into account when you calculate the new position of the edit controls, you are just simply placing them X distance from the top of your client area.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
The scrollbars come up automatically since my CFormView is too big (by design) for the Client window.
I tried putting the repositioning in the OnScroll event as well, but now its as if theres no scrollability for those controls!!! So my fix is not right. Can I bother you for more hints on how to calculate how much I scrolled and take that into account? I cant quite see what I am to do here. I'd really really appreciate your help,
Thanks,
ns
|
|
|
|
|
My guess is that you are doing something like :
void CMyFormView::OnSize(UINT nType, int cx, int cy)
{
m_MyEditCtrl.MoveWindow(cx - EditCtrlWidth, 50, EditCtrlWidth, EditCtrlHeight);
... in order to place the edit control at the right edge, 50 pixels from the top.
What you have to do is call GetScrollPosition() to figure the scrolling into the calculation
void CMyFormView::OnSize(UINT nType, int cx, int cy)
{
int HScrollDistance = GetScrollPosition().y;
m_MyEditCtrl.MoveWindow(cx - EditCtrlWidth, 50 - HScrollDistance, EditCtrlWidth, EditCtrlHeight);
...
HTH
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
I am totally overwhelmed. I have been so stressed out over this, and was going to do a dialog based app instead of the cool mDI, and this was really distressing. I've tried your solution on one of my boxes and its behaving wonderfully. I wont breathe until I check it out on the whole UI but I am most hopeful!
You have saved my life literally! I am very grateful.
I had looked around for some function like this but it wasnt in the class wizard or in the members of the class CView either...where is it inherited from?
ANother associated question. This has been happening with my editboxes so I have to do something like(to prevent a debug assert). If I dont put your statement inside the if, it debug asserts. If I didnt have an editbox I was checking for, how would I have handled the assert? Which objects GetSafeHWnd would I test? I dont know if this is clear but its something I'd like to know about, if you have any ideas why....
if( NULL != m_editright.GetSafeHwnd() )
{
int VScrollDistance = GetScrollPosition().y;
m_editright.MoveWindow(cx - 200, 50 - VScrollDistance, 200, 200);
// m_editright.MoveWindow(cx-200,360,200, cy-60);
}
Thank you,
ns
|
|
|
|
|
ns wrote:
where is it inherited from?
CObject
-CCmdTarget
--CWnd
---CView
----CScrollView
-----CFormView
GetScrollPosition is a member of CScrollView
ns wrote:
ANother associated question
I should have remembered this, but it has been a while since i did something like this.
OnSize is called when the form is first created, before any of it's child controls are created. So you are right, you will get ASSERT's if you try to access nonexistant child controls. You are handling the situation correctly.
HTH
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
Its the same with setwindowpos. I have a control I want to "attach " to the right edge of the CFormView in my MDI. I do this with movewindow in onSize, and set the y top as say 10 - some fixed value. This form is scrollable. Now when I scroll the control off the screen and resize, it immediately pops back into view - 10 pixels from the top edge, leaving a big blank space above it - the area that had been scrolled off. So it thinks its supposed to be at 10 pixels from the top, and repositions itself, leaving a blank gap above. I am deeply troubled by this. Help!!!
Thanks,
ns
|
|
|
|
|
Hey, I have a question regarding the windows message EM_SETCHARFORMAT. I am trying to use this and I am having a problem. I have a text editor and it allows the user to set the text to different fonts. This works but if, for example, there are 5 lines of text, each line has a different font, when I highlight all 5 lines and try to change the font, it only changes the font of the first selected line, not all 5 lines. Any idea what is causing this, the carriage return perhaps? How do I fix this so it will change the font for all the lines?
|
|
|
|
|
1.
How can I change font of a CFileDialog in MFC application and OPENFILENAME in Win32 Application ?
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
In MSDN, I found a samples: ChatSvr and Chatter. That is a network application using CSocket. But I don't know how to use CSocket in multithread. In ChatSvr, I want to throw each client connecting to server to a particular thread. It means server will manage each client ( and his socket) in 1 thread. How can I do that ?
I imagine the code for solving this problem may be like this:
void CServerDoc::ProcessPendingAccept()
{
CClientSocket* pSocket = new CClientSocket(this);
if (m_pSocket->Accept(*pSocket))
{
pSocket->Init();
m_connectionList.AddTail(pSocket);
//Add this line:
m_threadList.Add(....);
//or
AfxBeginThread(....);
}
else
delete pSocket;
}
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
I've created two regions with the CRgn class and the function CreatePolygonRgn. I then use the CombineRgn function to take the intesection of the two regions created with CreatePolygonRgn. I now need to turn the resulting region into a polygon.
I've been trying to use the GetRegionData function to return the points that make up the region. But I'm not having a success. The function keeps returning NULL for the RGNDATA pointer. Here is what I did:
RGNDATA* pRgnData;
x=aRgn.GetRegionData(NULL,1);
y=aRgn.GetRegionData(pRgnData,x);
pRgnData is still NULL.
What am I doing wrong?
|
|
|
|
|
YOU've got to allocate the buffer into which OS will put the region data. If you pass it your null pointer, it will tell you how space you should allocate for the buffer. The example above is passing an undefined pointer.
e.g.
DWORD x=aRgn.GetRegionData(NULL,1);
RGNDATA* pRgnData=(RGNDATA*)malloc(x);
DWORD y=aRgn.GetRegionData(pRgnData,x);
|
|
|
|
|
Thanks Scott. I'll try that.
Paul
|
|
|
|
|
Hello,
As I still have problem to print my MSChart ActiveX, I should have several work around:
1) Use the MsChart.EditCopy to copy my graph in the clipboard in a metafile format and print it from clipboard
2) capture the part of the dialog screen containing my graph and print it
But the question remains the same : how do I print a graphical object ( or a metafile or directly a MSChart) ?
And with solution 2), how do I capture this part of my screen, under which form and how do I print it ?
Thanks in advance for your help
DD
|
|
|
|
|
Qadddd wrote:
But the question remains the same : how do I print a graphical object ( or a metafile or directly a MSChart) ?
A graphical object can be selected into a DC. Just blit it to the printer DC.
A metafile can be played back to a DC using PlayEnhMetaFile .
|
|
|
|
|
hello,
to be clear in my mind, do you have any code example that perform this kind of operation.
I have to say that I am not a specialist in VC++ and that playing with printers (apart some easy prints in text mode) is quite new for me.
I looked on the web and found no example for metafile play on a printer DC, they are all destinated to a rect, so a screen so it seems that I can't use this solution.
No solution for the screen capture in a rect object that could be printed ?
Thanks in advance
DD
|
|
|
|
|
Qadddd wrote:
I have to say that I am not a specialist in VC++
You don't have to be. This is basic Win32 API programming.
I looked on the web and found no example
You looked in the wrong place (or with the wrong search phrase(s)). Try looking at MSDN and the samples there.
|
|
|
|
|
>>You don't have to be. This is basic Win32 API programming.
there are so many other things more interesting than printing ...
I am just learning and coding in VC++ by myself, the night at home, and loos e so much time on a single problem like this one ... and have some many other things to do ...
>>You looked in the wrong place (or with the wrong search phrase(s)).
I am not a specialist from the web neither, i use google and then jump in the thousands links or post some question on forums after having searched for a solution in already existing posts. What's the right phrase to print in vc++ an chart produced by an activeX Mschart? Try by yourself and we'll see if you are more lucky or efficient than me
>>Try looking at MSDN and the samples there.
there so many articles, the one more complicated than the other. It is simple, when I want to find something in MSDN, I never find it. Print for example, there is no simple doc explaining the right way to do it with a good significative example (at least when you search with their "search for"). another thing, I am coding in vc++, I don't give a damn about article talking of VB or other . Try to find out how to print chart produced by using a MsChart activeX, the only info I found is for VB. Try to search in the newsgroup, this question appear several times for at least 2 years, but there is no answer neither from students nor from microsoft ...
Frankly, I don't understand why there is no "Print" method as there is an "EditCopy" method ... or at least the explanation to do it.
DD
|
|
|
|
|
the only command I know if is itoa and that requires a second or third convesion before I end up with a MFC useable CString. I read a post saying something about using the Format command but I have been unable to get it to work.
Can anyone help?
Thanks
Eric
|
|
|
|
|
CString str;
int i = 100;
str.Format("%d", i);
that's it. it's just like printf/sprintf.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|