int dlgWaypointOutOfTerrain(TCHAR *Message){

  WndFrame* wfrm;
  int res = 0;

#ifdef HAVEEXCEPTIONS
  __try{
#endif

    char filename[MAX_PATH];
    LocalPathS(filename, TEXT("dlgWaypointOutOfTerrain.xml"));
    wf = dlgLoadFromXML(CallBackTable, 
		        
                        filename, 
		        hWndMainWindow,
		        TEXT("IDR_XML_WAYPOINTTERRAIN"));

    if (wf) {

    
      wfrm = (WndFrame*)wf->FindByName(TEXT("frmWaypointOutOfTerrainText"));

      wfrm->SetCaption(Message);
      wfrm->SetCaptionStyle(
          DT_EXPANDTABS
        | DT_CENTER
        | DT_NOCLIP
        | DT_WORDBREAK);


      res = wf->ShowModal();
      delete wf;

    }

    wf = NULL;

#ifdef HAVEEXCEPTIONS
  }__except(EXCEPTION_EXECUTE_HANDLER ){

    res = 0; 
    // ToDo: log that problem

  };
#endif

  return(res);

}
示例#2
0
/**
 * Displays a MessageBox and returns the pressed button
 * @param lpText Text displayed inside the MessageBox
 * @param lpCaption Text displayed in the Caption of the MessageBox
 * @param uType Type of MessageBox to display (OK+Cancel, Yes+No, etc.)
 * @return
 */
int WINAPI
MessageBoxX(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
  WndForm *wf = NULL;
  WndFrame *wText = NULL;
  int X, Y, Width, Height;
  WndButton *wButtons[10];
  int ButtonCount = 0;
  int i, x, y, d, w, h, res, dY;
  RECT rc;

  assert(lpText != NULL);
  assert(lpCaption != NULL);

  // JMW this makes the first key if pressed quickly, ignored
  // TODO bug: doesn't work sometimes. buttons have to be pressed multiple times (TB)
  XCSoarInterface::Debounce();

  rc = XCSoarInterface::main_window.get_screen_position();

#ifdef ALTAIRSYNC
  Width = Layout::Scale(220);
  Height = Layout::Scale(160);
#else
  Width = Layout::Scale(200);
  Height = Layout::Scale(160);
#endif

  X = ((rc.right - rc.left) - Width) / 2;
  Y = ((rc.bottom - rc.top) - Height) / 2;

  y = Layout::Scale(100);
  w = Layout::Scale(60);
  h = Layout::Scale(32);

  // Create dialog
  wf = new WndForm(&XCSoarInterface::main_window, _T("frmXcSoarMessageDlg"),
                   lpCaption, X, Y, Width, Height);
  wf->SetFont(MapWindowBoldFont);
  wf->SetTitleFont(MapWindowBoldFont);
  wf->SetBackColor(Color(0xDA, 0xDB, 0xAB));

  // Create text element
  wText = new WndFrame(wf, _T("frmMessageDlgText"),
                       0, Layout::Scale(5), Width, Height);

  wText->SetCaption(lpText);
  wText->SetFont(MapWindowBoldFont);
  wText->SetCaptionStyle(DT_EXPANDTABS | DT_CENTER | DT_NOCLIP | DT_WORDBREAK);
  // | DT_VCENTER

  /* TODO code: this doesnt work to set font height
  dY = wText->GetLastDrawTextHeight() - Height;
  */
  dY = Layout::Scale(-40);
  wText->resize(Width, wText->GetTextHeight() + 5);
  wf->resize(Width, wf->get_size().cy + dY);

  y += dY;

  // Create buttons
  uType = uType & 0x000f;
  if (uType == MB_OK || uType == MB_OKCANCEL) {
    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("OK")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDOK);
    ButtonCount++;
  }

  if (uType == MB_YESNO || uType == MB_YESNOCANCEL) {
    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("Yes")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDYES);
    ButtonCount++;

    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("No")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDNO);
    ButtonCount++;
  }

  if (uType == MB_ABORTRETRYIGNORE || uType == MB_RETRYCANCEL) {
    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("Retry")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDRETRY);
    ButtonCount++;
  }

  if (uType == MB_OKCANCEL || uType == MB_RETRYCANCEL || uType == MB_YESNOCANCEL) {
    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("Cancel")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDCANCEL);
    ButtonCount++;
  }

  if (uType == MB_ABORTRETRYIGNORE) {
    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("Abort")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDABORT);
    ButtonCount++;

    wButtons[ButtonCount] =
        new WndButton(wf, _T(""), gettext(_T("Ignore")), 0, y, w, h, OnButtonClick);

    wButtons[ButtonCount]->SetTag(IDIGNORE);
    ButtonCount++;
  }

  d = Width / (ButtonCount);
  x = d / 2 - w / 2;

  // Move buttons to the right positions
  for (i = 0; i < ButtonCount; i++) {
    wButtons[i]->move(x, y);
    x += d;
  }

  // Show MessageBox and save result
  res = wf->ShowModal();

  delete wf;

#ifdef ALTAIRSYNC
  // force a refresh of the window behind
  InvalidateRect(hWnd,NULL,true);
  UpdateWindow(hWnd);
#endif

  return(res);
}