DWORD WINAPI ThreadFunction( LPVOID lpParam ) { (void)lpParam; //make happy compiler for unused variable while (TRUE) //Once created the thread runs always { //If checked reads usb for each iteration if(SendDlgItemMessage(hWnd,START_BUTTON,BM_GETCHECK ,0,0)== BST_CHECKED) { char* var = USB_Read(); //Get data from the sensor SetWindowText(hLux, var); //Display the data Sleep(1); //Why this? to don't have a furious CPU usage } } } ..... //Winmain DWORD dwThreadId; //thread ID in case you'll need it //Create and start the thread CreateThread( NULL, // default security attributes 0, // use default stack size ThreadFunction, // thread function name NULL, // argument to thread function 0, // use default creation flags &dwThreadId); // returns the thread identifier ...... case WM_COMMAND: switch (wp) { case START_BUTTON: printf("START_BUTTON"); if(SendDlgItemMessage(hWnd,START_BUTTON,BM_GETCHECK ,0,0)== BST_CHECKED) SendDlgItemMessage(hWnd,START_BUTTON,BM_SETCHECK ,BST_UNCHECKED, 0); else SendDlgItemMessage(hWnd,START_BUTTON,BM_SETCHECK ,BST_CHECKED, 0); break; } break;
也可以使用
SendMessage(hwndButtonPollFlag, BM_SETCHECK, BST_CHECKED, 0);
代替
SendDlgItemMessage
原文链接: https://www.cnblogs.com/strive-sun/p/12468037.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/404983
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!