如何给一个窗口msg优先于其他窗口msgs(这样一个窗口msg不能打断它)(c ++)

时间:2014-08-19 19:25:56

标签: c++ winapi message-queue i2c

我不确定如何说出这个问题,所以希望这是有道理的......

我有一个GUI工作,从板上读取值,并在窗口中显示它们。这个窗口也有一个菜单。我的问题是,当我点击一个菜单项时,它似乎在完成之前跳出了我的更新功能,这让我从我的电路板发出通信错误(因为在切换到菜单处理之前命令没有完成) 。问题是间歇性的,因为在更新功能运行时我并不总是单击菜单。

其他一些信息: 使用以下

定期发送Update功能

PostMessage(hwnd,WM_COMMAND,WM_USER + 1,NULL);

case WM_USER+1:
{
    debugFunc = 2;
    Update();   
    InvalidateRect(hwnd, NULL, FALSE);
    debugFunc = 2;
}

debugFunc整数用于调试...每当窗口发送WM_ENTERMENULOOP或WM_EXITMENULOOP时,我会查看这个debugFunc值是什么...每当我遇到通信错误时,debugFunc == 4(debugFunc设置)在更新功能4)...意味着在调用菜单之前,这个WM_USER + 1 msg没有完成。

那么,是否可以通过菜单调用给出消息WM_USER + 1或函数Update更高优先级?那么在显示菜单项之前必须完成WM_USER + 1或Update?

编辑::这里更新,它只是使用I2C适配器发送一堆消息来获取读取.. 我没有写任何iPortAIMaster函数,它们带有适配器

void Update()
{
    int receiveLength = 0;
    debugFunc = 4;
    //The following CStrings hold a string value that is to be updated to the window
    CString newVoltage, newCurrent, newPower, newStatus;
    CString StatusDisplay;

    //The following act like flags
    //If STATUS_WORD VOUT bit is set, checkVout = 1...meaning all pages must have their Vout Status checked
    //The rest follow in a similar fashion
    int checkTemp = 0, checkVout = 0, checkIout = 0, checkInput = 0;

    //Holds the pBuf data output from a MasterTxRx command is sent
    //Holds the new voltage or new current values
    //Must be translated to a CString to update the window
    BYTE *nV, *nC;

    //Holds a bit position
    int bit;
    float valueV, valueC;

        if (isOn)
        {
            pBufStatus[0] = 0x79;    //STATUS_WORD
            ////buf += "\r\n Sending the STATUS_WORD command to check for errors";
            //BYTE I2CAddr, BYTE *pBufStatus, unsigned int TxLen, unsigned int RxLen, BYTE doStop, UINT time
            newPort.iPortAIMasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 820);
            //Get the PAGE reading, value is placed in pBufStatus
            receiveLength = newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
            //Store pBufStatus
            pBufWORD[0] = pBufStatus[0];
            pBufWORD[1] = pBufStatus[1];

    #pragma region "Reading and Updating the window"

    #pragma region "Reading new IN Volt Cur Pow"
    {
                valueV = 0;
                valueC = 0;

                //Read_VIN
                pBufStatus[0] = 0x88;       //Read_VIN Command
                pBufStatus[1] = 0;      //Clear out earlier command

                //Send Read_VIN command
                MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                //Get the Voltage Reading, value is placed in pBufStatus
                newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                nV = pBufStatus;    //Save Copy

                //CONVERT THE VALUE TO USEABLE FORM
                valueV = ((int)valueV << 8) + pBufStatus[1];
                valueV = ((int)valueV << 8) + pBufStatus[0];
                //Multiply by 100 for formatting
                valueV = valueV / 100;

                newVoltage.Format("%.2f", valueV);

                //Read_IIN command
                pBufStatus[0] = 0x89;       //Read_IIN Command

                //Send Read_IIN command
                MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                //Get the Voltage Reading, value is placed in pBufStatus
                newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                nC = pBufStatus;    //Save Copy

                //CONVERT THE VALUE TO USEABLE FORM
                valueC = ((int)valueC << 8) + pBufStatus[1];
                valueC = ((int)valueC << 8) + pBufStatus[0];
                //Multiply by 100 for formatting
                valueC = valueC / 100;

                newCurrent.Format("%.2f", valueC);

                newPower.Format("%.2f", (valueC*valueV));

                //SetWindowText(VoltIn, newVoltage);
                //SetWindowText(CurIn, newCurrent);
                //SetWindowText(PowIn, newPower);
                VoltInR = newVoltage;
                CurInR = newCurrent;
                PowInR = newPower;
    }
    #pragma endregion

    #pragma region "Reading new Temperatures"
    {
            valueV = 0;
            //READ_TEMPERATURE_1
            pBufStatus[0] = 0x8D;       //Read_VIN READ_TEMPERATURE_1
            pBufStatus[1] = 0;      //Clear out earlier command

            //Send READ_TEMPERATURE_1 command
            MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
            //Get the Voltage Reading, value is placed in pBufStatus
            newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
            nV = pBufStatus;    //Save Copy

            //CONVERT THE VALUE TO USEABLE FORM
            valueV = ((int)valueV << 8) + pBufStatus[1];
            valueV = ((int)valueV << 8) + pBufStatus[0];
            //Multiply by 100 for formatting
            valueV = valueV / 100;

            newVoltage.Format("%.2f", valueV);
            //SetWindowText(TempU11, newVoltage);
            TempU11R = newVoltage;

            valueV = 0;
            //READ_TEMPERATURE_2
            pBufStatus[0] = 0x8E;       //Read_VIN READ_TEMPERATURE_2
            pBufStatus[1] = 0;      //Clear out earlier command

            //Send READ_TEMPERATURE_2 command
            MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
            //Get the Voltage Reading, value is placed in pBufStatus
            newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
            nV = pBufStatus;    //Save Copy

            //CONVERT THE VALUE TO USEABLE FORM
            valueV = ((int)valueV << 8) + pBufStatus[1];
            valueV = ((int)valueV << 8) + pBufStatus[0];
            //Multiply by 100 for formatting
            valueV = valueV / 100;

            newVoltage.Format("%.2f", valueV);
            //SetWindowText(TempU12, newVoltage);
            TempU12R = newVoltage;

            valueV = 0;
            //READ_TEMPERATURE_3
            pBufStatus[0] = 0x8F;       //Read_VIN READ_TEMPERATURE_3
            pBufStatus[1] = 0;      //Clear out earlier command

            //Send READ_TEMPERATURE_3 command
            MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
            //Get the Voltage Reading, value is placed in pBufStatus
            newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
            nV = pBufStatus;    //Save Copy

            //CONVERT THE VALUE TO USEABLE FORM
            valueV = ((int)valueV << 8) + pBufStatus[1];
            valueV = ((int)valueV << 8) + pBufStatus[0];
            //Multiply by 100 for formatting
            valueV = valueV / 100;

            newVoltage.Format("%.2f", valueV);
            //SetWindowText(TempU13, newVoltage);
            TempU13R = newVoltage;
    }
    #pragma endregion

            for (int i = 0; i < 11; i++)
            {
                valueV = 0;
                valueC = 0; 

                //FOR LOOP Index thru pages
                //i = 0 +5V
                //i = 1 +3.3V
                //i = 2 +12V
                //i = 3 -12V
                //i = 4 +12V_AUX
                //i = 10    +28V_Input
                pBufStatus[0] = 0x00;           //Page Command
                pBufStatus[1] = (char)i;        //Page Number
                MasterTx(I2CAddr, pBufStatus, 2, 1, 60);

    #pragma region "Reading new OUT Volt Cur Pow"
                switch (i)
                {
                    case 0:
                    case 1:
                    case 2:
                    {
                        //Read_VOUT
                        pBufStatus[0] = 0x8B;       //Read_Vout Command
                        pBufStatus[1] = 0;      //Clear out earlier command

                        //Send Read_VOUT command
                        MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                        //Get the Voltage Reading, value is placed in pBufStatus
                        newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                        nV = pBufStatus;    //Save Copy

                        //CONVERT THE VALUE TO USEABLE FORM
                        valueV = ((int)valueV << 8) + pBufStatus[1];
                        valueV = ((int)valueV << 8) + pBufStatus[0];
                        //Multiply by 100 for formatting
                        valueV = valueV / 100;

                        newVoltage.Format("%.2f", valueV);

                        //Read_IOUT command
                        pBufStatus[0] = 0x8C;       //Read_Iout Command

                        //Send Read_IOUT command
                        MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                        //Get the Voltage Reading, value is placed in pBufStatus
                        newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                        nC = pBufStatus;    //Save Copy

                        //CONVERT THE VALUE TO USEABLE FORM
                        valueC = ((int)valueC << 8) + pBufStatus[1];
                        valueC = ((int)valueC << 8) + pBufStatus[0];
                        //Multiply by 100 for formatting
                        valueC = valueC / 100;

                        newCurrent.Format("%.2f", valueC);

                        newPower.Format("%.2f", (valueC*valueV));
                        break;
                    }
                    case 3:
                    case 4:
                    {
                        //Read_VOUT
                        pBufStatus[0] = 0x8B;       //Read_Vout Command
                        pBufStatus[1] = 0;      //Clear out earlier command

                        //Send Read_VOUT command
                        MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                        //Get the Voltage Reading, value is placed in pBufStatus
                        newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                        nV = pBufStatus;    //Save Copy

                        //CONVERT THE VALUE TO USEABLE FORM
                        valueV = ((int)valueV << 8) + pBufStatus[1];
                        valueV = ((int)valueV << 8) + pBufStatus[0];
                        //Multiply by 100 for formatting
                        valueV = valueV / 100;

                        newVoltage.Format("%.2f", valueV);
                        break;
                    }
                    case 10:
                    {
                        //Read_VOUT
                        pBufStatus[0] = 0x8B;       //Read_Vout Command
                        pBufStatus[1] = 0;      //Clear out earlier command

                        //Send Read_VOUT command
                        MasterTxRx(I2CAddr, pBufStatus, 1, 2, 1, 120);
                        //Get the Voltage Reading, value is placed in pBufStatus
                        newPort.iPortAIGetMasterRxMsg(512, pBufStatus);
                        nV = pBufStatus;    //Save Copy

                        //CONVERT THE VALUE TO USEABLE FORM
                        valueV = ((int)valueV << 8) + pBufStatus[1];
                        valueV = ((int)valueV << 8) + pBufStatus[0];
                        //Multiply by 100 for formatting
                        valueV = valueV / 100;

                        newVoltage.Format("%.2f", valueV);
                        break;
                    }
                }
    #pragma endregion

    #pragma region "Display reading"
                    switch (i)  //switch on the page number, display new values and checks faults if needed
                    {                       
                        case 0:         //+5V
                        {
        #pragma region "5V Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(Volt5at24, newVoltage);
                                Volt5at24R = newVoltage;
                                //SetWindowText(Cur5at24, newCurrent);
                                Cur5at24R = newCurrent;
                                //SetWindowText(Pow5at24, newPower);
                                Pow5at24R = newPower;
                                break;
                            }
        #pragma endregion
                        }
                        case 1:         //+3.3V
                        {
        #pragma region "3.3V Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(Volt3at15, newVoltage);
                                Volt3at15R = newVoltage;
                                //SetWindowText(Cur3at15, newCurrent);
                                Cur3at15R = newCurrent;
                                //SetWindowText(Pow3at15, newPower);
                                Pow3at15R = newPower;
                                break;
                            }
        #pragma endregion
                        }
                        case 2:         //+12V
                        {
        #pragma region "12V Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(Volt12at1, newVoltage);
                                Volt12at1R = newVoltage;
                                //SetWindowText(Cur12at1, newCurrent);
                                Cur12at1R = newCurrent;
                                //SetWindowText(Pow12at1, newPower);
                                Pow12at1R = newPower;
                                break;
                            }
        #pragma endregion
                        }
                        case 3:         //-12V
                        {
        #pragma region "-12V Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(Volt12at2, newVoltage);
                                Volt12at2R = newVoltage;
                            }
        #pragma endregion
                        }
                        case 4:         //+12V AUX
                        {
        #pragma region "12V AUX Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(Volt12at40, newVoltage);
                                Volt12at40R = newVoltage;
                            }
        #pragma endregion
                        }
                        case 10:            //+28V input
                        {
        #pragma region "3.3 HSKPR Display"
                            {
                                //SEND OUTPUT TO WINDOW USING SetWindowText();
                                //SetWindowText(VoltIn, newVoltage);
                                Volt3HR = newVoltage;
                                break;
                            }
        #pragma endregion
                        }
                    }
    #pragma endregion
                }
    #pragma endregion       
        }
}

0 个答案:

没有答案