|
Move the loop into a background thread and on each iteration (or every nth one) check for a "pause" flag that can be set by the UI thread; just be sure it is done in a thread-safe manner.
|
|
|
|
|
Thanks, but I have so little experience with threads, I will have to bone up on it.
Raymond
|
|
|
|
|
For dialog boxes, you can add and periodically call the following. Adjust to get best responsiveness:
BOOL CMyDialog::Pump()
{
MSG msg;
while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
return FALSE;
}
}
LONG idle = 0;
while (AfxGetApp()->OnIdle(idle++));
return TRUE;
}
|
|
|
|
|
Thanks, but I don't see how that can be made to deal with a loop.
Raymond
|
|
|
|
|
In the loop you periodically call the function; this keeps the message pump going and allows messages to be processed. This is the traditional way to make a progress/cancelable dialog box.
The alternative, and preferable for anything lengthy, is to run the operation in a thread.
|
|
|
|
|
In the end it was easy enough to run the function with its loop in a thread.
"ThreadProcTCP" is a rather involved module, with a loop, but it all works fine.
if (hChild)
GetExitCodeThread( hChild, &dwExitCodeThread );
if (dwExitCodeThread!=STILL_ACTIVE)
hChild = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProcTCP, hWnd, 0, &dwChild );
RaymondM
|
|
|
|
|
Note two things; a thread handle is non-signaled when it's running and signaled when it's not. Thus you can do a WaitForSingleObject() on a thread handle. Second: if you do any CRT calls in your thread, you should use __beginthreadex() (not all CRT calls need thread local storage (TLS), but figuring out which ones need it is tedious and, to my knowledge, not documented.)
|
|
|
|
|
Hallo,
is there any possibility to prevent an embedded child window to change its z-order?
My current problem is, I have an control embedded that brings itself into the front sporadically. Since it's embedded in one of my dialogs, the corresponding dialog is popping into the foreground, too.
Within the application this causes an affected dialog to pop in front of another dialog the user could be working in at the same moment.
For testing purposes I made a ::SetParent(controlHwnd, NULL). Once being a child of the desktop, it pops in front of any application now, not only on top of the application it was embedded in.
Anyhow, since I have no chance to modify the control itself (no sources!), I am searching for a way to prevent the control of changing its z-order. Is there any chance to "pin" it?
I have tried nearly all windows styles, but since the control seems to push itself into the front, I cannot do a lot against it this way. Perhaps subclassing the control's window and filtering some specific events? Any help appreciated!
Thanks a lot in advance,
Roland
|
|
|
|
|
This Article by Raymond Chen[^], might suggest a solution.
Then again it might make things worse by confusing the issue.
What you want to determine is why your control "brings itself into the front sporadically".
It's being triggered by something, obviously.
Here's another Interesting bit of z-order lore[^].
|
|
|
|
|
I obviously don't get this bind stuff as I cannot seem to get it right
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace boost::bind;
typedef int DWORD;
typedef std::pair<std::string, bool> user_info;
typedef std::map<DWORD, user_info> USER_MAP;
typedef std::vector<DWORD> VEC_STAFF;
int _tmain(int argc, _TCHAR* argv[])
{
USER_MAP m_Users;
VEC_STAFF Staff;
VEC_STAFF::iterator it = std::partition(Staff.begin(), Staff.end(),(bind(&USER_MAP::find, m_Users, _1) != m_Users.end()));
What I wanted to code to do is that for every entry in the Staff vector it should check to see whether that user id was present in the map, and if so move those items to the front.
I have an example using a functor that works as I hoped the above code would, but the bind version is obviously not doing what I think its doing.
struct InUsersMap : public std::unary_function<USER_MAP::key_type,bool>
{
InUsersMap(USER_MAP & theMap, USER_MAP::const_iterator end)
: m_theMap(theMap)
{
}
inline bool operator()(CSecurePatients::USER_MAP::key_type& id) const
{
return m_theMap.find(id) != m_theMap.end();
}
private:
const USER_MAP &m_theMap;
}
Finally does anyone know how to avoid getting the socket bind function from windows being included
|
|
|
|
|
When a .Net code calls an unmanaged C++ code, do we have the same thread executing the code.
And what about code exception ? Is .Net code capable of catching exception
originating from the unmanaged C++ code.
Thank you in advance.
(I don't program in .Net I just would like to know).
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
Yes
No (except possibly for a structured exception [generated by the OS])
|
|
|
|
|
Is there a way in C or C# to enumerate the port numbers in listening state on a remote Windows computer? I know you can use GetTcpTable() to enumerate the ports on the local computer, but I want remote.
|
|
|
|
|
I do'nt think this is possible.
Some applications called port scanners (like SATAN) give result by looping on a all port numbers within a specified range, initiate a connection i,n each time then decide using the reply result.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
Like the other poster said, you could do a port scan, or run your client on the other end and that should send you a snapshot of the ports that the computer is listening on.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
OP here.
There can be multiple instances of my app running on computer A, each listening on a different port. On computer B, I want to run a monitor app that can connect to any of the app instances running on computer A. It would be nice if I could enumerate those instances rather than having to just "know" what port(s) are listening.
What I might do is code my application to use a limited range or list of ports (say 100 fixed port numbers) and then code the monitor app to simply scan that list.
|
|
|
|
|
Perhaps you could select one specific standard port as a "management" port; computer B could open a connection to the standard port, and computer A would send back a list of its own open ports.
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
When using GDI+ ImageAttributes::SetColorMatrix, does the ColorMatrix pointed to in the first paramter need to remain in scope after the method call?
|
|
|
|
|
How to Write the Stored Procedure From Visual C++ with two arguments
|
|
|
|
|
Hello!
I have a Windows service which starts another application using CreateProcess. Thus, the application runs with SYSTEM privileges. This application calls LsaEnumerateLogonSessions, which returns the error code 8 (Not enough storage is available to process this command.). The service and the application are run under Windows 7 x64.
ULONG luLogonSessionCount = 0;
LUID *pLogonSessionList = NULL;
NTSTATUS lNtStatus = LsaEnumerateLogonSessions( &luLogonSessionCount, &pLogonSessionList );
LsaNtStatusToWinError( lNtStatus ) returns 8. Does anyone know the cause of this?
Thanks in advance!
|
|
|
|
|
msdn Smple-> http://msdn.microsoft.com/en-us/library/aa378275%28VS.85%29.aspx
what if you run the service under an admin account?
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi all,
I m using a Dialog based application,
On one button click i display the Modeless dialog box.here i m using a for loop.
and using Sleep function for delay of 1 second after each increment in for loop.
in modeless dialog box i m using two progressbar.Prg1,Prg2
1. Prg1 StepIt one by one as For loop working.
2. I want Prg2 show continous progress like its step it by timer and step it the progressbar until the modeless dialog box exist,for each value of for loop.
when for loop ends than modelss dialog box destroy.
everything is working fine ,only Prg2 not works fine here.
its not stepit by timer,
please help me for this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Since you are using a timer, the WM_TIMER message will not be processed when you are in the for loop.
Try putting the following message loop within the for loop.
if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
::DispatchMessage(&msg);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Ask the author (this may help you not spamming the forum ).
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]
|
|
|
|