Bonjour,
je souhaiterais faire une appli avec seulement un bouton.
Au depart le bouton affiche Start et lorsque l'on clique dessus il doit lancer l'exection d'une boucle et afficher Stop.
Si l'on clique sur Stop vous aurez compris qu'on arrete la boucle.
Cette boucle est en fait un Worker Thread donc j'ai fait ca :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 void CTestDlg::OnStartBtn() { if (m_bRunning == false){ m_bRunning = true; m_hThread = AfxBeginThread(thScanCarte, (void*)this); m_btnStart.SetWindowText( _T("Stop") ); } else{ m_btnStart.SetWindowText( _T("Start") ); m_bRunning = false; } }
Est ce que c'est ca ? Ca me parait bizarre de recreer le thread a chaque fois...Code:
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
31
32
33 UINT CTestDlg::thScanCarte( LPVOID pParam ) { CTestDlg* pThis = (CTestDlg*) pParam; USHORT status; CString s; bool bFlag = true; while(pThis->m_bRunning) { if (bFlag){ bFlag = false; pThis->m_btnStart.SetIcon(IDI_OK, CSize(16,16) ); } else{ bFlag = true; pThis->m_btnStart.SetIcon(IDI_NEUTRAL, CSize(16,16) ); } //AfxMessageBox(_T("ZOB")); if ( pThis->m_card.ReadCard() ){ s = pThis->m_card.GetString( _T("Prenom") ); AfxMessageBox(s); } Sleep(100); } AfxMessageBox(_T("Je sors du thread")); return 0; }