|
-
Dec 14th, 2002, 08:02 PM
#1
Thread Starter
Addicted Member
Accessing members of a dlg class from outside of it
Lets say I have a Dialog called Cdlg. And one of its member is a CButton called bButton. How would I access a function thats a member of bButton such as GetWindowText from outside of the Cdlg class, like a thread.
-
Dec 14th, 2002, 08:41 PM
#2
It's a bad idea manipulating MFC objects from a different thread than they were created with. Sooner or later there'll be an assertion fault.
But anything else, simply make the sub-object public. If you have a reference or pointer to the dialog you can then access the sub-object through it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 14th, 2002, 08:43 PM
#3
Thread Starter
Addicted Member
But looking through the code (The core for the App was made by the wizard I don't know much about MFC) I dont see any instance of the actual dialog being declared, at least not a global one that I can access outside of the Applications class.
-
Dec 15th, 2002, 05:06 AM
#4
Then you'll have to declare one.
If this is a dialog-based app the dialog class instance is a local variable of CYourApp::InitInstance(). You need to add a CYourDlg& variable in a place you can access it globally and set it to this dialog instance:
Code:
CYourDlg dlg;
g_dlgref = dlg;
dlg.DoModal();
//...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 15th, 2002, 01:36 PM
#5
Thread Starter
Addicted Member
What is g_dlgref? And wont dlg.DoModal() make another dialog appear on the screen?
-
Dec 15th, 2002, 05:34 PM
#6
Thread Starter
Addicted Member
Ye you were right I got a assertion fault when I moved the mouse over the form. So this doesn't help me since I need a way to get the caption of a button and add items to a list in report view from the thread. How could I do this?
-
Dec 15th, 2002, 07:00 PM
#7
Pass the HWND of the dialog to the new thread and create a local CWnd object there (CWnd::FromHandle or better CWnd::Attach).
Then use the standard API wrappers for GetDlgItem etc. to get the button and use SetWindowText to change its text. Same goes for the list view. Create a local CListCtrl object and use CWnd::Attach to attach the HWND of the list view control to it. Then you can use the member functions to manipulate it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 15th, 2002, 10:17 PM
#8
Thread Starter
Addicted Member
Could I create a local CmyDlg object and then use CWnd::Attach to attack it to the dialog and then use it to manipulate the controls on the dialog?
-
Dec 16th, 2002, 05:37 AM
#9
I'm not sure. I've never tried.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 16th, 2002, 04:12 PM
#10
Thread Starter
Addicted Member
How could I get the handle for the window in an MFC app?
-
Dec 16th, 2002, 05:21 PM
#11
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 16th, 2002, 06:19 PM
#12
Thread Starter
Addicted Member
I tried this and suprise suprise got another one of our lovely assertion faults:
Code:
AfxBeginThread(ScanThread, GetSafeHwnd());
In the thread:
Code:
CmyDlg dlg;
dlg.Attach((HWND)pParam);
-
Dec 16th, 2002, 07:23 PM
#13
It asserts in the Attach function?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 16th, 2002, 08:10 PM
#14
Thread Starter
Addicted Member
-
Dec 16th, 2002, 08:56 PM
#15
Thread Starter
Addicted Member
Ok, I kinda got it to work, at least when I use _beginthread to start the thread.
-
Dec 17th, 2002, 05:59 AM
#16
Should still be AfxCreateThread in an MFC app...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 17th, 2002, 03:44 PM
#17
Thread Starter
Addicted Member
How bad is it that I'm using _beginthread instead? Any ideas why AfxBeginThread wouldn't work? It seemed to be passing the hwnd parameter wrong.
-
Dec 17th, 2002, 05:35 PM
#18
AfxBeginThread creates a CWinThread object, which does some initializing in its constructor.
MFC 7.0 doesn't seem to rely on its usage, but you never no.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|