|
Because I still cannot get the main thread to intercept the keyboard while the sending function is executing even in the new thread.
I must be doing it wrong - here is the code snippet
// implementing multiuthreading
TRACE("\n Start the C_MorseCode_Thread thread");
m_C_MorseCode_Thread = (C_MorseCode_Thread*) AfxBeginThread(RUNTIME_CLASS(C_MorseCode_Thread));
m_C_MorseCode_Thread->m_C_Morse_Class->C_ConvertText("Test Test Test Test ",m_CFD2008Doc);
Do I need to start the execution in the new thread itself?
|
|
|
|
|
You're doing that wayyyyy wrong. Read an article on AfxBeginThread() first and try again. You're still making a direct call into the method, even if it is on a different thread.
|
|
|
|
|
I am making progress, however, have some minor questions.
1.How does the parameter gets into worker thread control function ?
2.Why does this function need to be defined as static?
3.Per article I am using , the worker thread can be “easily stopped”, however, since the thread sets the COM port (DTR) how do I know it will disable the DTR not just quit the thread? ( I am guessing I need to make sure it will and stopping the thread is no guarantee.)
4.If I use user-interface thread I need to create Cwnd ( Morse code class) It fails but “getLastError” reports “function completed successfully”.
I am using MFC document / view to set / control COM port (DTR) ( outputting Morse code string) and have to be able to stop it ( reset DTR via keyboard ) from the main thread.
I think I will need to use user-interface thread to get better control.
One more – if I want the user interface thread to intercept keyboard messages I am planning to intercept them in the main thread (Cview) via PreTranslateMessage and than PostThreadMessage to thread of interest. Is that the only way to accomplish this?
Thanks for reading,
Any constructive help will be as always appreciated.
Cheers Vaclav
|
|
|
|
|
Hi all
In my aplication menu had a ribbon edit with spin button, I'm using this:
pEdit->EnableSpinButtons(1, 1000);
But when I increment with up arrow over 999 the value is changed to 1,000
I used GetEditText to change this value but what I have is 1
I can't change increment or ignore ',' or remove ',' from value, that is a bug with ribbon.
In old MFC application I have Spinbuttonctrl in create method I have used UDS_NOTHOUSANDS but in ribbon I don't have this option.
If somebody can help me.
Thank you
|
|
|
|
|
Not sure I understand what your problem is... When you do a GetEditText on your control you only get 1 when it should be a 1000? or you don't expect to be able to reach 1000? Can you clarify?
|
|
|
|
|
Seems the comma in 1,000 is his problem (ie GetEditText reads "1,000" then parseInt() or whatever stops at the comma). If there's no suitable style/attribute on the control he's using, then I guess it requires a bit of string-munching.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The problem is comma, when I use GetEditText() returns '1' and not '1,000', I want 1000 because I'm editing a object and when reach 1000 returns to value 1, that's wrong. I don't have parseInt() method I'm using mfc c++.
thank you
|
|
|
|
|
This seems like such an obvious bug... why would GetEditText() parse out the text (CString never ends on a ',' so I don't see how this bug could occur)? where are you checking your return? Maybe post your actual code and point out where you see the 1.
|
|
|
|
|
Hi
Here is my code:
CMFCRibbonEdit *pEdit = DYNAMIC_DOWNCAST(CMFCRibbonEdit, MyApp->GetRibbonElement(ID_RIBBON_FORMAT_WIDTH));
if(pEdit == NULL)
return;
CDrawObj *pObj = (CDrawObj*)m_selection.GetHead();
if(pObj == NULL){
ASSERT(0);
return;
}
if(_ttoi(pEdit->GetEditText()) < 1) <==== Here GetEditText() return 1 and not 1,000 I tested with MFCOffice2007Sample and they have the same problem
return;
this->InvalObj(pObj);
int nDelta = _ttoi(pEdit->GetEditText()) - pObj->m_position.Width();
if(nDelta < GetDocument()->m_size.cx){
CRect newPosition = pObj->m_position;
newPosition.right += nDelta;
pObj->MoveTo(newPosition);
}
|
|
|
|
|
See... you're problem is probably with the conversion of the CString to an integer... place pEdit->GetEditText() on its own line and look at the text returned. If its 1000, with or without a coma, its correct and the problem is with the function doing the conversion to integer. You can always take your returned CString and remove the ',' character before even attempting the conversion.
CString ret = pEdit->GetEditText();
ret.Remove(',');
|
|
|
|
|
Thank you
Now is working but when I click in Up Arrow the increment shows 1,000, 1,001, 1,002 and when I change focus shows the correct value.
Thanks for all
|
|
|
|
|
that's a different issue, post as new question pls...
|
|
|
|
|
The problem is resolved:
I used:
CString str = pEdit->GetEditText();
str.Remove(`,`);
pEdit->SetEditText(str);
Thank you
|
|
|
|
|
Cool... cheers!
|
|
|
|
|
Thanks. All fixed while I was sleeping... You've spelled out exactly what I was referring to a few message above.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hello everyone,
I have a problem... I want to send/post a message to a CDocument object from a CDialog object. I know I have use WM_COMMAND message but the thing is that the CDialog object does not have any access to information of CDocument since it is created from another thread. What should I put in the parameter HWND? Is there a handle for CDocuments?
Any suggestions?
Thanx in advance!
Odysseas Zografos
|
|
|
|
|
Odysseas Z wrote: I want to send/post a message to a CDocument object...
It's not a window, so why?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I just had to call some specific functions of my CDocument derived but I managed to by-pass it..
Anyway I solved my problem but academically speaking I still pose the same question. If someone wants to "trigger" with WM_COMMAND message a CDocument how does he references to it and what does he puts in the first parameter (HWND) of the Send/Post Message function?
The referencing part is easy... http://support.microsoft.com/kb/108587[^]
But the cast from CDocument to HWND SendMessage((HWND)CMyDoc::GetDoc(),...) of course fails... So what does someone do?
Cheers!
O.
|
|
|
|
|
You seem to be confused about both C++ and Windows here; you cannot cast a CDocument object to an HWND since the one is not derived from, or the same 'shape' as, the other. A CDocument object is an instance of a class and an HWND is a Windows handle. There is also no mechanism within the CDocument class to receive windows messages. You could create a special command that will be handled by your CDocument class, and then send that command to your main or view window. Alternatively you could call the method of your document directly after your dialog has completed by checking some value within your CDialog class. If you really want to understand command and message handling in MFC then read this excellent paper[^] which Iain Clarke[^] pointed me at only yesterday.
The best things in life are not things.
|
|
|
|
|
I don't think you can message directly to a CDocument, you probably have to message the CView associated with it. In another words, send message to CView and have CView interact with CDocument however it needs to.
|
|
|
|
|
I think in the spirit of MFC document / view implementation one should interact / send messages to view only anyway. But I agree it seems convoluted.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: But I agree it seems convoluted.
Isn't it always?
...but I agree with you, should probably go through view anyway.
|
|
|
|
|
Hi all!
Is there a way to parse command line options from a string/file? I'd prefer a standard library that works on Linux, but if there is some way to do it from boost or some other library please let me know.
Please note that I'm NOT talking about command line arguments that are passed to the main function (argv), instead the complete cmdline is saved in a file.
Thanks alot!
|
|
|
|
|
If you really need a flexible thing, then have a look at Lua[^].
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]
modified on Monday, June 27, 2011 4:09 PM
|
|
|
|
|
Whether you pulled the string from a file or from the command line, it'd be parsed in the same fashion.
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|