Hello,
J'ai eu ce problème et j'ai utilisé un message personnalisé, je ne sais pas si c'est la meilleure solution mais ça marche bien.
J'ai défini un ID pour mon message (MainFrm.h):
#define WM_STATUS_CHANGE WM_USER+100
(voir http://cpp.developpez.com/faq/vc/?pa...PrivateMessage)
Ensuite j'ai défini une fonction qui intercepte le message dans CMainFrm.cpp.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
//{{AFX_MSG_MAP(CMainFrame)
//}}AFX_MSG_MAP
ON_WM_CREATE()
...
//Private message
ON_MESSAGE(WM_STATUS_CHANGE, &CMainFrame::OnStatusChange)
END_MESSAGE_MAP()
...
//ON STATUS CHANGE MESSAGE
//This message is received from other class for change Status bar text
// wparam [in]: Contains the string for update the status bar
// lparam [in]: Contains the status bar pane index to update.
long CMainFrame::OnStatusChange(WPARAM wparam,LPARAM lparam)
{
//Get the string
CString *stStatus = (CString*) wparam;
//get the index
int iIndex = (int) lparam;
//Check parameters and, if there are OK, update the status bar
if(!stStatus->IsEmpty() && (iIndex >= ST_STATUS) && (iIndex <= ST_ATR))
this->SetStatus(*stStatus, iIndex);
return 0L;
} |
Voici "l'appel" depuis une autre fonction, il faut préalablement récuperer un pointeur sur la MainFrame afin de pouvoir lui envoyer un message, d'autres possibilités sont dispos dans la FAQ.
1 2 3 4 5 6 7 8 9
|
//Get a pointer to the mainframe for send message
m_pTheFrame = (CMainFrame*)( AfxGetMainWnd()) ;
if(m_pTheFrame != NULL)
{
//post message
m_csString = "Text à mettre dans la status bar";
m_pTheFrame->PostMessageA(WM_STATUS_CHANGE, (WPARAM)&m_csString, STATUS_BAR_INDEX1);
} |
Voici encore le code de ma fonction SetStatus (que j'aurais pu appelé SetStatusText si j'étais un bon programmeur
):
Tu pourra noter que j'ai ajouter un flag qui se met à TRUE uniquement lorsque la barre de status est crée ( dans CMainFrame::OnCreate), afin d'éviter une erreur si un appel a SetStatus est fait trop rapidement.
1 2 3 4 5 6 7 8 9 10 11 12
|
void CMainFrame::SetStatus(CString st, int iIndex)
{
if(!m_bIsStatusBarReady) return; //Flag set to TRUE when status bar is created
//Ici tu peux placer du code pour éventuellement modifier le texte
//dans un certain format, vérifier la validité de l'index,
//ou encore d'autres traitements.
m_wndStatusBar.SetPaneText(iIndex, st);
} |
En ésperant avoir pu t'aider. Désolé pour la conjugaison et l'orthographe, j'ai écrit ça rapidement
Partager