Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
In my MFC application, I've created the two tabbed control ( Tab1 & Tab2 ) using CPropertyPage & CPropertySheet. In Tab1 am having a static variable (IDC_SELL) & during runtime i need to change the label of the variable. My snipnet code looks like this:
C++
UINT Thread(LPVOID lParam)
{
  //SampleApp --> Current MFC Application window.
  HWND hWnd = ::FindWindow(0,"SampleApp");

  while(1)
  {
    // Other stuffs ...
   
    ::SetDlgItemText(hWnd,IDC_SELL,"Hello");

  }
   return(1);
}

void CTab1Dlg :: OnButtonOK()
{
  AfxBeginThread(Thread,0);
}


With this code, the label IDC_SELL doesn't change to Hello. But when i code like this:
C++
void CTab1Dlg :: OnButtonOk()
{
 SetDlgItemText(IDC_SELL,"Hello");
}

This works pretty well... I tried to create a thread in class like this:

C++
//CTab1Dlg.h
class CTab1Dlg : public CPropertyPage
{
public:
  static UINT Thread(LPVOID lParam);
}
//CTablDlg.cpp
UINT CTab1Dlg :: Thread(LPVOID lParam)
{
while(1)
  {
    // Other stuffs ...
SetDlgItemText(IDC_SELL,"Hello"); // Here SetDlgItemText Crashes stating that m_hWnd is NULL.
  }
   return(1);
}


Please, Can anyone suggest me how to use SetDlgItemText globally in PropertyPages.

Thank you All.
Posted

1 solution

Does hWnd (in ::SetDlgItemText(hWnd,IDC_SELL,"Hello");) is the handle of the CTab1Dlg window?


The call of SetDlgItemText(IDC_SELL,"Hello"); inside CTab1Dlg, calls the global ::SetDlgItemText function with the handle of the CTab1Dlg window and, the same parameters as provided to the SetDlgItemText function.


Try to find the window of CTab1Dlg and use its handle.

 
Share this answer
 
Comments
Guru_C++ 19-Feb-13 2:07am    
No.. hWnd is the handle of the Main MFC application window. I will try to find the window of the CTab1Dlg.. Is there any API's to find the window of Property pages ? Am not sure, Recently i 've learnt the Property pages & implementing it .
Shmuel Zang 19-Feb-13 2:34am    
You can provide the window's handle in the thread's parameter (lParam). Try to start the thread at a point when the m_hWnd of the dialog has already been initialized (like the OnInitDialog function), provide m_hWnd in the thread's parameter and use the global ::SetDlgItemText function with the provided window's handle.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900