Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
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:
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:
void CTab1Dlg :: OnButtonOk()
{
 SetDlgItemText(IDC_SELL,"Hello");
}
This works pretty well... I tried to create a thread in class like this:
 
//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 18-Feb-13 19:50pm
Guru_C++1.2K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.

  Permalink  
Comments
Guru_C++ at 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 at 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)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 169
1 George Jonsson 145
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100