|
Maybe try calling
PostCode.ReleaseBuffer(m_PostCode.LineLength(0));
before calling Replace()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Yes, this worked like a charm!
Thanks a lot Mark, very speedy response!
Louis.
|
|
|
|
|
Hey Guys,
I have an MFC CStatic derived class that has a public member function Draw();. Draw uses GDI to draw stuff to the CStatic window. I call this Draw method from a multimedia timer (timeSetEvent) to continually update the display.
My problems is that When my main app is doing a lot of work the drawing is sometimes interrupted when I load files. So I put the lengthy process of loading files in a worker thread, but the drawing is still "jerky" when loading a file. Is there anything else I can do to ensure that my CStatic is always drawing? Is this something I need a user interface thread for?
Thanks,
Greg
|
|
|
|
|
I'm not certain what you're trying to achieve here as genuinely constant redrawing would preclude you doing anything else anyway but you may have run up against a perenial problem with the MFC architecture. Essentailly anything done to the user interface is done on the main thread even if you call it from a worker thread. I would definitely suggest doing the file loading on a worker thread before getting into the absolute minefield of multiple user interface threads.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Basically I have two music files playing (video and/or audio) I am showing a scrolling waveform as the song is playing in realtime (using GDI). I need this waveform to always scroll. When loading a file into the second player while the first player is playing the scrolling waveform is being interrupted. I just need that waveform to always be scrolling.
So MFC always draws from the main thread no matter what? That's no good for me. Is my only option UI threads?
|
|
|
|
|
If you're doing that sort of thing and you want it really smooth I'd consider DirectX/OpenGL or perhaps just doing everything except the drawing in lower priority background threads and relying on having enough hardware under the bonnet to keep up. Double buffering may be your friend aswell when it comes to getting smooth display updates. i.e. draw it all to an off screen Bitmap and then blit that to the screen in one go. With a bit of manipulation perhaps you could do the scrolling in the bitmap memory aswell without having to redraw the old parts of the waveform.
It's a while since I did much PC based MFC but I certainly wouldn't have recommended it for the sort of app your describing when I did. Having said that there may be other issues causing your problems. Are you using a cyclic or fixed buffer that doesn't do any heap allocation while in use to store your waveform? If not you're going to get horrible performance glitches from the memory allocator for example.
Are you maxing out your current hardware? If you check the performance monitor while your app is the only one running and it's flat out at 100% then either you've got some ineffecient code or you're trying to push your hardware beyond what it can achieve. Ultimately all such jolts and flickers are down to something being blocked either by synchronisation or a bandwidth limit somewhere. Unless something is resource stealing. In that regard watch out for the Quicktime tray icon app if you use DirectX it can steal the graphics card from you every few seconds and cause horrible jitter.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I don't agree that all drawing is done on one thread. Through WM_PAINT maybe, but if you're using
GDI to draw from another thread then it's drawing on that thread. I do video rendering and it's
definitely not on one UI thread
*edit* BTW, I've personally never used multiple UI threads - I meant multiple worker <br />
threads doing GDI drawing.
Try calling GDIFlush() when you're done drawing each time.
Also remember GDI is not thread safe - It's up to you to sync drawing from other threads with
drawing that may occur in response to WM_PAINT on the UI thread.
Mark
-- modified at 13:15 Wednesday 4th July, 2007
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi,
Using a CDialogBar:OnSize(UINT nType, int cx, int cy) I get assertion error when i am trying to access a child window ie CStatic control under OnSize method. In OnInitDialog it works fine but in the OnSize the hWnd is equal to ??? (unkown). What's wrong here ?
void CBottomPanel::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CStatic *pStatic;
pStatic= (CStatic*) GetDlgItem(IDC_MYSTATIC);
-----> ASSERT(pStatic); ----------------------------->Assertion Error, not valid handle.
}
sdancer75
|
|
|
|
|
On the first call [or so] to OnSize the child windows have not been created yet. In other words, their HWNDs are not valid. Perheps this is what causes the assertion failure. Try to have smth like so;
CStatic *pStatic;
pStatic= (CStatic*) GetDlgItem(IDC_MYSTATIC);
if (NULL != pStatic)
{
// do anything here
}
In this way you will skip the first time call to OnSize.
In general, using GetDlgItemis not a good idea. Instead, let the wizard define CStatic c_myStatic member-variable. In this case the code will turn into this one;
if (NULL != c_myStatic.GetSafeHwnd())
{
// do anything here
}
--
=====
Arman
|
|
|
|
|
Hi Arman,
I suppose you have right. I did not tested since i have changed my code and i placed all code to CalcDynamicLayout(int nLength, DWORD dwMode) and it works.
Thank you for your reply,
Regards,
sdancer75
|
|
|
|
|
I agree with Arman maybe your error is of first call.
|
|
|
|
|
in my progarm (special to deal with data), i need good expressions for 2,4,8,16 based integers.
for example, in c++, we use 0x... to stand for 16 based data.
so, expressions i try to use are:
0b... (2 based)
0f... (4 based)
0o... (8 based)
0x... (16 based)
but i am afraid that expressions above are not good.
i hope i can use common or popular expressions.
do you know expressions which are accepted already by people for different based integers?
|
|
|
|
|
Base-2 and base-8 numbers already have a known prefix. Why the change? What exactly are you trying to do?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hey!
m working on a code where in i have to write to a board. the system and the board are connected via UART. m using VC++. the problem is that the moment i try to write a character the system hangs. here is a part of the code -
void CserialportthingieDlg::OnBnClickedWrite()
{
UpdateData(TRUE);
size_t size;
size = strlen(m_sshwwrite);//m_sshwwrite is he variable associated with the editbox
int i;
i=size-1;
asd->WriteByte(m_sshwwrite[i]);//asd is an instance of the class SerialCom where in i writebyte has been defined.
}
the definition of writebyte is --
BOOL CSerialCom::WriteByte(BYTE bybyte)
{
iBytesWritten=0;
if(WriteFile(hComm,&bybyte,1,&iBytesWritten,NULL)==0)
return false;
else
return true;
}
please let me know if any thing is wrong with the code or tell me a better way.
thanks a lot!
regards
lovy
|
|
|
|
|
How do you set the serial port timeouts (remember: WriteFile is a blocking call)?
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.
|
|
|
|
|
actually i had set some arbit time out.
now even when i restored it to the default value the system still hangs!
help me out!
thanks
regards
lovy
|
|
|
|
|
Post the relevant code (i.e. port open, DCB definition, etc..)
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.
|
|
|
|
|
If WriteFile() is failing, call GetLastError() to find out why.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
May be you are setting the wrong kind of handshaking. If you are setting hardware handshake, unless the board on the other end sets the relevant lines in the port, the WriteFile will wait until the port timeout (if I remember it correctly).
There are variables in the DCB structure that need to be set for setting the handshake mode(None, Software, or Hardware).
Also you could check if the board is working by trying it with HyperTerminal first with the correct Handshaking.
this is this.
|
|
|
|
|
Hello. I am new to MFC and C++ in general. I am interested in how to get the lower and higher parts of a DWORD variable?
|
|
|
|
|
I guess you're looking for the HIWORD and LOWORD macros. MSDN docs are here[^]
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Have a llot at LOWORD and similar macros on MSDN http://msdn2.microsoft.com/en-us/library/ms632659.aspx[^].
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.
|
|
|
|
|
After I switched from VS2003 to VS2005 the Windows error sound comes up when I close my application but there's no error message.
The only changes I made in the code are the ones required to make it VS2005 compatible.
|
|
|
|
|
Are you sure there is no MessageBeep() in your code ?
Just guessing
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
That's Microsoft's way of making your application more multimedia robust!
If you run in the debugger, do you see any exception/error/assert messages in the Output window
during shutdown?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|