Exemple #1
0
std::string Alert::GetText() {
  LOG(TRACE) << "Entering Alert::GetText";
  HWND label_handle = NULL;
  // Alert present, find the OK button.
  // Retry up to 10 times to find the dialog.
  int max_wait = 10;
  while ((label_handle == NULL) && --max_wait) {
    ::EnumChildWindows(this->alert_handle_,
                       &Alert::FindTextLabel,
                       reinterpret_cast<LPARAM>(&label_handle));
    if (label_handle == NULL) {
      ::Sleep(50);
    }
  }

  std::string alert_text_value;
  if (label_handle == NULL) {
    alert_text_value = "";
  } else {
    int text_length = ::GetWindowTextLength(label_handle);
    std::vector<wchar_t> text_buffer(text_length + 1);
    ::GetWindowText(label_handle, &text_buffer[0], text_length + 1);
    std::wstring alert_text = &text_buffer[0];
    alert_text_value = CW2A(alert_text.c_str(), CP_UTF8);
  }
  return alert_text_value;
}
Exemple #2
0
std::string Alert::GetStandardDialogText() {
  LOG(TRACE) << "Entering Alert::GetStandardDialogText";
  TextLabelFindInfo info;
  info.label_handle = NULL;
  info.control_id_found = 0;
  info.excluded_control_id = 0;

  // Alert present, find the OK button.
  // Retry up to 10 times to find the dialog.
  int max_wait = 10;
  while ((info.label_handle == NULL) && --max_wait) {
    ::EnumChildWindows(this->alert_handle_,
                       &Alert::FindTextLabel,
                       reinterpret_cast<LPARAM>(&info));
    if (info.label_handle == NULL) {
      ::Sleep(50);
    }
  }

  // BIG ASSUMPTION HERE! If we found the text label, assume that
  // all other controls on the alert are fully drawn too.
  TextBoxFindInfo textbox_find_info;
  textbox_find_info.textbox_handle = NULL;
  textbox_find_info.match_proc = &Alert::IsSimpleEdit;
  ::EnumChildWindows(this->alert_handle_,
                     &Alert::FindTextBox,
                     reinterpret_cast<LPARAM>(&textbox_find_info));
  if (textbox_find_info.textbox_handle) {
    // There's a text box on the alert. That means the first
    // label found is the system-provided label. Ignore that
    // one and return the next one.
    info.label_handle = NULL;
    info.excluded_control_id = info.control_id_found;
    info.control_id_found = 0;
    ::EnumChildWindows(this->alert_handle_,
                       &Alert::FindTextLabel,
                       reinterpret_cast<LPARAM>(&info));
  }
  
  std::string alert_text_value;
  if (info.label_handle == NULL) {
    alert_text_value = "";
  } else {
    int text_length = ::GetWindowTextLength(info.label_handle);
    std::vector<wchar_t> text_buffer(text_length + 1);
    ::GetWindowText(info.label_handle, &text_buffer[0], text_length + 1);
    std::wstring alert_text = &text_buffer[0];
    alert_text_value = StringUtilities::ToString(alert_text);
  }
  return alert_text_value;
}