A question about GetDlgItem
-
Hi,Everyone: i create a project CFormView as its base class. i add "List Control" in the Mainform, and i use the "List Control" with code below: ----------------------------------------------------------------------- class CvcydcjView : public CFormView void CvcydcjView::OnInitialUpdate() { ... CListCtrl* pList = (CListCtrl*) GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40); ... } ----------------------------------------------------------------------- now i want to use the control in my other class, obviously i can't use that code to get the DlgItem, can anyone help me to solve the problem? -- use the Mainform Control in other class. Thank you so much! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
Hi,Everyone: i create a project CFormView as its base class. i add "List Control" in the Mainform, and i use the "List Control" with code below: ----------------------------------------------------------------------- class CvcydcjView : public CFormView void CvcydcjView::OnInitialUpdate() { ... CListCtrl* pList = (CListCtrl*) GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40); ... } ----------------------------------------------------------------------- now i want to use the control in my other class, obviously i can't use that code to get the DlgItem, can anyone help me to solve the problem? -- use the Mainform Control in other class. Thank you so much! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR.. -
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..Hi,Dear Rahim: first of all, thank you so much for your reply! as you said: Rahim Rattani wrote: CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); but i get these errors: ------------------------------------- error C2065: 'CMainFrame' : undeclared identifier .... and in my project i don't have CMainFrame Class cos it's Form based :( Do you have any other suggestions? Thx a million! :) (it's really lots of informations you provide!) - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..MessageBox("Put the code in the right way! :)")
Thx! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE -
Hi,Dear Rahim: first of all, thank you so much for your reply! as you said: Rahim Rattani wrote: CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); but i get these errors: ------------------------------------- error C2065: 'CMainFrame' : undeclared identifier .... and in my project i don't have CMainFrame Class cos it's Form based :( Do you have any other suggestions? Thx a million! :) (it's really lots of informations you provide!) - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
If you are workin on a dialog based application, the dialog is declared and created in InitInstance() of the Application class. Why dont u declare the dlg as public in the class, instead of InitInstance(). Create and display it in InitInstance but declare it as a public variable. Then you will be able to accessit anywhere as
theApp.yourDlgVariable;
..RR.. -
Hi,Everyone: i create a project CFormView as its base class. i add "List Control" in the Mainform, and i use the "List Control" with code below: ----------------------------------------------------------------------- class CvcydcjView : public CFormView void CvcydcjView::OnInitialUpdate() { ... CListCtrl* pList = (CListCtrl*) GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40); ... } ----------------------------------------------------------------------- now i want to use the control in my other class, obviously i can't use that code to get the DlgItem, can anyone help me to solve the problem? -- use the Mainform Control in other class. Thank you so much! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
If you are workin on a dialog based application, the dialog is declared and created in InitInstance() of the Application class. Why dont u declare the dlg as public in the class, instead of InitInstance(). Create and display it in InitInstance but declare it as a public variable. Then you will be able to accessit anywhere as
theApp.yourDlgVariable;
..RR..Rahim Rattani wrote: dialog based application it's a bit different. i created the project using single document and last step choose form-base, so i do have CvcydcjApp class as well as CvcydcjDoc & CvcydcjView. i don't know whether your method can be used in this case and how ? could you tell me the details. Thx a million! Best wishes! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
Rahim Rattani wrote: dialog based application it's a bit different. i created the project using single document and last step choose form-base, so i do have CvcydcjApp class as well as CvcydcjDoc & CvcydcjView. i don't know whether your method can be used in this case and how ? could you tell me the details. Thx a million! Best wishes! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
If you are using a SDI application, then you ould definitely have a CMainframe class (the one i mentioned in my first reply). CMainfrmae is the class derived from CFrameWnd, and without it u can cannot create a SDI application. Check it you will have a CMainFrame class in your application and let me know. The solution in my first reply should definitely work. Let me know if you have a class name CMainframe (or a class derived from CFrameWnd) ..RR..
-
If you are using a SDI application, then you ould definitely have a CMainframe class (the one i mentioned in my first reply). CMainfrmae is the class derived from CFrameWnd, and without it u can cannot create a SDI application. Check it you will have a CMainFrame class in your application and let me know. The solution in my first reply should definitely work. Let me know if you have a class name CMainframe (or a class derived from CFrameWnd) ..RR..
:sigh: i'm so sorry! i do have CMainframe Class! i'm so stupid! sorry! i'll try your first method! Thx a million!!!! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..You're my hero!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ^.^ :-D Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! it worked!!!!!!!!!!!!!!!!! ^.^ God Bless you!!!!!!! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..:laugh: :laugh: - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE
-
Can't you pass the control's pointer to the other class? "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
This is a really bad idea. It means the other class has knowledge about the details of the implementation of the representation, which is none of its business. This violates basic principles of object oriented programming, data abstraction, etc. Even the idea that it is a list control should be a secret from all other classes.
-
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..Hi,Rahim: Your code run very well in my class, thx! now i met some problem when it's running in a thread,
DWORD WINAPI CallOut(LPVOID lp) { ... CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(pchildWnd->GetSafeHwnd() != NULL) { ASSERT(pchildWnd->GetSafeHwnd() != NULL); if(pchildWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)pchildWnd; break; } pchildWnd = pchildWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL); }
when i debug, the program stopped at:while(pchildWnd->GetSafeHwnd() != NULL);
i create the thread using following code:m_hCallthread = CreateThread( NULL, // pointer to security attributes NULL, // initial thread stack size CallOut, // pointer to thread function NULL, // argument for new thread 0, // creation flags NULL // pointer to receive thread ID );
can u give me some suggestions? Thx! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE -
Hi,Rahim: Your code run very well in my class, thx! now i met some problem when it's running in a thread,
DWORD WINAPI CallOut(LPVOID lp) { ... CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(pchildWnd->GetSafeHwnd() != NULL) { ASSERT(pchildWnd->GetSafeHwnd() != NULL); if(pchildWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)pchildWnd; break; } pchildWnd = pchildWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL); }
when i debug, the program stopped at:while(pchildWnd->GetSafeHwnd() != NULL);
i create the thread using following code:m_hCallthread = CreateThread( NULL, // pointer to security attributes NULL, // initial thread stack size CallOut, // pointer to thread function NULL, // argument for new thread 0, // creation flags NULL // pointer to receive thread ID );
can u give me some suggestions? Thx! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVEWhat were the values in PMainFrmWnd and pChildWnd when the program broke up. Also tell me the how many times the while loop had processed when this problem came. Was it a ASSERTION or an unhandled exception. Also paste the stack trace. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
-
What were the values in PMainFrmWnd and pChildWnd when the program broke up. Also tell me the how many times the while loop had processed when this problem came. Was it a ASSERTION or an unhandled exception. Also paste the stack trace. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
Rahim Rattani wrote: PMainFrmWnd :0x00461300 at first is 0x00462d90 Rahim Rattani wrote: pChildWnd when the program broke up. is 0x00000000 Rahim Rattani wrote: how many times the while loop had processed when this problem came : it's 2 Rahim Rattani wrote: Was it a ASSERTION or an unhandled exception. yes, it's
ASSERT(pYourView != NULL);
the programme can't run intopYourView = (CvcydcjView*)pchildWnd;
Rahim Rattani wrote: stack trace. i'm so sorry i don't know how to get it... :sigh: Thank you soooooooooooo much! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE -
Rahim Rattani wrote: PMainFrmWnd :0x00461300 at first is 0x00462d90 Rahim Rattani wrote: pChildWnd when the program broke up. is 0x00000000 Rahim Rattani wrote: how many times the while loop had processed when this problem came : it's 2 Rahim Rattani wrote: Was it a ASSERTION or an unhandled exception. yes, it's
ASSERT(pYourView != NULL);
the programme can't run intopYourView = (CvcydcjView*)pchildWnd;
Rahim Rattani wrote: stack trace. i'm so sorry i don't know how to get it... :sigh: Thank you soooooooooooo much! - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVEI dont have a clue whats the problem. But still I woudl suggest that instead of obtaning a pointer to the view in a thread and working on it. You should obtain a pointer to it before initiating the thread and pass it to the thread as a parameter. I will consider it as a much better option. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
-
First Obtain the ptr of view class "CvcydcjView" as
CMainFrame* pMainFrmWnd = (CMainFrame*)AfxGetMainWnd(); ASSERT(pMainFrmWnd != NULL); CvcydcjView* pYourView = NULL; CWnd* pchildWnd = pMainFrmWnd->GetWindow(GW_CHILD); ASSERT(pchildWnd->GetSafeHwnd() != NULL); while(childWnd->GetSafeHwnd() != NULL) { ASSERT(childWnd->GetSafeHwnd() != NULL); if(childWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") { pYourView = (CvcydcjView*)childWnd; break; } childWnd = childWnd->GetWindow(GW_HWNDNEXT); } ASSERT(pYourView != NULL);
Now you have got ptr to your class you can call the functions asCListCtrl* pList = (CListCtrl*)pYourView->GetDlgItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
At the moment i dont remember whether GetDlgItem() is public or not. If its not public create your own function that should be public which calls GetDlgItem inside the class as The below is the public functionCWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); }
now call this function form your other class asCListCtrl* pList = (CListCtrl*)pYourView->getItem( IDC_LIST_MEM); pList->InsertColumn(0, "TestColumn", LVCFMT_CENTER,40);
..RR..Rahim Rattani wrote: The below is the public function CWnd* CvcydcjView::getItem(UINT p_nResourceID) { return GetDlgItem(p_nResourceID); } Hi,Dear Rahim:
//while(pchildWnd->GetSafeHwnd() != NULL) // { // ASSERT(pchildWnd->GetSafeHwnd() != NULL); // if(pchildWnd->GetRuntimeClass()->m_lpszClassName == "CvcydcjView") // { pYourView = (CvcydcjView*)pchildWnd; // break; // } // pchildWnd = pchildWnd->GetWindow(GW_HWNDNEXT); // }
then i can get pYourView rightly - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE -
I dont have a clue whats the problem. But still I woudl suggest that instead of obtaning a pointer to the view in a thread and working on it. You should obtain a pointer to it before initiating the thread and pass it to the thread as a parameter. I will consider it as a much better option. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
Thxs! a million,Rahim. You're so kind! so i'd love to ask you another question, your solutions are always Great!! Rahim Rattani wrote: before initiating the thread i think maybe there will be some diffiulties,we initialize the thread in view class. but that's ok, i think now we can use the control using your getitem method, so coooooooool! :laugh: now i got another question,wish you can take a look: i want to use message method, but i don't have a very clear idea about how to use it. here is the circumstance: there is a process running in my CvcydcjView:
int CvcydcjView::ReadRecord() { OpenDatabase(); CopytoMemory(); //when i finish this process, i want to sendmessage to the thread now it can start SendMessages(); }
DWORD WINAPI CallOut(LPVOID lp); { if(ReceiveMessageFromReadRecord) DoSomething(); else Wait(); }
i don't know how to write the code, if you can help, that will be very Great!!!!!!!! Thanks in advance!!!!!!!!!!! Best Wishes, - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE -
I dont have a clue whats the problem. But still I woudl suggest that instead of obtaning a pointer to the view in a thread and working on it. You should obtain a pointer to it before initiating the thread and pass it to the thread as a parameter. I will consider it as a much better option. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
:) - - - - - - - - - - - - - - - - - - - - - - - - - - Many nights we prayed with no proof anyone could hear, we were moving moutains long before we knew we could ! Yet now i'm standing here, although we know there's much to fear, hope seems like summer bird too swiftly flown away ... There can be miracles! When you believe, though hope is frail, it's hard to kill ! Who knows what miracles, you can achieve! When you believe, somehow you will ... YOU WILL WHEN YOU BELIEVE