|
Was a bit pissed about something....Now I feel much better!
Oh, glad to be helpful in such a weird way
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
yes. but it's not nice.
http://www.codeproject.com/lounge.asp?forumid=1159&app=50&fr=101&select=126729#xx126729xx
-c
Smaller Animals Software, Inc.
You're the icing - on the cake - on the table - at my wake. Modest Mouse
|
|
|
|
|
Here is a code snippet :
class CTest
{
public:
void test1(CString t)
{
AfxMessageBox( _T("test1: ") + t);
}
void test2(CString t)
{
AfxMessageBox( _T("test2: ") +t);
}
};
//test
............
typedef void (CTest::*method_ptr)(CString);
CTest x;
method_ptr fn;
fn = &CTest::test1;
(x.*fn)("xyz");
fn = &CTest::test2;
(x.*fn)("xyz");
...........
|
|
|
|
|
#include <stdio.h>
class A
{
public:
void abc()
{
printf("hello world");
}
};
int main(int argc, char* argv[])
{
void (A::*pf)()=&A::abc;
A a;
(a.*pf)();
return 0;
}
Nish
[Signature temporarily down]
|
|
|
|
|
So basicly there is not a way to have an indpendant type of function pointer that can work for any function in any class?
I am trying to implement a command list where when the user type in a command it searches through its list, finds it and then executes the appropriate function.
Thanks.
Steve
Not all who wander are lost...
|
|
|
|
|
Steve Severance wrote:
So basicly there is not a way to have an indpendant type of function pointer that can work for any function in any class?
I am trying to implement a command list where when the user type in a command it searches through its list, finds it and then executes the appropriate function
Actually you can point the same function pointer to any number of functions as long as they all have the same prototype [means same argument types and return value]
Nish
[Signature temporarily down]
|
|
|
|
|
would it be possible to use a base class like
class CRoot
{
//root class
};
class MyClass : public CRoot
{
void MyFunc();
};
and then
void (CRoot::*pf)()=&CMyClass::MyFunc;
MyClass a;
(a.*pf)();
Steve
Not all who wander are lost...
|
|
|
|
|
I open a window A and from this, another window B for which the window A is the parent window. In window B there is a button with a label "Start" that starts the execution of the thread "Train". This thread must get data from the parent window and perform some calculations, and finally, update some controls in window A. I use AfxBeginThread (Train, this) from B window and inside the thread function I get a pointer to the parent window by means of GetParent function. However this does not work. Can anyone help me?
|
|
|
|
|
Can you show some code snippets?
Nish
[Signature temporarily down]
|
|
|
|
|
In the lack of more info, I'd venture to say the problem is that you are trying to call some member function (or use some member variable) of the CWnd * returned by GetParent (possibly cast to CAWnd * or whatever your class is named). Is this right? If so, then the problem is that that CWnd * is not actually the original object; this is due to inherent limitations of MFC with respect to multithreading. To solve the problem, pass the thread a pointer to A instead of a pointer to B (and have A store somehow a pointer to B so that you have access to both windows).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
All threads in MFC has own CWnd-HWND map and it don't initialize while you create new thread due to perfomance reason. A common solution is to put HWND in thread-parameters and in child thread should construct CWnd by means CWnd::FromHandle function.
Good luck
|
|
|
|
|
I finally solved the problem by using the following approach:
In the cpp file of the child window B I declared a global object of type "window A". Then in the InitDialog member function of window B I called the GetParent function and I copied its return to the global object of type "window A". In the next step I used this global object from my thread function and it worked !! I also noticed that the GetParent function it works if it is called from the thread function but only the MFC based procedures of the parent window are accessible - in this way I managed to disable a button of the parent window A from the thread function of the child window B. However if the parent window A has additional member functions (non MFC based)they are not accessible in this way - but they are, if we use the method of the global object described above.
Thanks all of you for your response
Athanasios Margaris
University of Macedonia
Dept. of Applied Informatics
Thessaloniki Greece
Web Site : http://www.neural.uom.gr (most in Greek)
|
|
|
|
|
A CWnd is really two distinct entities: a C++ object which you access using a CWnd* (typically this), and the Window object created by the system, which you access using a window hande (HWND). In order for MFC to make these two separate entities work like one, it must frequently find the HWND associated with a particular CWnd object, and or find the CWnd object associated with a particular HWND.
The first operation, mapping from CWnd to the associated HWND is easy (just look up the m_hWnd member variable). This works fine in any thread.
The second mapping, from HWND to CWnd* uses what is know as a handle map (a table which tracks which HWNDs were created by CWnd objets in that thread). This handle map is thread specific. Furthermore, since you can create HWNDs without even creating a CWnd object (e.g. dialog controls created by the dialog template), MFC sometimes creates generic temporary CWnd objects which you can use for the duration of a message handler to access these HWNDs via a CWnd object.
The GetParent() member function just calls the Windows API funtion ::GetParent (m_hWnd), which returns the HWND of the parent. MFC then uses the (thread specific) handle maps to get a CWnd object associated with the parent HWND. If the parent window was not created via a CWnd object in the same thread, this will a temporary generic CWnd object. So in your case, when the second thread calls GetParent() it gets a pointer to a temporary generic CWnd and NOT the CMyCWndDerivedClass object that created the parent HWND in the first thread. If you cast the CWnd pointer to a pointer your derived class, you'll acess whatever memory just happens to sit after the temporary CWnd object.
You can confirm this with
CWmd *pWnd = GetParent ();
ASSERT_KINDOF (CMyCWndDerivedClass, pWnd);
This will work in your main thread, but fail in your derived thread.
When working with multiple threads, it is much simpler to have only the original main thread responsible for the GUI. Worker threads can update data, and then use ::PostMessage() with an HWND to send a message the main thread (that created the HWND) that it should update its appearance. Since all windows messages are handled by the single GUI thread that creates all HWNDs, the handle maps work just as expected in a single threaded application. It you let multiple threads deal with HWNDs and CWnd objects directly, then you need to understand temporary and permanent handle maps AND when and how they are used by MFC. Believe me, the first approach is much simpler.
Stephen C. Steel
Kerr Vayne Systems Ltd.
|
|
|
|
|
Hi,
I'm trying to change some controls size of my dialog when I maximize/minimize it. But I don't know which are exactly the steps I must do to change those controls width and heigth!! It's not difficult but I can't manage myself!!
Thanks in advance,
Edgar
|
|
|
|
|
You could use the method SetWindowPos
Call this member function to change the size, position, and Z-order of child, pop-up, and top-level windows.
BOOL SetWindowPos(
const CWnd* pWndInsertAfter,
int x,
int y,
int cx,
int cy,
UINT nFlags
);
Probably you'll have to obtain a pointer to the control with
GetDlgItem()
The GetDlgItem function retrieves a handle to a control in the specified dialog box.
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Hope this helps.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Use SetWindowsPlacement....
Regards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
Computer analyst to programmer: "You start coding. I'll go find out what they want."
|
|
|
|
|
There is a very nice and easy-to-use class on CP.
/moliate
|
|
|
|
|
Incredible! how many simple and powerfull!!!
Thanks a lot!
|
|
|
|
|
I want to be able to tell the visual studio editor (VC++ specifically) to open a file and move to a specific line, from and external (not and add-in or macro) MFC program.
Can anyone suggest somewhere to find examples on how to do this... (I've looked in MSDN but it seems to be only concerned with VB, Add-ins and macros).
Thanks...
Blade[DMS]
|
|
|
|
|
Yesterday I asked question about how can use "Anchor property" in MFC,some guyes tell me
about some articles (3 articles) in CP.I checked them,all of them are for VC6 and
all of them have some problems in VS.NET .Is there any other way for using Anchor propert?
Or is there anybody use those articles in VS.NET?Maybe I made mistake somewhere?
I used these articles:
ResizableLib By Paolo Messina
Layout Manager for Dialogs, Formviews, DialogBars and PropertyPages By Erwin Tratar
ResizableFormView By Paolo Messina
Any suggestion would be appreciataed.
thanx
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I have an MDI app that has multiple document templates. I create a pointer to each and then when I want to activate a Doc/View I use:
theApp.m_ptSCR->OpenDocumentFile(NULL);
This works perfectly for the default behavior of the views, but I need to be able to pass arguments to have a different behavior occur in the OnInitialUpdate function in my view classes. How do I get the parameters passed through to the view?
Ed
|
|
|
|
|
Probably the easiest way is to store additional information in your app object before calling OpenDocumentFile. View could access this using AfxGetApp (with proper static_cast) during OnInitialUpdate.
Other possible location for this sort of data is static member of CYourView.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I am still somewhat new to this so bear with me.
In my main app I declare some variables as static, then in my view I can use AfxGetApp() to get a pointer to the main app and access the variables. Correct? This will work perfectly but the static_cast is the part I don't have a good handle on. What would the code be in my view to access a variable declared in my main app as
static CString m_sMessage;
Thanks so much for your help.
Ed
|
|
|
|
|
(Just an approach among others, by no way standard technique) Add some variables to your CDocTemplate -derived class to hold this initialization params. Set them before the call to OpenDocumentFile . In OnInitialUpdate , the view is already attached to the document, so by static_cast<CMyDocTemplate *>(GetDocument()->GetDocTemplate()) you get access to the params.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If I do it this way, how do I add variables to CMultiDocTemplate? It doesn't give me the option to derive from it.
Ed
|
|
|
|