zoukankan      html  css  js  c++  java
  • 创建线程检查按钮的状态

    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
  • 相关阅读:
    Linux网络基础配置
    UVA 116 Unidirectional TSP(dp + 数塔问题)
    修改Hosts文件
    倒排索引
    可以把阿里云上面的一些介绍和视频都看看
    练练脑,继续过Hard题目
    explicit的用法
    auto_ptr的使用和注意
    我写的快排程序
    快速排序、查第k大
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12468037.html
Copyright © 2011-2022 走看看