首页 > 编程语言 > 详细

创建线程检查按钮的状态

时间:2020-03-12 13:07:08      阅读:72      评论:0      收藏:0      [点我收藏+]
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;

 

创建线程检查按钮的状态

原文:https://www.cnblogs.com/strive-sun/p/12468037.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!