Advertisement
SirNickolas

OS 7 Button Activation handler

Nov 28th, 2014
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <sys/iomsg.h>
  6. #include <sys/neutrino.h>
  7. #include "connection_id.h"
  8.  
  9. //...
  10. //Прочие заголовки.
  11. //...
  12.  
  13. #define MSG_PREFIX "delay 2 calc "
  14. static const size_t MSG_PREFIX_LENGTH = sizeof MSG_PREFIX / sizeof(char) - 1;
  15.  
  16. int OnSendClicked(PtWidget_t* widget, ApInfo_t* apinfo, PtCallbackInfo_t* cbinfo) {
  17.     char msg[256] = MSG_PREFIX;
  18.     char response[40];
  19.     char* input;
  20.     size_t msgSize;
  21.     //Получаем текст, введенный в InputTextBox.
  22.     PtGetResource(ABW_InputTextBox, Pt_ARG_TEXT_STRING, &input, 0);
  23.     //Приписываем его к сообщению.
  24.     strncpy(msg + MSG_PREFIX_LENGTH, input, sizeof msg / sizeof(char) - MSG_PREFIX_LENGTH);
  25.     //Вычисляем размер сообщения.
  26.     msgSize = MSG_PREFIX_LENGTH + (strlen(input) + 1) * sizeof(char);
  27.     //Отправляем на сервер.
  28.     if (MsgSend(connectionId, msg, msgSize, response, sizeof response) == -1) {
  29.         fputs("Cannot send a message\n", stderr);
  30.         exit(1);
  31.     }
  32.     //Выводим ответ сервера в OutputTextBox.
  33.     PtSetResource(ABW_OutputTextBox, Pt_ARG_TEXT_STRING, response, strlen(response) * sizeof(char));
  34.     return Pt_CONTINUE;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement