|
How long does it take your dialog box to update the progress bar? Is that a long complicated process? Is your dialog box modeless?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Okay. First, I will answer questions.
1) The interval of the progress bar varies from data to data. Consider, for example, the process of zipping data. Zipping varies from data to data.
2) The dialog box is modeless. The dialog box is a private member in view.
-----
I want to clarify the actual problem. I saw a response from a member that implied that my description was not easy to understand.
The design works fine.
- worker thread handles data processing
- main thread (view) sends messages to dialog box
- dialog box updates the progress bar
The problem is that I believe the process of updating the progress bar is *considered* as part of the main thread. I think the reason is because the dialog box itself is declared in view (main thread).
I need three *independent* processes.
1) data processing
2) dialog box/progress bar updating
3) main thread is idling thus keeps the program from "locking."
Problem: Program seems to "lock" even though the data processing is done in the worker thread.
Question: I believe the reason it seems to "lock" is because as main thread sends message to dialog box to update the progress bar and as the dialog box update the progress bar, the frame considers the entire process (message + updating) as being in the main thread. I need to know a way to make everything separate.
Kuphryn
|
|
|
|
|
I would change your update mechanism to be more passive. If you are sending a message to the main thread, then the main thread is calling the update function 10000 times, like you described in your worker thread, that would be a drain on the system.
Have you considered using a timer on the main thread, set to say 1/10th of a second. The timer handler would call the update function of the dialog, and the dialog could use a thread synchronized varaible that indicates the current iteration of your worker loop thread?
Otherwise if your dialog update function depends on processing the data for every iteration, maybe your worker thread could create a report or cache all of the data for the main thread, then the dialog would just have to update a few times a second.
Good Luck!
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
|
Okay.
I have consider several different design schemes. One of which is passing a pointer of a dialog box created in view into the worker thread. There, the worker thread can update the dialog box's progress bar. However, I do not think that will solve the problem of "locking." The reason is the dialog box belongs to view, thus it is still apart of view and the main thread. That leaves me with two alternatives opposites of one another.
Alternative #1
- create the dialog box first
- message view after InitDialog()
- view active a function inside of the dialog box
- function instantiate a worker thread that is *part of dialog box*
- worker thread will update the progress bar directly
Alternative #2 (opposite #1)
- create a worker thread
- create a dialog box w/ progress bar *inside of worker thread*
- update the progress bar directly
From the two alternatives, which one do you think is best? I want to make the design as "safe" as possible i.e, non-volatile.
Please mention any ideas you may have.
Thanks,
Kuphryn
|
|
|
|
|
I've tried to trap the WM_CTLCOLOREDIT and used SetBkMode(TRANSPARENT), but this only worked for static control, not edit control.
Now I wonder if there's any easy way I can achieve the desired result (that is, no text background) without using any text output function. Please help me!
Uzi
|
|
|
|
|
I'd say the solution outlined in Mike Dunn's VC++ FAQ works all the same for edit controls (with the obvious changes.) Otherwise, you can take a look at some of te CEdit derived controls here at CP, some of them provide background transparency.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi.
I am working on a program that utilizes several threads (worker threads). I want to implement a class-safe thread synchronization. In his book, Prosise uses CCriticalSection and CEvent.
I would like to use CCriticalSection with CSingleLock. However, Visual C++ outputted errors when I declared the CCriticalSection and CSingleLock. For example:
-----
// this is in the document class (single)
...
private:
...
CCriticalSection m_cs;
CSingleLock m_sl;
...
};
-----
Visual C++ outputted similar errors referring to both classes. Here are the errors:
-----
d:\C++\MyApp\MyApp.h(96): error C2146: syntax error : missing ';' before identifier 'm_cs'
d:\C++\MyApp\MyApp.h(96): error C2501: 'CMyAppDoc::CCriticalSection' : missing storage-class or type specifiers
d:\C++\MyApp\MyApp.h(96): error C2501: 'CMyAppDoc::m_cs' : missing storage-class or type specifiers
d:\C++\MyApp\MyApp.h(97): error C2146: syntax error : missing ';' before identifier 'm_sl'
d:\C++\MyApp\MyApp.h(97): error C2501: 'CMyAppDoc::CSingleLock' : missing storage-class or type specifiers
d:\C++\MyApp\MyApp.h(97): error C2501: 'CMyAppDoc::m_sl' : missing storage-class or type specifiers
-----
I tried declaring both variable as protected and global. I saw the same errors.
Is there something specific that I need to add to the document interface as in maybe #include <something>?
Thanks,
Kuphryn
|
|
|
|
|
You've got to #include <afxmt.h> . Probably it's a good idea to insert the inclusion in "stdafx.h" .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
I am using the CInternetSession class
to retrive a target web page as follows.
...
...
CInternetSession interSession; // line1
CStdioFile *stdioFile; // line2
stdioFile = interSession.OpenURL(strURL, 1, INTERNET_FLAG_TRANSFER_BINARY); // line3
...
...
It works well, but sometimes program stopped at line3 therefore
I cannot do anything farther.
That problem occurrs, I think, when the target site is stagnant state
or something like that.
Anyway, how can I set the maximum waiting time to retrive that site.
Thinks....
|
|
|
|
|
Yes. See this article.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Your answer was very helpful.
|
|
|
|
|
I am kind-a-new in winsock programing (without MFC , but i want to create udp client server application.
I am looking for a way for a program to call my function when packet is received and i have found WSAAsyncSelect, but i dont want to have hidden window just to route messages. Is there any function, that would work on callbacks?
|
|
|
|
|
An alternative to windows messages is <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wsapiref_34aa.asp">WSAEventSelect</a> , which sets an event of your choice whenever some of the network events selected happens. If you want to call a function based on this, you'll have to set up a thread waiting for the event and calling the function appropriately --Winsock doesn't provide any automatic way of doing this, as far as I know.
Nevertheless, if your app is single-threaded and does have a message pump, then WSAAsyncSelect is probably a cleaner approach.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That is what i have looking for... well exactly, callback would be nicer, but that would be too easy
Thank you
|
|
|
|
|
From what i've read, making a window is the "regular" way of doing this with WSAAsyncSelect. It's really not difficult at all, infact, just cut and paste the code below into your project
if ((Window = MakeWorkerWindow()) == NULL)
return FALSE;
HWND MakeWorkerWindow(void)
{
WNDCLASS wndclass;
CHAR *ProviderClass = "NetworkWindow";
HWND Window;
char szError[128];
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)NetworkWindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = NULL;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = ProviderClass;
if (RegisterClass(&wndclass) == 0)
{
wsprintf(szError,"RegisterClass() failed with error %d\r\n", GetLastError());
MessageBox(NULL,szError,NULL,MB_OK);
return NULL;
}
// Create a window.
if ((Window = CreateWindow(
ProviderClass,
"",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
NULL,
NULL)) == NULL)
{
wsprintf(szError,"NetworkWindow Creation Failed #%d",GetLastError());
MessageBox(NULL,szError,NULL,MB_OK);
return NULL;
}
return Window;
}
|
|
|
|
|
Yeah, i know that method, but i hate creating hidden windows just to route messages and i DONT WANT TO DO THAT in a console program!
|
|
|
|
|
hi,
I have a handle to a bitmap and what to display it. Whta can be options?
karanba
|
|
|
|
|
Select it into a device context and the BitBlt it to the place you want it to be seen.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile.
- Jamie Hale, 17/4/2002
|
|
|
|
|
i used this method in OnInitDialog() & it's not working
CWnd *pWnd;
LOGFONT lf;
CFont font;
pWnd = GetDlgItem(IDC_STATIC_LINK);
pWnd->GetFont()->GetLogFont(&lf);
lf.lfUnderline = TRUE;
font.CreateFontIndirect(&lf);
pWnd->SetFont(&font);
any ideas?
|
|
|
|
|
override the OnCtlCOlor() message and set it there
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
coming soon: situations to avoid #38: "...and the dog was there too?"
|
|
|
|
|
It's working !! Thanx
|
|
|
|
|
How can I declare function pointer to be put into a map ??
like:
std::map
|
|
|
|
|
This should work:
typedef bool func(long, CDataBase*);
std::map<long, func*> mapLongToFunc; Though i suppose there's prolly a more concise way of doing it.
--------
And we die young.
Faster we run. Alice in Chains, We Die Young
|
|
|
|