|
Sweet, thanks a lot man. I might have more questions, but i'm good for now.
|
|
|
|
|
|
I've created a Dialog that after some input collects data until the buffer is full or the user click on the Stop button.
The problem I'm having is I have a while loop the does the data collection code and once my gui has entered this loop all buttons in the dialog box have no functionality... (I can't click on anything). How would I check to see if the user has clicked on the "stop" button?
At 1st I thought maybe:
<br />
while( ... || ... || (m_nStopBtn.GetCheck() )<br />
{<br />
...<br />
}<br />
but that didn't work since the gui won't let me click on the stop button...
What could I be doing wrong?
Thanks,
Kitty5
|
|
|
|
|
you shouldn't put huge processes into the GUI thread...
move that loop into a worker thread to avoid the GUI to be frozen
|
|
|
|
|
You beat me to that answer :P
Also, make sure you use proper synchronization objects when doing this (do NOT just try to check a boolean variable each iteration of the loop to see if you should stop!).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
:->
Zac Howland wrote: NOT just try to check a boolean variable each iteration of the loop to see if you should stop!
of course
|
|
|
|
|
pardon my stupidity but....
Zac Howland wrote: proper synchronization objects
?
Thanks,
Kitty5
|
|
|
|
|
zac meant that as several threads access the same memory (see my other answer for the beginning of the discussion), two (or more) threads can access and modify the same variable at the same time.
very bad idea !!!
the solution for this is to "synchronize" the objects that are shared to avoid such problems/
google for semaphores and/or mutex for example
|
|
|
|
|
Basically, what you will want is to create a worker thread (as mentioned above). As part of the creation, you will want to pass in a variable that contains a handle to an event (typically, you will want to pass much more than just that, so a structure/class is created to hold everything you need to pass and then you pass a pointer to that object to the thread you are creating). Each iteration (or some on some interval) of your loop, your worker thread will call WaitForSingleObject and check to see if the event is signaled. If it is not, it continues doing its thing. During the whole loop, you should lock the data section you will be writing to using at least one critical section (which is a form of semaphore that Windows gives you). This way, your GUI thread (or any other thread for that matter -- all of which should also be using critical sections to access the shared data) cannot try to read/write to the memory that you are still loading.
If all of that sounds greek to you, read up on multithreaded programming in C/C++ (lots of good articles on here and Google can be a great help as well). Unless you are going to be working with other OS's, you can focus your search to Windows specific articles.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm new with creating MFC Application GUIs... please pardon the stupid question that follows....
What do you mean when you say:
toxcct wrote: move that loop into a worker thread to avoid the GUI to be frozen
?
Do I create a separate class for the worker thread and have the GUI call it?
The while loop is using member variables of the GUI...(i.e. checking to see whatever user inputs are.
thanks so much,
Kitty5
|
|
|
|
|
actually, the code is already executing in a thread (threads are some executing parts managed by the system). when you put the loop in the event handler, the execution leaves the event handler only when the loop exits and all the instructions where executed.
the problem with suc a design is that other event handlers (such as a button click - yeah, your stop for example) are pushed in the application events stack, but not poped until the current event is not finished.
then, what you can do for that is saying to the system that the loop will be executed in parallel. i mean, the event handler starts the loop, but doesn't wait for its end.
the system doesn't bother if the loop is using member variabless or not, because threads of a same process share the same memory...
|
|
|
|
|
I think you meant to say queue instead of stack
|
|
|
|
|
See here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
AfxBeginThread()
windows platform: process is comprised of main thread (UI thread on client-side) and can spawn additional threads (UI and/or worker) typically single cpu can process one thread any given moment and in this example spawn a worker thread to process data
Kuphryn
|
|
|
|
|
Thanks everyone!
All the answers have been a great help!
now I've got a lot of reading ahead of me!
Kitty5
|
|
|
|
|
|
I do agree that ideally you should employ the techniques suggested above, using worker threads. But sometimes a person does not have the time (or experience) for this route to be feasable.
I often use the pump message technique (equivalent in VB as DoEvents()) to prevent the UI freezing and also allow the user to interrupt lengthy sessions.
Have a look at the FAQ[^], under section
4.3 I have a dialog that does some lengthy processing, and I need to have a Cancel button so the user can abort the processing. How do I get the Cancel button to work?
I Dream of Absolute Zero
|
|
|
|
|
RChin wrote: I often use the pump message technique (equivalent in VB as DoEvents()) to prevent the UI freezing and also allow the user to interrupt lengthy sessions.
While I can understand not wanting to create tons of threads all over the place, creating what amounts to message pumps all over the place is a much worse practice and should be avoided (even in VB).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
With some tinkering, I got Group View working for a list view control in report mode (e.g. the letter-heading-separators in XP-Explorer-"My Computer")
However, LVM_SORTITEMSEX doesn't yield a result. The comparison callback function gets called alright, but there's no change in item order.
Google doesn't yield much. Any experiences / tips?
|
|
|
|
|
hi all
I am creating tool tip for a button by using following code.
void CreateMyTooltip(HWND hwnd)
{
HWND hwndTT;
TOOLINFO ti;
LPTSTR lptstr = (LPTSTR)"This is my button";
RECT rect;
hwndTT = CreateWindowEx(NULL,
TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_BALLOON |
TTS_ALWAYSTIP, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
SetWindowPos(hwndTT,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE |
SWP_NOACTIVATE);
GetClientRect (hwnd, &rect);
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS | TTF_TRANSPARENT;
ti.hwnd = hwnd;
ti.hinst = NULL;
ti.uId = IDC_BUTTON1; // To this button i am adding tooltip
ti.lpszText = lptstr;
ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
}
when i moved my mouse on the button, instead of tool tip message "This is my button" i am getting |||||||||||, rectangular boxes.
I am new to win32 api'
thanks for ur valuable suggestions
Manjunath S
GESL
Bangalore
|
|
|
|
|
You are trying to build a Unicode application, but the string you are passing is ANSI. You have two choices: 1) build an ANSI/MBCS app; or 2) change this code line
LPTSTR lptstr = (LPTSTR)"This is my button";
to
LPTSTR lptstr = (LPTSTR)_T("This is my button");
Best wishes,
Hans
|
|
|
|
|
I am building an application in which i want to show the back ground of selected cell in a different color say red. i have used onLeave and OnEnter events of the grid to achieve that. in the onleave event handler i change the background of old selected cel to white and in the onenter i change the bkcolor of cell to red.
so the bkcolor of cell left is changed to white as needed and the cell to which user is moving becomes red. but this cell bkground is not set if the first selection by the user is cell(0,0)
it works fine unless the first selection by the user is not
cell(0,0) if user select cell(0,0) as first selection then its color is not changed. but if the user selects some other cell then its color is changed and selecting now cell(0,0) also changes its bkcolor.
|
|
|
|
|
Hello Everyone,
This is my first attempt at doing anything with C++.
I'm trying to create a C++ DLL using Visual C++ 2005 Express. The idea is to be able to call the functions in this DLL from an access application.
After trawling for days, I now have a DLL that compiles and seems to work fine on the PC where it was developed.
When I put my application on a different PC, I get a runtime error 48 when trying to load the DLL.
The error text is 'File not Found' when searching for my DLL, but my investigation has show that this is actually a DLL loading error. After adding debugging code, I find that the LoadLibrary error is 0.
I have tried rebuilding the DLL, rewriting it and receive the same error '48' every time whenever I try to run the DLL functions on other machines, despite everything being fine on the dev box.
Does anyone have any ideas?
Should I be shipping more than just the DLL to other machines?
Thanks in advance.
G
|
|
|
|
|
Wheres your dll file(path) in current directory from your app or in windows directory
|
|
|
|
|
Where are you installing the DLL on the other machines? The DLL needs to be either in the same directory as the calling executable (Access in the case) or in the Windows path. Are you using a library in your DLL? (i.e. MFC) If so are you using static linking or dynamic linking? Any dynamically linked library needs its DLL to follow the same rules, in the same directory as the executable or in the windows path.
|
|
|
|