|
I have been using a modeless dialog for indicating the progress of a task. In the dialog is a CProgressCtrl, and a cancel button. I have recently added a CListCtrl as well.
Everything works fine as long as you do not move the dialog, or click in the list control. Once you do this, things start to get wierd. Usually, there is a 2-3 second delay when clicking on something, or moving the window. During this delay, nothing is happening with the task that the dialog is showing the progress of. It should be continuing on, but nothing happens. The screen does not draw correctly either.
Each time I manually break, the stack points to my function that is pumping messages (it gets called periodically during the task). The PeekMessage seems to be "stuck" for some reason. Again, this only happens if the dialog is moved, or when clicking on a control within the dialog.
Any ideas on why this may be happening? Any work-arounds?
<br />
while (::PeekMessage (&msg, NULL, 0,0, PM_NOREMOVE)) {<br />
<br />
if (pbrcv != NULL && msg.message == WM_MYMSG1){<br />
*pbrcv = true;<br />
}<br />
if (!AfxGetApp()->PumpMessage()) {<br />
::PostQuitMessage(0);<br />
return false;<br />
}<br />
} <br />
LONG lIdle = 0;<br />
while (AfxGetApp()->OnIdle (lIdle++))<br />
;<br />
}<br />
Thanks,
DaveQ
|
|
|
|
|
I assume you have a single-threaded program. When you click on one of the controls on the modeless dialog, it is not receiving enough of the CPU to carry out what needs to be done (e.g, paint). When it does get a timeslice, things probably appear "jumpy."
The PeekMessage() solution you have employed is an antiquated and largely unused 16-bit Windows solution (but still used because it is "well known"). It's bad for several reasons. The most important one is that it puts, in the time-critical main loop, a function whose overhead is substantial. Another problem is, since there is a modeless dialog active, there is no IsDialogMessage() call there to handle it. Go with a worker thread.
|
|
|
|
|
Thank you for replying.
Unfortunately, the worker thread isn't something I'm going to be able to do. It's difficult to explain why. I did try putting the dialog in a GUI thread, but got the same result. I think what may be happening is the message that helps keep the task running properly is getting "eaten" by something??
The PeekMessage loop that I showed earlier is there to keep the GUI alive, but the filter is set to read all messages. I thought that the task message (call it WM_USER + 100) would be left alone since I specified PM_NOREMOVE, but it is acting as if the message is not being left in the queue.
I may have to do something cheesy like prevent the window from being moved if I can't find the problem.
Thanks for your help.
|
|
|
|
|
Here's a weird one... I have the following calls for performing asynchronous I/O on a USB device (control logic for device type abstraction stripped away):
if(!m_waiting_for_read)
{
io_complete = DeviceIoControl( m_device_handle,
ioctl_code,
control_buffer,
control_buffer_size,
buffer,
read_size,
&bytes_read,
m_read_asynch_info )
? true : false );
}
else
{
io_complete = GetOverlappedResult( m_device_handle,
m_read_asynch_info,
&bytes_read,
FALSE )
? true : false;
}
m_waiting_for_read = false;
if(!io_complete)
{
// Read failed, or need to wait for asynchronous result
DWORD result = GetLastError();
if(result == ERROR_IO_PENDING)
m_waiting_for_read = true;
else
HandleDeviceIOReadError(status);
}
else
HandleBytesRead( buffer, bytes_read );
Seems sensible...in normal operation:
1. DeviceIoControl returns 0 (io not complete)
2. GetLastError returns ERROR_IO_PENDING
next iteration:
3. GetOverlappedResult returns 1 (io complete)
But here's the bizarre behavior I'm seeing:
1. DeviceIoControl returns 0 (io not complete)
2. GetLastError returns ERROR_IO_PENDING
next iteration:
3. GetOverlappedResult returns 0 (io not complete)
4. GetLastError returns ERROR_SUCCESS
What am I to make of this? Strangely, GetOverlappedResult did set bytes_read to something (bytes_read was set to zero before the call; after the call it was 0x0d, which happens to be the number of bytes that were read on the previous read cycle, which followed the good 1-2-3 pattern. bytes_read cannot be considered to be valid since GetOverlappedResult returned 0, but it is still strange that it's being set. In any case...after GetOverlappedResult returns 0, GetLastError should return ERROR_IO_PENDING or some other actual error, but not ERROR_SUCCESS. Should I interpret ERROR_SUCCESS to mean that the I/O is still pending and call GetOverlappedResult again? If that were the case, why didn't it return ERROR_IO_PENDING?
Thanks in advance,
Brian
|
|
|
|
|
Hi, I get bored that of many variable types that were declired by Microsoft for Visual C++. But still I love programing and have energy to fight with that lots of details included in programing.
So I need a good tutorial to learn variable types, type casting and window API return values. The most I hate and need to learn to show different types of variables for example in an messagebox or edit area. sprintf does allow everting to format as a string? or what else professionals use?
every word that you infor me would pleasent of you?
goog works...
karanba
|
|
|
|
|
Aside from the built-in (i.e., intrinsic) types, you can peruse the various .H files for a plethora of typdef statements, function prototypes, etc.
|
|
|
|
|
How can I get and set time out for winsock?(non-mfc)
Please sent me a piece of code.
thanx.
karanba
|
|
|
|
|
One solution is setsockopt(). You may change the send and/or receive timeout for non-blocking I/O.
// For send
SO_SNDTIMEO
// For receive
SO_RCVTIMEO
Kuphryn
|
|
|
|
|
|
As per the documentation in the source, by defining USE_MALLOC_LOCK, you get thread safe versions of the routines.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
|
Hi,
I know that there is a share memory technique with Linux. Is
there a same share memory technique for windows and VC++ (two cpus)?
Any reference?
Thanks in advance!
chen
|
|
|
|
|
I'm not sure about what Linux is doing but there are several way to share memory between applications. Memory mapped files and defining a shared section in a common dll are two.
John
|
|
|
|
|
|
When I use IShellFolder->EnumObjects for folder retieve at the root namespace(desktop), the folder list I got is strange.
first, the "My Documents" Shell linked folder is not the first subfolder under desktop, unlike what we see when using explorer.exe or File-Open dialogs.
second, a special folder named "Internet Explorer", But when we use File-Open Dialog, It does not appear in the folder combobox.
Can I do the same like the folder combobox in File-Open Dialog?
How to do?
Thanks.
|
|
|
|
|
hi.
I´m recovering a field´s value with CString x = (LPCSTR) (_bstr_t)pRs_SP->Fields->Item["id_symposium"]->Value ;
but It has a problem when Value is NULL, how can I solve it?
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
You have to check it explicitly. Probably best to wrap this in a function:
CString VariantToString( const _variant_t& var )
{
if ( var.vt == VT_EMPTY || var.vt == VT_NULL )
{
return CString( );
}
else
{
_bstr_t bstrVar( var );
CString strVar( (LPCWSTR)bstrVar );
return strVar;
}
}
and then use it like this:
CString x = VariantToString( pRs_SP->Fields->Item["id_symposium"]->Value );
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
<smallel hombre="" arriesga="" su="" vida="" cada="" vez="" que="" elige="" y="" eso="" es="" lo="" hace="" libre="">
|
|
|
|
|
Hi, everyone!
I am writing two small funtions, one is used to change from
hex string to decimal string, and the other one is vice versa.
For example, I simply use sprintf(..."%X" ...) to change from
decimal string to hex string and use "%02X" to set filling
character. When changing from decimal to hex, I need two functions
one of which will put 0 before the converted value if it is only
one bit, for example, 10 --> 0A. Another one do not have the function,
for example, 10 --> A. When changing from decimal to hex, I need
only one function. I want to know whether there are some more effienet
ways?
Thanks in adavnce,
George
|
|
|
|
|
Use strtol() to convert from base 16 to base 10.
|
|
|
|
|
Thanks, DavidCrow buddy!
George
|
|
|
|
|
Thanks, DavidCrow buddy!
I have another question. How to change from base 10
to another base? The function strtol() you introduced
to me can only change from base 16 to base 10.
regards,
George
|
|
|
|
|
Have you tried itoa()?
int num = 1234;
char str[32];
itoa(num, str, 8);
|
|
|
|
|
Thanks, DavidCrow buddy!
George
|
|
|
|