|
I've used this exact approach. There is nothing wrong with what you are doing.
Johann Gerell wrote:
the only possibility of a memory leak is that the GUI thread message queue is filled
I found the following in the MSDN for PostMessage() [^]. There is a default limit of 10,000 messages that may be posted to a window using PostMessage() . If your call to PostMessage() fails, you should delete the memory allocated for the string yourself.
PostMessage() is nice because access to the message queue is synchronized for you. If the 10,000 message limit is a problem, you will need to create your own communication mechanism between the two threads. Here's a simple example:
CTypedPtrList<CPtrList,char *> Queue;
CCriticalSection QueueCS;
char *string = NULL;
QueueCS.Lock();
if (!Queue.IsEmpty()) string = Queue.RemoveHead();
QueueCS.Unlock();
free(string);
QueueCS.Lock();
Queue.AddTail(strdup("Message string"));
QueueCS.Unlock(); The two threads communicate using a simple queue of pointers to strings. The critical section safeguards access to the queue. The worker thread allocates the strings on the heap using strdup() , and the GUI thread deallocates them using free() .
The only complication with this approach is that you must have the GUI thread poll the queue at intervals to update the screen. For example, using a WM_TIMER handler, you could have the GUI thread update the screen at one second intervals.
Another possibility is to reduce the number of strings sent by the worker thread. If the strings being sent are a simple progress update ("Processing for 5 seconds...", "Processing for 6 seconds...", and so on), you only need to send strings when the time changes.
Software Zen: delete this;
|
|
|
|
|
Hi
In functions like PreTranslateMessage you get a pointer to a MSG structure which includes some UINT message. How can I resolve that number into plaintext (the name of the message) e.x. "WM_KEYDOWN" so that I have an understandable TRACE output?
Thanks & Bye,
T.T.H.
|
|
|
|
|
please refer winuser.h
where you can find the numeric values of each windows message
example:
#define WM_COMMAND 0x0111
#define WM_SYSCOMMAND 0x0112
#define WM_TIMER 0x0113
#define WM_HSCROLL 0x0114
#define WM_VSCROLL 0x0115
#define WM_INITMENU 0x0116
#define WM_INITMENUPOPUP 0x0117
#define WM_MENUSELECT 0x011F
#define WM_MENUCHAR 0x0120
#define WM_ENTERIDLE 0x0121
|
|
|
|
|
Hi !
I'm sure this is a stupid question, but, if I do this :
char Buffer[10];
std::cin >> Buffer;
How can I make sure that the input won't be longer than the buffer ?
Jérôme
|
|
|
|
|
Use
std::cin.read(Buffer,sizeof(Buffer)); (caveat, this does not append and null terminating character.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
|
|
hi..
I am developing an application which requires me to collect voice spoken on telephone (i.e. outgoing call), record it and play it back later..
The numbers dialed on the telephone should appear on the screen.. Can someone pls tell me how to go about this.. basically what i want to know is how to communicate with the USB driver ..(phone is connected to USB port using and adapter.)
I also want to know how to record voice spoken on telephone..
Thanx
mpal
|
|
|
|
|
|
I am New to CodeProject, and have used the Article Wizard to create an article and noticed no feedback is given...
This article is based for Beginners using File I/O... I was wondering if some of you would take time to review this short tutorial and give me feedback and vote if its suitable for Beginners.
http://www.codeproject.com/useritems/FileIOTutorial.asp[^]
Thanks Ahead of Time,
~~HDPerformance808.
Contact Information:
Email: HDPerformance808@hotmail.com
AIM: HDPerformance808
|
|
|
|
|
how can I display the data that I get from the USB2.0 port? The data from the USB port continuously is in the "int buffer[1000];" I would like to use the PolyLineto(pt,1000) function to draw the line ; pt is defined as CPoint pt[1000],
for(int i=0;i<1000;i++)
{
pt[i].x=i;
pt[i].y=buffer[i];
}
if I use the "pt[i].y=buffer[i]; " sentence ,every time the CPU will do an extra copy work, it will waste the CPU time.
Are there any good methords that I don't need to copy the buffer data to the pt[i].y array?
thanks
zhenyuanwu.
|
|
|
|
|
hi,
Use memcpy fucntion it will copy the whole buffer at a shot.
all the best
Hasan.
hasansheik@yahoo.co.in
hasansheik@lycos.com
|
|
|
|
|
I'd like to setup my application so it can only run from the CD it's to be distributed on.
Can someone offer suggestions?
Thanks
Rich.
|
|
|
|
|
Simply follow this logic.
- Get the path of your Application using [
GetModuleFilename ]api.
- Now extract the Directory from the this path using [
_splitpath ]
- Check Is this directory is CD drive?[
GetDriveType ] if yes run the program else......
This logic may not work well when some one is using
S/W like vitural CD,Nero Image Drive
etc.
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Hi,
I need to change the background colour of checkbox. Is there anyway by which this can be accomplished.
Thanks for any help
Regards
Vikram Attiganal
|
|
|
|
|
Follow these step:-
1. Make the CheckBox control OWNERDRAWN either by selecting OWNER DRAWN property from property window or using [your button object]::ModifyStyle(0,BS_OWNERDRAW).
2.Handle WM_CTLCOLOR message to set background color of control.
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
I've developed an application that receives UDP messages through
an Ethernet connection. This application run on W2K and I've uses
some SDK functions to manage sockets.
Mine problem is the following:
the application runs properly on PCs where there are Visual Studio
and Win SDK installed.
When I run the application on a PC without that applications,
it is not able to manage fragmented UDP packets. It receives only
small UDP packets but not larger ones (the select made on sockets
doesn't return when a packet is received).
I've also verified to OS version and the service packs installation
but it seems to not be the problem.
How can I solve this problem ?
Is it due to some DLL not available in the PC ?
Is it due to some sockets, or network card settings ?
Thanks a lot
|
|
|
|
|
Dears,
How can i draw a normal rectangle(not focus rectangle ) and circle using CDC class. I mean to say which methods are to be used?
|
|
|
|
|
|
In the project,there are serveal DocTemplate,How to save all the documents of diffferent Doctemplate into one file
|
|
|
|
|
Iam developing an excel like application similar to the AlxGrid which is found in the site
http://www.alxsoft.narod.ru/ENG/alxgrid.htm
When we have millions of data displayed in the grid, the process of selection is quite slow..its actually selecting cell by cell and hence the performance of the grid is quite slow....
can anyone help me out with this..
|
|
|
|
|
Hi,
how kan i mov a Dialogbox without a titlelist? Is just normal Dialogwindow without a titlelist and system menue, i kan only move, replace, them in the screen when is a titlelist created? i think on a event like OnMouseDown or somethink like this, is there any API or Function for this?
thanx
mirsad
|
|
|
|
|
hmmm.....i had the same prob.....though i can move the dialog where i want to it still doesnt move the way it does as it does in the windows dialog......
well thiz is what i have done.....
sense for the drag of the mouse,whenever the mouse is dragged use the SetWindowPos() function.....
here is the coding i have used in the in OnMouseMove() function......
void CxyzDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_DragOn==TRUE)
{
CPoint point1=point;
ClientToScreen(&point1);
this->SetWindowPos(&CWnd::wndTop ,point1.x-473,point1.y-23,0,0, SWP_SHOWWINDOW|SWP_NOSIZE);
}
CDialog::OnMouseMove(nFlags, point);
}
please note that the m_DragOn is set to ONE on the OnLButtonDown()function and set to zero on the OnLButtonUp() function.....
also note that in the SetWindowPos() function i have changed the value of the x cordinate by 473 and y cordinate by 23(which happenz to make the mouse pointer to point to the center of my dialog)....u will have to set the value accordingly!!!!!
ps:there definitely an another way to do it,but i guess thiz gives a good result as well.....
hope thiz helpz ......
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
If I understand your question,
Handle the WM_NCHITTEST.
Write the following code in OnNcHitTest(CPoint point)
{
CRect rect;
GetClientRect(&rect);
ClientToScreen(&rect);
if (rect.PtInRect(point))
return HTCAPTION;
return CDialog::OnNcHitTest(point);
}
Good code for life.
|
|
|
|
|
hi,
@rateep thanx for the great help! That is what i need!
@khan++, i kant find the WM_NCHITTEST event in my Class Wizard
thanx
mirsad
|
|
|
|