|
how can i pass the dialog class's address..as in how should i write on the third argument of the createThread()
sorry to trouble again
Regards
afender
|
|
|
|
|
Anonymous wrote:
on the third argument of the createThread()
If you're using MFC inside of the worker thread then call AfxBeginThread to start it. It's the only way you can make MFC objects to acquire correctly the TLS data they use.
rechi
|
|
|
|
|
Simply by putting second parameter of AfxBeginThread as "this". For further process...please refere following replies for this question.
C.R.Naik
|
|
|
|
|
hi
below are the code i had modified
unsigned long __stdcall CProjectv1Dlg::ThreadFunc(void* lpvoid)
{
CProjectv1Dlg *myThis = (CProjectv1Dlg *)lpvoid;
while(1){
if( a == 0){
myThis->myThis = "read success";
myThis->UpdateData(FALSE);
}
}
}
now my problem lies on the myThis->UpdateData(FALSE), it seems i cannot directly use this function. Any other way to update the data?
thks again
afender
|
|
|
|
|
I supposed that ID of your dialog's Edit Box is IDC_EDIT_MYTHIS, then your problem can be solved by the following code :
unsigned long __stdcall CProjectv1Dlg::ThreadFunc(void* lpvoid)
{
CProjectv1Dlg *myThis = (CProjectv1Dlg *)lpvoid;
while(1){
if( a == 0){
//myThis->myThis = "read success";
//myThis->UpdateData(FALSE);
::SetWindowText(::GetDlgItem(myThis->m_hWnd, IDC_EDIT_MYTHIS), "read success");
}
}
}
Welcome
C.R.Naik
|
|
|
|
|
hi
below are the code i had modified
unsigned long __stdcall CProjectv1Dlg::ThreadFunc(void* lpvoid)
{
CProjectv1Dlg *myThis = (CProjectv1Dlg *)lpvoid;
while(1){
if( a == 0){
myThis->m_result = "read success";
myThis->UpdateData(FALSE);
}
}
}
now my problem lies on the myThis->UpdateData(FALSE), it seems i cannot directly use this function. Any other way to update the data?
thks again
afender
|
|
|
|
|
The problem should be that UpdateData is protected and can not be accessed from without the class. Thus you could add a public function to your dialog which calls UpdateData and changes the value of your member variable.
|
|
|
|
|
unsigned long __stdcall CProjectv1Dlg::ThreadFunc(void* lpvoid) <br />
{<br />
CProjectv1Dlg *myThis = (CProjectv1Dlg *)lpvoid;<br />
while(1){<br />
if( a == 0){<br />
myThis->display(); <br />
}<br />
}<br />
}<br />
<br />
void CProjectv1Dlg::display()<br />
{<br />
UpdateData(FALSE);<br />
}
is this what u means?
regards
afender
|
|
|
|
|
(This post has been edited to correct a stupid mistake on my part. See later follow-up for more information.)
Never update a window directly from a worker thread. You should also avoid using SendMessage from a worker thread to a window. Instead, use PostMessage and use a user defined message (WM_USER + x.)
In your example, you'll either need to pass a discrete value, which the dialog will then use to obtain the string itself and pass that as one of the parameters of the user message. Or put a critical section around any reading/writing of m_result.
|
|
|
|
|
i still not quite understand on how to do it.
ok, let say i put the PostThreadMessage() in the worker thread as follow
unsigned long __stdcall CProjectv1Dlg::ThreadFunc(void* lpVoid)
{
CProjectv1Dlg *myThis = (CProjectv1Dlg *)lpVoid;
while(1){
if(count == 0){
m_result += "success";
PostThreadMessage(myThis->TID, WM_USER + 0x10, 0, 0);
}
}
return 0;
}
where i use the
TID = GetCurrentThreadId();
so now the question is,
let say i want to update the edit box, how to determine the WM_USER + x? or just simply put a value in the specific range.
regards
afender
|
|
|
|
|
Unfortunately, I mixed two solutions together and blundered. You shouldn't use PostThreadMessage, but rather call the PostMessage of the dialog from the thread. (i.e. mythis->PostMessage(WM_USER + 0x10....)
The value for your user message can be anything, just make sure it's unique (I've made that mistake before.)
You then need to make a custom handler for the Dialog for that specific user message. To make the dialog flexible, in the past I've passed and IDS_ define as the WPARAM (or LPARAM) and then the message handler simply loads that string and updates the edit control. (If you know that only the thread will be setting m_result, then you can get away without a critical section, but that may come back to haunt you someday.)
Here's a link to help explain that.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFCNOTES_TN006.asp[^]
|
|
|
|
|
hei, it works
Thks for the help, really appreciate it!!
regards,
afender
|
|
|
|
|
Hello All,
I have a question. Right now when I create a modeless dialog window, it appears over the parent dialog window. This is fine, but when I click on the parent dialog window, it does not appear over the child window. Let me set this up a little better.
I am using Visual C++ 6.0
I have a Dialog window called EntryWindow
I have a Dialog Window called ResultWindow
EntryWindow creates ResultWindow when you click on a button (called calculate)
So ResultWindow opens fine, but when I click on EntryWindow again, it STAYS underneath ResultWindow. How do I make it so that Either Dialog window I click on shows up on top?
Please help me out with this, I'd love to learn hwo to do this.
Thanks,
NickOne
|
|
|
|
|
Post the code you are using to do this so we can see if we can spot any problems.
Dave
|
|
|
|
|
Hi,
It's probably not possible, but, i'm trying to declare a static member function of a class with "C" linkage.
Why? cos i'm trying to have a fortran function call this member function of a class, and the first arg is a pointer to the class.
I know I can make this just a global function rather than a member function, but that doesn't seem right to me.
Here's what I've tried (which doesn't work)
extern "C" static void __stdcall DC_MOVE (CGraphView*& pGraphView, float *x, float *y);
I need extern "C" to get the compiler to decorate the names in a way that fortran can understand. __stdcall is the calling convention that fortran uses.
Any ideas? or can someone confirm that this is not possible?
Thanks
Jon
#include <beer.h>
|
|
|
|
|
You will probably need to define the function in a DEF file for the function name to be mangled in the way that you want. Or is it that your program isn't building properly?
Chris Richardson
C/C++ Include Finder[^]
|
|
|
|
|
I think you will have to remove all of the name decorations for the entire class, I dont think that you can do that for just one function inside of the class.
So you will need to do something like this:
extern "C" CGraphView
{
public:
...
static void __stdcall DC_MOVE (CGraphView*& pGraphView, float *x, float *y);
};
The only problem with this is that you will not be able to use function overloading in your class. So if that is a problem, then you may want to make it a global function.
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!
|
|
|
|
|
I will try that; i'm not going to be using function overloading (this is a fairly lightweight class).
Only thing I worry about is that class CGraphView is derived from CView and implements dynamic creation. Which is a lot of hidden code that might break it.
#include <beer.h>
|
|
|
|
|
Hiya I am just wondering if anyone has come across this problem.
I have an SQL database which I read and write to. I write a number of items( Number, Planet Name )the first time to the database fine. The items go in fine and in order into their columns:
e.g 1. Jupitar 2. Venus 3. Mars 4. Earth
Then when I modify the table in some way, e.g like deleting all the items, and refill the table with the exact same code, they come out in a different order e.g
3. Mars 1. Jupitar 4. Earth 2. Venus
And I definitely have not changed the code and they are all definitely deleted. WEIRD!! I have tried the same in ACCESS and works fine every time, only wrong in SQL.
Does anyone have any ideas on this??
grahamoj.
|
|
|
|
|
It's not wrong at all. When you select records, they are returned in an arbitrary order unless you explicitly request a different order.
instead of "select * from mytable", try "select * from mytable order by [number]"
that will get you consistant results every time.
Jon
#include <beer.h>
|
|
|
|
|
|
Handling WM_CTLCOLOR should do it. If not, try WN_ERASEBKGND.
|
|
|
|
|
I've tried it with WM_CTLCOLOR but unsuccessful. Now I will try with WN_ERASEBKGND, thanks )
|
|
|
|
|
Hi,
I'm new to Carchive and Serialization so i will try to be as detailed as possible with my question.
I currently have a dialog box with a CListCtrl and what i want to do is serialize the CListCtrl. From what i have read , serialization will allow you to recreate your object/class based on storing member variables. I find code where they do this for one variable at a time i.e.
archive << m_bMyVariable;
etc...
i don;t know about you but i do not find this useful at all... i could write all this code myself...
what is special about the serialize() function?
what does IMPLEMENT_SERIAL do?
what i'm trying to do is take a "snapshot" of my list control with all its items, the currently selected item, the currently checked items etc... and save it to file so i can reload that state when i show the dialog box again.
now I could do this all manually but i thought i had seen something useful in serialization.
am i braking up the wrong tree?
thank you in advance,
|
|
|
|
|
If I click on my item in the CListCTrl, I cycle back to the red line THREE times (just from one click). I thought one click means the itemchnaged function runs ONCE...?
void CSearchView::OnItemchangedListctrlkeys(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
return;
<code> m_optionsListBox.DeleteAllItems();</code> this breakpoint is stepped into THREE times and after the third time the UI shows up. Why three times and not just once?
Appreciate your help,
ns
|
|
|
|