Exemplo n.º 1
0
// Main process
void ViMain()
{
	char tmp[MAX_PATH];
	UINT ostype = GetOsInfo()->OsType;
	VI_SETTING_ARCH *suitable;
	TOKEN_LIST *t;
	UINT i;

	if (OS_IS_WINDOWS_NT(ostype) == false ||
		GET_KETA(ostype, 100) <= 1)
	{
		// The OS is too old
		MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_BAD_OS+skip));
		return;
	}

	Zero(&setting, sizeof(setting));

	// Read the inf file
	Format(tmp, sizeof(tmp), "%s\\%s", MsGetExeDirName(), VI_INF_FILENAME);
	if (ViLoadInf(&setting, tmp) == false)
	{
		// Failure
		MsgBoxEx(NULL, MB_ICONSTOP, _U(IDS_INF_LOAD_FAILED+skip), VI_INF_FILENAME);
		return;
	}

	ViSetSkip();

	// Parse the command line options
	t = GetCommandLineToken();

	for (i = 0;i < t->NumTokens;i++)
	{
		char *s = t->Token[i];

		if (IsEmptyStr(s) == false)
		{
			if (StartWith(s, "/") || StartWith(s, "-"))
			{
				if (StrCmpi(&s[1], "web") == 0)
				{
					setting.WebMode = true;
				}
			}
			else
			{
				StrCpy(setting.SettingPath, sizeof(setting.SettingPath), s);
			}
		}
	}

	FreeToken(t);

	suitable = ViGetSuitableArchForCpu();

	// Security check
	if (setting.WebMode)
	{
		bool ok = true;

		if (ViIsInternetFile(suitable->Path) == false)
		{
			ok = false;
		}

		if (IsEmptyStr(setting.SettingPath) == false)
		{
			if (ViIsInternetFile(setting.SettingPath) == false)
			{
				ok = false;
			}
		}

		if (ok == false)
		{
			// Security breach
			MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_SECURITY_ERROR+skip));
			return;
		}
	}

	// Get the current installation state
	ViLoadCurrentInstalledStates();

	if (suitable->Supported == false)
	{
		// This CPU isn't supported
		MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_CPU_NOT_SUPPORTED+skip));
		return;
	}

	if (suitable->CurrentInstalled && suitable->Build <= suitable->CurrentInstalledBuild)
	{
		// Do not download client software since it has already been installed
		setting.DownloadNotRequired = true;
	}

	// Show the dialog
	ViInstallDlg();
}
Exemplo n.º 2
0
extern "C" BOOL EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat)
{

  // Don't print empty documents
  if (SendMessage(hwnd,SCI_GETLENGTH,0,0) == 0) {
    MsgBox(MBWARN,IDS_PRINT_EMPTY);
    return TRUE;
  }

  int startPos;
  int endPos;

  HDC hdc;

  RECT rectMargins;
  RECT rectPhysMargins;
  RECT rectSetup;
  POINT ptPage;
  POINT ptDpi;

  //RECT rectSetup;

  TEXTMETRIC tm;

  int headerLineHeight;
  HFONT fontHeader;

  int footerLineHeight;
  HFONT fontFooter;

  WCHAR dateString[MIDSZ_BUFFER] = { L'\0' };

  DOCINFO di = {sizeof(DOCINFO), nullptr, nullptr, nullptr, 0};

  int lengthDoc;
  int lengthDocMax;
  int lengthPrinted;

  struct Sci_RangeToFormat frPrint;

  int pageNum;
  BOOL printPage;

  WCHAR pageString[32] = { L'\0' };

  HPEN pen;
  HPEN penOld;

  PRINTDLG pdlg = { sizeof(PRINTDLG), nullptr, nullptr, nullptr, nullptr, 
    0, 0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
  pdlg.hwndOwner = GetParent(hwnd);
  pdlg.hInstance = g_hInstance;
  pdlg.Flags = PD_USEDEVMODECOPIES | PD_ALLPAGES | PD_RETURNDC;
  pdlg.nFromPage = 1;
  pdlg.nToPage = 1;
  pdlg.nMinPage = 1;
  pdlg.nMaxPage = 0xffffU;
  pdlg.nCopies = 1;
  pdlg.hDC = nullptr;
  pdlg.hDevMode = hDevMode;
  pdlg.hDevNames = hDevNames;

  startPos = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
  endPos = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0);

  if (startPos == endPos) {
    pdlg.Flags |= PD_NOSELECTION;
  } else {
    pdlg.Flags |= PD_SELECTION;
  }

  // |= 0 - Don't display dialog box, just use the default printer and options
  pdlg.Flags |= (flagPrintFileAndLeave == 1) ? PD_RETURNDEFAULT : 0;

  if (!PrintDlg(&pdlg)) {
    return TRUE; // False means error...
  }

  hDevMode = pdlg.hDevMode;
  hDevNames = pdlg.hDevNames;

  hdc = pdlg.hDC;

  // Get printer resolution
  ptDpi.x = GetDeviceCaps(hdc, LOGPIXELSX);    // dpi in X direction
  ptDpi.y = GetDeviceCaps(hdc, LOGPIXELSY);    // dpi in Y direction

  // Start by getting the physical page size (in device units).
  ptPage.x = GetDeviceCaps(hdc, PHYSICALWIDTH);   // device units
  ptPage.y = GetDeviceCaps(hdc, PHYSICALHEIGHT);  // device units

  // Get the dimensions of the unprintable
  // part of the page (in device units).
  rectPhysMargins.left = GetDeviceCaps(hdc, PHYSICALOFFSETX);
  rectPhysMargins.top = GetDeviceCaps(hdc, PHYSICALOFFSETY);

  // To get the right and lower unprintable area,
  // we take the entire width and height of the paper and
  // subtract everything else.
  rectPhysMargins.right = ptPage.x            // total paper width
                          - GetDeviceCaps(hdc, HORZRES) // printable width
                          - rectPhysMargins.left;        // left unprintable margin

  rectPhysMargins.bottom = ptPage.y            // total paper height
                           - GetDeviceCaps(hdc, VERTRES)  // printable height
                           - rectPhysMargins.top;        // right unprintable margin

  // At this point, rectPhysMargins contains the widths of the
  // unprintable regions on all four sides of the page in device units.

  // Take in account the page setup given by the user (if one value is not null)
  if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
          pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) {

    // Convert the hundredths of millimeters (HiMetric) or
    // thousandths of inches (HiEnglish) margin values
    // from the Page Setup dialog to device units.
    // (There are 2540 hundredths of a mm in an inch.)

    WCHAR localeInfo[3];
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);

    if (localeInfo[0] == L'0') {  // Metric system. L'1' is US System
      rectSetup.left = MulDiv (pagesetupMargin.left, ptDpi.x, 2540);
      rectSetup.top = MulDiv (pagesetupMargin.top, ptDpi.y, 2540);
      rectSetup.right  = MulDiv(pagesetupMargin.right, ptDpi.x, 2540);
      rectSetup.bottom  = MulDiv(pagesetupMargin.bottom, ptDpi.y, 2540);
    } else {
      rectSetup.left  = MulDiv(pagesetupMargin.left, ptDpi.x, 1000);
      rectSetup.top  = MulDiv(pagesetupMargin.top, ptDpi.y, 1000);
      rectSetup.right  = MulDiv(pagesetupMargin.right, ptDpi.x, 1000);
      rectSetup.bottom  = MulDiv(pagesetupMargin.bottom, ptDpi.y, 1000);
    }

    // Dont reduce margins below the minimum printable area
    rectMargins.left  = max(rectPhysMargins.left, rectSetup.left);
    rectMargins.top  = max(rectPhysMargins.top, rectSetup.top);
    rectMargins.right  = max(rectPhysMargins.right, rectSetup.right);
    rectMargins.bottom  = max(rectPhysMargins.bottom, rectSetup.bottom);
  } else {
    rectMargins.left  = rectPhysMargins.left;
    rectMargins.top  = rectPhysMargins.top;
    rectMargins.right  = rectPhysMargins.right;
    rectMargins.bottom  = rectPhysMargins.bottom;
  }

  // rectMargins now contains the values used to shrink the printable
  // area of the page.

  // Convert device coordinates into logical coordinates
  DPtoLP(hdc, (LPPOINT)&rectMargins, 2);
  DPtoLP(hdc, (LPPOINT)&rectPhysMargins, 2);

  // Convert page size to logical units and we're done!
  DPtoLP(hdc, (LPPOINT) &ptPage, 1);

  headerLineHeight = MulDiv(8,ptDpi.y, 72);
  fontHeader = CreateFont(headerLineHeight,
                          0, 0, 0,
                          FW_BOLD,
                          0,
                          0,
                          0, 0, 0,
                          0, 0, 0,
                          L"Arial");
  SelectObject(hdc, fontHeader);
  GetTextMetrics(hdc, &tm);
  headerLineHeight = tm.tmHeight + tm.tmExternalLeading;

  if (iPrintHeader == 3)
    headerLineHeight = 0;

  footerLineHeight = MulDiv(7,ptDpi.y, 72);
  fontFooter = CreateFont(footerLineHeight,
                          0, 0, 0,
                          FW_NORMAL,
                          0,
                          0,
                          0, 0, 0,
                          0, 0, 0,
                          L"Arial");
  SelectObject(hdc, fontFooter);
  GetTextMetrics(hdc, &tm);
  footerLineHeight = tm.tmHeight + tm.tmExternalLeading;

  if (iPrintFooter == 1)
    footerLineHeight = 0;

  di.lpszDocName = pszDocTitle;
  di.lpszOutput = nullptr;
  di.lpszDatatype = nullptr;
  di.fwType = 0;
  if (StartDoc(hdc, &di) < 0) {
    DeleteDC(hdc);
    if (fontHeader)
      DeleteObject(fontHeader);
    if (fontFooter)
      DeleteObject(fontFooter);
    return FALSE;
  }

  // Get current date...
  SYSTEMTIME st;
  GetLocalTime(&st);
  GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,nullptr,dateString,MIDSZ_BUFFER);

  // Get current time...
  if (iPrintHeader == 0)
  {
    WCHAR timeString[SMALL_BUFFER] = { L'\0' };
    GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,nullptr,timeString,SMALL_BUFFER);
    StringCchCat(dateString,COUNTOF(dateString),L" ");
    StringCchCat(dateString,COUNTOF(dateString),timeString);
  }

  // Set print color mode
  int printColorModes[5] = {
    SC_PRINT_NORMAL,
    SC_PRINT_INVERTLIGHT,
    SC_PRINT_BLACKONWHITE,
    SC_PRINT_COLOURONWHITE,
    SC_PRINT_COLOURONWHITEDEFAULTBG };
  SendMessage(hwnd,SCI_SETPRINTCOLOURMODE,printColorModes[iPrintColor],0);

  // Set print zoom...
  SendMessage(hwnd,SCI_SETPRINTMAGNIFICATION,(WPARAM)iPrintZoom,0);

  lengthDoc = (int)SendMessage(hwnd,SCI_GETLENGTH,0,0);
  lengthDocMax = lengthDoc;
  lengthPrinted = 0;

  // Requested to print selection
  if (pdlg.Flags & PD_SELECTION) {
    if (startPos > endPos) {
      lengthPrinted = endPos;
      lengthDoc = startPos;
    } else {
      lengthPrinted = startPos;
      lengthDoc = endPos;
    }

    if (lengthPrinted < 0)
      lengthPrinted = 0;
    if (lengthDoc > lengthDocMax)
      lengthDoc = lengthDocMax;
  }

  // We must substract the physical margins from the printable area
  frPrint.hdc = hdc;
  frPrint.hdcTarget = hdc;
  frPrint.rc.left = rectMargins.left - rectPhysMargins.left;
  frPrint.rc.top = rectMargins.top - rectPhysMargins.top;
  frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left;
  frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top;
  frPrint.rcPage.left = 0;
  frPrint.rcPage.top = 0;
  frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1;
  frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1;
  frPrint.rc.top += headerLineHeight + headerLineHeight / 2;
  frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;
  // Print each page
  pageNum = 1;

  while (lengthPrinted < lengthDoc) {
    printPage = (!(pdlg.Flags & PD_PAGENUMS) ||
                 (pageNum >= pdlg.nFromPage) && (pageNum <= pdlg.nToPage));

    StringCchPrintf(pageString,COUNTOF(pageString),pszPageFormat,pageNum);

    if (printPage) {

      // Show wait cursor...
      SendMessage(g_hwndEdit, SCI_SETCURSOR, (WPARAM)SC_CURSORWAIT, 0);

      // Display current page number in Statusbar
      StatusUpdatePrintPage(pageNum);

      StartPage(hdc);

      SetTextColor(hdc, RGB(0,0,0));
      SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF));
      SelectObject(hdc, fontHeader);
      UINT ta = SetTextAlign(hdc, TA_BOTTOM);
      RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2,
                  frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2};
      rcw.bottom = rcw.top + headerLineHeight;

      if (iPrintHeader < 3)
      {
        ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, pszDocTitle,
                      lstrlen(pszDocTitle), nullptr);
      }

      // Print date in header
      if (iPrintHeader == 0 || iPrintHeader == 1)
      {
        SIZE sizeInfo;
        SelectObject(hdc,fontFooter);
        GetTextExtentPoint32(hdc,dateString,StringCchLenW(dateString,COUNTOF(dateString)),&sizeInfo);
        ExtTextOut(hdc, frPrint.rc.right - 5 - sizeInfo.cx, frPrint.rc.top - headerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, dateString,
                      StringCchLenW(dateString,COUNTOF(dateString)), nullptr);
      }

      if (iPrintHeader < 3)
      {
        SetTextAlign(hdc, ta);
        pen = CreatePen(0, 1, RGB(0,0,0));
        penOld = (HPEN)SelectObject(hdc, pen);
        MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, nullptr);
        LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4);
        SelectObject(hdc, penOld);
        DeleteObject(pen);
      }
    }

    frPrint.chrg.cpMin = lengthPrinted;
    frPrint.chrg.cpMax = lengthDoc;

    lengthPrinted = (int)SendMessage(hwnd, SCI_FORMATRANGE, printPage, (LPARAM)&frPrint);

    if (printPage) {
      SetTextColor(hdc, RGB(0,0,0));
      SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF));
      SelectObject(hdc, fontFooter);
      UINT ta = SetTextAlign(hdc, TA_TOP);
      RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2,
                  frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2};

      if (iPrintFooter == 0)
      {
        SIZE sizeFooter;
        GetTextExtentPoint32(hdc,pageString,StringCchLenW(pageString,COUNTOF(pageString)),&sizeFooter);
        ExtTextOut(hdc, frPrint.rc.right - 5 - sizeFooter.cx, frPrint.rc.bottom + footerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, pageString,
                      StringCchLenW(pageString,COUNTOF(pageString)), nullptr);

        SetTextAlign(hdc, ta);
        pen = ::CreatePen(0, 1, RGB(0,0,0));
        penOld = (HPEN)SelectObject(hdc, pen);
        SetBkColor(hdc, RGB(0,0,0));
        MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, nullptr);
        LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4);
        SelectObject(hdc, penOld);
        DeleteObject(pen);
      }

      EndPage(hdc);
    }
    pageNum++;

    if ((pdlg.Flags & PD_PAGENUMS) && (pageNum > pdlg.nToPage))
      break;
  }

  SendMessage(hwnd,SCI_FORMATRANGE, FALSE, 0);

  EndDoc(hdc);
  DeleteDC(hdc);
  if (fontHeader)
    DeleteObject(fontHeader);
  if (fontFooter)
    DeleteObject(fontFooter);

  // Reset Statusbar to default mode
  StatusSetSimple(g_hwndStatus,FALSE);

  // Remove wait cursor...
  { POINT pt; SendMessage(g_hwndEdit, SCI_SETCURSOR, (WPARAM)SC_CURSORNORMAL, 0); GetCursorPos(&pt); SetCursorPos(pt.x, pt.y); }

  return TRUE;
}
Exemplo n.º 3
0
VOID ViewItems_OnCommand( HWND hwnd,
                          INT  id,
                          HWND hwndCtrl,
                          UINT codeNotify )
{
  INT i, j, n;
  CHAR szBuf[128];
  HWND hwndList;
  LRESULT lResult;

  switch(id)
  {
    case IDC_ITEM_LIST:

      if ( codeNotify == LBN_SELCHANGE )
      {
        ViewItems_ItemChanged( hwnd );
      }
      break;

    case IDC_ITEM_RESOURCES:

      if ( codeNotify == LBN_SELCHANGE )
      {
        lResult = ListBox_GetCurSel( hwndCtrl );

        if ( lResult != LB_ERR )
        {
          ListBox_GetText( hwndCtrl, lResult, szBuf );

          for( j = 0; j < po->nBitmaps; ++j )
          {
            if ( !_fstricmp( szBuf, po->pBitmapData[j].bitmap_name ) )
            {
              break;
            }
          }

          if ( j < po->nBitmaps )
          {
            PreviewBitmap( hwnd,
                           IDC_ITEM_BITMAP_PREVIEW,
                           IDC_ITEM_BITMAP_SIZE,
                           &po->pBitmapData[j],
                           po->pPalette );
          }
          else
          {
            PreviewBitmap( hwnd,
                           IDC_ITEM_BITMAP_PREVIEW,
                           IDC_ITEM_BITMAP_SIZE,
                           NULL,
                           NULL );
          }
        }
      }
      break;

    case IDC_ITEM_PIXEL_SIZE:

      if ( codeNotify == EN_CHANGE )
      {
        lResult = ListBox_GetCurSel( GetDlgItem( hwnd, IDC_ITEM_LIST ) );

        if ( lResult >= 0 && lResult < po->nItems )
        {
          i = (INT)lResult;

          SendMessage( hwndCtrl,
                       WM_GETTEXT,
                       (WPARAM)sizeof(szBuf),
                       (LPARAM)((LPSTR)szBuf) );

          po->pItemData[i].pixel_size = (float)atof( szBuf );

          bChange = TRUE;
        }
      }
      break;

    case IDC_ITEM_NEW:

      i = po->nItems;

      if (i == MAX_ITEMS)
      {
        MsgBox( hwnd,
                MB_ICONEXCLAMATION,
                "The limit of %d items has been reached.",
                MAX_ITEMS );

        break;
      }

      _fmemset( szNewItemName, 0, sizeof(szNewItemName) );
      _fmemset( nNewIndex, 0, sizeof(nNewIndex) );
      nNewItemType = -1;
      dNewPixelSize = 15.62;

      for(j = 0; j < MAX_ELEMENTS; ++j)
      {
        nNewIndex[j] = -1;
      }

      if (EditItemDialog(hwnd) == IDCANCEL)
      {
        break;
      }

      hwndList = GetDlgItem(hwnd, IDC_ITEM_LIST);

      ListBox_AddString(hwndList, szNewItemName);

      _fmemset(&po->pItemData[i], 0, sizeof(ITEM_DATA));
      _fstrcpy(po->pItemData[i].item_name, szNewItemName);
      po->pItemData[i].pixel_size = (float)dNewPixelSize;
      po->pItemData[i].item_type = nNewItemType;

      n = GetNumItemElements(nNewItemType);

      for(j = 0; j < n; ++j)
      {
        po->pItemData[i].index[j] = nNewIndex[j];
      }

      ++po->nItems;

      ListBox_SetCurSel(hwndList, i);
      ViewItems_ItemChanged(hwnd);

      bChange = TRUE;

      break;

    case IDC_ITEM_DELETE:

      hwndList = GetDlgItem( hwnd, IDC_ITEM_LIST );

      lResult = ListBox_GetCurSel( hwndList );

      if ( lResult >= 0 && lResult < po->nItems )
      {
        i = (INT)lResult;
        Object_DeleteItem( po, i );
        ListBox_DeleteString( hwndList, i );

        if ( i == 0 )
          ListBox_SetCurSel( hwndList, 0 );
        else
          ListBox_SetCurSel( hwndList, i - 1 );

        ViewItems_ItemChanged( hwnd );

        bChange = TRUE;
      }

      break;

    case IDC_ITEM_EDIT:

      hwndList = GetDlgItem( hwnd, IDC_ITEM_LIST );

      lResult = ListBox_GetCurSel( hwndList );

      if ( lResult >= 0 && lResult < po->nItems )
      {
        i = (INT)lResult;

        _fstrcpy( szNewItemName, po->pItemData[i].item_name );
        dNewPixelSize = (double)po->pItemData[i].pixel_size;
        nNewItemType = po->pItemData[i].item_type;

        n = GetNumItemElements( nNewItemType );

        for( j = 0; j < n; ++j )
        {
          nNewIndex[j] = po->pItemData[i].index[j];
        }

        if ( EditItemDialog( hwnd ) == IDCANCEL )
        {
          break;
        }

        if ( !szNewItemName[0] )
        {
          MsgBox( hwnd,
                  MB_ICONEXCLAMATION,
                  "The item must be given a name." );

          break;
        }

        _fmemset( &po->pItemData[i], 0, sizeof(ITEM_DATA) );
        _fstrcpy( po->pItemData[i].item_name, szNewItemName );
        po->pItemData[i].pixel_size = (float)dNewPixelSize;
        po->pItemData[i].item_type = nNewItemType;

        n = GetNumItemElements( nNewItemType );

        for( j = 0; j < n; ++j )
        {
          po->pItemData[i].index[j] = nNewIndex[j];
        }

        j = ListBox_GetTopIndex(hwndList);

        ListBox_ResetContent(hwndList);

        for( i = 0; i < po->nItems; ++i )
        {
          ListBox_AddString( hwndList, po->pItemData[i].item_name );
        }

        ListBox_SetTopIndex( hwndList, j );
        ListBox_SetCurSel( hwndList, (INT)lResult );

        ViewItems_ItemChanged( hwnd );

        bChange = TRUE;
      }

      break;
      
    case IDOK: case IDCANCEL:

      if ( hPalCommon )
      {
        DeleteObject( hPalCommon );
        hPalCommon = NULL;
      }

      EndDialog( hwnd, IDOK );
      break;
  }
  
} // ViewItems_OnCommand
Exemplo n.º 4
0
static	void	Configure_Flow_KB120F( void )
{
    //	for kb120f, kb6120, kb6120b
    static	struct  uMenu  const  menu[] =
    {
			{ 0x0201u, "设置粉尘流量" },
			{ 0x0C00u, "流 量" },
			{ 0x1400u, "限 压" }
    };
    uint8_t	item = 0u;
    BOOL	changed = FALSE;
    BOOL	need_redraw = TRUE;

    do
    {
			if ( need_redraw )
			{
				cls();
				Menu_Redraw( menu );
				need_redraw = FALSE;
			}
			ShowI16U( 0x0C11u, Configure.SetFlow[PP_TSP], 0x0501u, " L/m" );
			if ( Configure.TSP_Pr_Portect != 0u )
			{
				ShowI16U( 0x1411u, Configure.TSP_Pr_Portect , 0x0502u, " kPa" );
			}
			else
			{
				Lputs( 0x1411, "   [停用]   " );
			}

			item = Menu_Select( menu, item + 1u, NULL );
			switch( item )
			{
			case 0:
				if ( changed )
				{
					need_redraw = TRUE;
					switch( MsgBox( "保存修改结果 ?", vbYesNoCancel + vbDefaultButton3 ))
					{
					case vbYes:
						ConfigureSave();
						break;
					case vbNo:
						ConfigureLoad();
						break;
					case vbCancel:
						item = 1u;
						break;
					default:
							break;
					}
				}
				break;
			case 1:
				if( EditI16U( 0x0C11u, & Configure.SetFlow[PP_TSP  ], 0x0501u ))
				{
					if ( Configure.SetFlow[PP_TSP  ] > 1400u )
					{
						Configure.SetFlow[PP_TSP  ] = 1400u;
					}
					if ( Configure.SetFlow[PP_TSP  ] <  600u )
					{
						Configure.SetFlow[PP_TSP  ] =  600u;
					}
					changed = TRUE;
				}
				break;

			case 2:
				ShowI16U( 0x1411u, Configure.TSP_Pr_Portect , 0x0502u, " kPa" );

				if( EditI16U( 0x1411u, & Configure.TSP_Pr_Portect , 0x0502u ))
				{
					if ( Configure.TSP_Pr_Portect > 2000u )
					{
						Configure.TSP_Pr_Portect = 2000u;
					}
					changed = TRUE;
				}
				break;
			default:
					break;
       }
    }
    while( enumSelectESC != item );
}
Exemplo n.º 5
0
BOOL CCopyHandlerApp::InitInstance()
{
	// ================================= Crash handling =======================================
	SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter);

	// ================================= Configuration ========================================
	CString strPath;
	CString strCfgPath;
	CString strLogPath;

	// note that the GetProgramDataPath() below should create a directory; ExpandPath() could
	// depend on the directory to be created earlier
	if(!GetProgramDataPath(strPath))
	{
		AfxMessageBox(_T("Cannot initialize Copy Handler (data path cannot be established)."), MB_ICONERROR | MB_OK);
		return FALSE;
	}

	strCfgPath = strPath + _T("\\ch.ini");

	// initialize configuration file
	m_config.set_callback(ConfigPropertyChangedCallback, NULL);

	// read the configuration
	try
	{
		m_config.read(strCfgPath);
	}
	catch(...)
	{
	}

	// set working dir for the engine
	icpf::config& rConfig = GetConfig();

//	rConfig.SetBasePath(strPath);
	// register all properties
	RegisterProperties(&rConfig);

	// ================================= Logging ========================================
	// initialize the global log file if it is requested by configuration file
	strLogPath = strPath +  + _T("\\ch.log");

	chcore::TLogger& rLogger = chcore::TLogger::Acquire();
	try
	{
		rLogger.init(strLogPath, (int_t)m_config.get_signed_num(PP_LOGMAXSIZE), (int_t)rConfig.get_unsigned_num(PP_LOGLEVEL), false, false);
		rLogger.Enable(m_config.get_bool(PP_LOGENABLELOGGING));
	}
	catch(...)
	{
		BOOST_ASSERT(false);
	}

	LOG_INFO(_T("============================ Initializing Copy Handler ============================"));
	LOG_INFO(_T(""));

	// ================================= COM ========================================
	LOG_INFO(_T("Initializing COM"));

	HRESULT hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
	if(FAILED(hResult))
	{
		CString strMsg;
		strMsg.Format(_T("Cannot initialize COM, the application will now exit (result = 0x%lx)"), hResult);

		LOG_ERROR(strMsg);
		AfxMessageBox(strMsg, MB_ICONERROR | MB_OK);
		return FALSE;
	}

	// ================================= Resource manager ========================================
	LOG_INFO(_T("Initializing resource manager..."));

	ictranslate::CResourceManager& rResManager = ictranslate::CResourceManager::Acquire();

	// set current language
	TCHAR szPath[_MAX_PATH];

	rResManager.Init(AfxGetInstanceHandle());
	rResManager.SetCallback(ResManCallback);
	rConfig.get_string(PP_PLANGUAGE, szPath, _MAX_PATH);
	TRACE(_T("Help path=%s\n"), szPath);
	if(!rResManager.SetLanguage(ExpandPath(szPath)))
	{
		TCHAR szData[2048];
		_sntprintf(szData, 2048, _T("Couldn't find the language file specified in configuration file:\n%s\nPlease correct this path to point the language file to use.\nProgram will now exit."), szPath);
		LOG_ERROR(szData);
		AfxMessageBox(szData, MB_ICONSTOP | MB_OK);
		return FALSE;
	}

	UpdateHelpPaths();

	// for dialogs
	ictranslate::CLanguageDialog::SetResManager(&rResManager);

	EnableHtmlHelp();

	// ================================= Checking for running instances of CH ========================================
	// check instance - return false if it's the second one
	LOG_INFO(_T("Checking for other running instances of Copy Handler"));
	if(!IsFirstInstance())
	{
		LOG_WARNING(_T("Other instance of Copy Handler is already running. Exiting."));
		MsgBox(IDS_ONECOPY_STRING);
		return FALSE;
	}

	// ================================= Common controls ========================================
	LOG_INFO(_T("Initializing GUI common controls"));

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	// ================================= Shell extension ========================================
	LOG_INFO(_T("Initializing shared memory for communication with shell extension"));

	m_hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CSharedConfigStruct), _T("CHLMFile"));
	if (m_hMapObject == NULL)
		return FALSE; 
	
	// Get a pointer to the file-mapped shared memory.
	g_pscsShared=(CSharedConfigStruct*)MapViewOfFile(m_hMapObject, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
	if (g_pscsShared == NULL) 
		return FALSE; 

	LOG_INFO(_T("Checking shell extension compatibility"));

	// calculate ch version
	long lCHVersion = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4;

	// check the version of shell extension
	LONG lVersion = 0;
	BSTR bstrVersion = NULL;

	hResult = CoCreateInstance(CLSID_CShellExtControl, NULL, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl);
	if(SUCCEEDED(hResult) && !m_piShellExtControl)
		hResult = E_FAIL;
	if(SUCCEEDED(hResult))
		hResult = m_piShellExtControl->GetVersion(&lVersion, &bstrVersion);
	if(SUCCEEDED(hResult) && lVersion == lCHVersion)
		hResult = m_piShellExtControl->SetFlags(eShellExt_Enabled, eShellExt_Enabled);
	if(FAILED(hResult) || lCHVersion != lVersion)
	{
		CString strMsg;
		strMsg.Format(_T("Shell extension has different version (0x%lx) than Copy Handler (0x%lx). Shell extension will be disabled."), lVersion, lCHVersion);

		LOG_WARNING(strMsg);
		MsgBox(IDS_SHELL_EXTENSION_MISMATCH_STRING);

		if(m_piShellExtControl)
			m_piShellExtControl->SetFlags(0, eShellExt_Enabled);
	}

	if(bstrVersion)
		::SysFreeString(bstrVersion);

	// ================================= Initial settings ========================================
	LOG_INFO(_T("Applying initial settings"));

	// set this process priority class
	HANDLE hProcess=GetCurrentProcess();
	::SetPriorityClass(hProcess, (DWORD)rConfig.get_signed_num(PP_PPROCESSPRIORITYCLASS));

#ifndef _DEBUG		// for easier writing the program - doesn't collide with std CH
	// set "run with system" registry settings
	SetAutorun(rConfig.get_bool(PP_PRELOADAFTERRESTART));
#endif

	// ================================= Main window ========================================
	LOG_INFO(_T("Creating main application window"));
	// create main window
	m_pMainWindow=new CMainWnd;
	if (!((CMainWnd*)m_pMainWindow)->Create())
		return FALSE;				// will be deleted at destructor

	m_pMainWnd = m_pMainWindow;
	CWinApp::InitInstance();

	LOG_INFO(_T("Copy Handler initialized successfully"));

	return TRUE;
}
Exemplo n.º 6
0
/********************************** 功能说明 ***********************************
*  系统配置 -> 恒温箱
*******************************************************************************/
static	void	Configure_HCBox( void )
{
    static  CHAR  const  MDS[][6] =
    {
        { "S关闭" }, { "H加热" }, { "C制冷" } , { "A自动" }
    };
    static	struct	uMenu	const	menu[] =
    {
        {	0x0201u, "配置恒温箱"	},
        {	0x0C00u, "控制方式"	},
        {	0x1400u, "设置温度"	},
    };
    uint8_t 	item = 1u;

    uint8_t		SetMode = Configure.HCBox_SetMode;
    uint16_t	SetTemp = Configure.HCBox_SetTemp;
    BOOL		changed = FALSE;
    BOOL		need_redraw = TRUE;

    do
    {
        if ( need_redraw )
        {
            cls();
            Menu_Redraw( menu );
            need_redraw = FALSE;
        }

        Lputs( 0x0C16U, MDS[SetMode] );
        ShowI16U( 0x1416U, SetTemp, 0x0501U, "℃" );

        item = Menu_Select( menu, item, NULL );
        switch( item )
        {
        case 1u:	/*	EditBoxMode	*/
            SetMode = ( SetMode + 1u) % 4u;
            changed = TRUE;
            break;

        case 2u:
            /* 注意: 因为恒温箱的设置温度范围是正数, 所以才可以使用无符号数编辑程序进行编辑 */
            if ( EditI16U( 0x1416U, &SetTemp, 0x0501U ))
            {
                if ( SetTemp <  150u )
                {
                    SetTemp = 150u;
                    beep();
                }
                if ( SetTemp >  300u )
                {
                    SetTemp = 300u;
                    beep();
                }
                changed = TRUE;
            }
            break;

        case 0u:
            if ( changed )
            {
                need_redraw = TRUE;
                switch ( MsgBox( "保存配置数据 ?", vbYesNoCancel + vbDefaultButton3 ))
                {
                case vbYes:
                    Configure.HCBox_SetMode = SetMode;
                    Configure.HCBox_SetTemp = SetTemp;
                    ConfigureSave();
                    set_HCBoxTemp( Configure.HCBox_SetTemp * 0.1f, Configure.HCBox_SetMode );
                    break;
                case vbNo:
                    ConfigureLoad();
                    break;
                case vbCancel:
                    item = 1u;
                    break;
                default:
                    break;
                }
            }
            break;

        default:
            break;
        }
    }
    while ( enumSelectESC != item );
}
Exemplo n.º 7
0
/********************************** 功能说明 ***********************************
*  系统配置 -> 采样流量
* 用户正常使用过程中不需要修改,原则上修改完采样流量后需要重新标定。
* 时均采样流量在采样前由用户设置,不在此处设置,对应的需要分段标定。
* 有这样有几种可能的组合:
	粉尘 1.05m3(KB-1000)
	粉尘 100L(KB-120F,KB6120A,KB6120B)
	粉尘 100L + 0.2L 两路(KB-6120C)
	日均 0.2L 两路(恒温恒流系列)

*******************************************************************************/
static	void	Configure_Flow_KB1000( void )
{
    MsgBox( "TODO KB-1000", vbOKOnly );
}
Exemplo n.º 8
0
VOID EditNoise_OnCommand( HWND hwnd,
                          INT  id,
                          HWND hwndCtrl,
                          UINT codeNotify )
{
    CHAR szBuf[128];
    LRESULT lResult;

    switch(id)
    {
    case IDC_EDIT_NOISE_LIST:

        if (codeNotify == LBN_SELCHANGE)
        {
            lResult = ListBox_GetCurSel(hwndCtrl);

            if ( lResult >= 0 && lResult < po->nSounds )
            {
                nNewSoundIndex = (INT)lResult;
            }
        }
        break;

    case IDC_EDIT_NOISE_NAME:

        if (codeNotify == EN_CHANGE)
        {
            SendMessage( hwndCtrl,
                         WM_GETTEXT,
                         (WPARAM)sizeof(szNewNoiseName),
                         (LPARAM)((LPSTR)szNewNoiseName) );
        }
        break;

    case IDC_EDIT_NOISE_RADIUS:

        if (codeNotify == EN_CHANGE)
        {
            SendMessage( hwndCtrl,
                         WM_GETTEXT,
                         (WPARAM)sizeof(szBuf),
                         (LPARAM)((LPSTR)szBuf) );

            dNewRadius = atof( szBuf );
        }
        break;

    case IDC_EDIT_NOISE_HEIGHT:

        if (codeNotify == EN_CHANGE)
        {
            SendMessage( hwndCtrl,
                         WM_GETTEXT,
                         (WPARAM)sizeof(szBuf),
                         (LPARAM)((LPSTR)szBuf) );

            dNewHeight = atof(szBuf);
        }
        break;

    case IDC_EDIT_NOISE_DELAY:

        if (codeNotify == EN_CHANGE)
        {
            SendMessage( hwndCtrl,
                         WM_GETTEXT,
                         (WPARAM)sizeof(szBuf),
                         (LPARAM)((LPSTR)szBuf) );

            nNewDelay = atoi(szBuf);
        }
        break;

    case IDOK:

        if (!szNewNoiseName[0])
        {
            MsgBox( hwnd,
                    MB_ICONEXCLAMATION,
                    "The noise must be given a name." );

            break;
        }

        if (nNewSoundIndex == -1)
        {
            MsgBox( hwnd,
                    MB_ICONEXCLAMATION,
                    "No sound assigned" );

            break;
        }

        EndDialog(hwnd, id);
        break;

    case IDCANCEL:

        EndDialog(hwnd, id);
        break;
    }

} // EditNoise_OnCommand
Exemplo n.º 9
0
void	Configure_Pr_Protect( void )
{
    static	struct  uMenu  const  menu[] =
    {
        { 0x0101u, "设置压力保护" },
		{ 0x0300u, "限 压" }
    };
    uint8_t	item = 0u;
    BOOL	changed = FALSE;
    BOOL	need_redraw = TRUE;

    do {
        if ( need_redraw )
        {
            cls();
            Menu_Redraw( menu );
            need_redraw = FALSE;
        }

        if ( Configure.TSP_Pr_Portect != 0u )
		{
			ShowI16U( 0x0307u, Configure.TSP_Pr_Portect , 0x0502u, " kPa" );
		}
		else
		{
			Lputs( 0x0307, " [停用]  " );
		}

        item = Menu_Select( menu, item + 1u );
        switch( item )
        {
        case 0:
            if ( changed )
            {
                need_redraw = TRUE;
                switch( MsgBox( "保存修改结果 ?", vbYesNoCancel + vbDefaultButton3 ))
                {
                case vbYes:
                    ConfigureSave();
                    break;
                case vbNo:
                    ConfigureLoad();
                    break;
                case vbCancel:
                    item = 1u;
                    break;
                default:
                    break;
                }
            }
            break;
        case 1:
			ShowI16U( 0x0307u, Configure.TSP_Pr_Portect , 0x0502u, " kPa" );

			if( EditI16U( 0x0307u, & Configure.TSP_Pr_Portect , 0x0502u ))
            {
                if ( Configure.TSP_Pr_Portect > 2000u )
                {
                    Configure.TSP_Pr_Portect = 2000u;
                }
                changed = TRUE;
            }
            break;
        default:
            break;
        }
    }
    while( enumSelectESC != item );
}
Exemplo n.º 10
0
INT_PTR CRecreateDlg::RecreateDlgProc(HWND hDlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
#define UM_USER_CONTROLS (WM_USER+121)
#define UM_FILL_CMDLIST (WM_USER+122)

	CRecreateDlg* pDlg = NULL;
	if (messg == WM_INITDIALOG)
	{
		pDlg = (CRecreateDlg*)lParam;
		pDlg->mh_Dlg = hDlg;
		SetWindowLongPtr(hDlg, DWLP_USER, lParam);
	}
	else
	{
		pDlg = (CRecreateDlg*)GetWindowLongPtr(hDlg, DWLP_USER);
	}
	if (!pDlg)
	{
		return FALSE;
	}

	PatchMsgBoxIcon(hDlg, messg, wParam, lParam);

	switch (messg)
	{
		case WM_INITDIALOG:
		{
			LRESULT lbRc = FALSE;

			// Visual
			SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hClassIcon);
			SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hClassIconSm);

			// Set password style (avoid "bars" on some OS)
			SendDlgItemMessage(hDlg, tRunAsPassword, WM_SETFONT, (LPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), 0);


			// Add menu items
			HMENU hSysMenu = GetSystemMenu(hDlg, FALSE);
			InsertMenu(hSysMenu, 0, MF_BYPOSITION, MF_SEPARATOR, 0);
			InsertMenu(hSysMenu, 0, MF_BYPOSITION | MF_STRING | MF_ENABLED,
					   ID_RESETCMDHISTORY, L"Clear history...");
			InsertMenu(hSysMenu, 0, MF_BYPOSITION | MF_STRING | MF_ENABLED
					   | (gpSet->isSaveCmdHistory ? MF_CHECKED : 0),
					   ID_STORECMDHISTORY, L"Store history");
			
			



			//#ifdef _DEBUG
			//SetWindowPos(ghOpWnd, HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
			//#endif

			RConStartArgs* pArgs = pDlg->mp_Args;
			_ASSERTE(pArgs);

			// Fill command and task drop down
			SendMessage(hDlg, UM_FILL_CMDLIST, TRUE, 0);

			// Set text in command and folder fields
			SetDlgItemText(hDlg, IDC_RESTART_CMD, pDlg->mpsz_DefCmd ? pDlg->mpsz_DefCmd : pArgs->pszSpecialCmd ? pArgs->pszSpecialCmd : L"");
			SetDlgItemText(hDlg, IDC_STARTUP_DIR, pDlg->mpsz_DefDir ? pDlg->mpsz_DefDir : pArgs->pszStartupDir ? pArgs->pszStartupDir : gpConEmu->WorkDir());

			// Split controls
			if (pArgs->aRecreate == cra_RecreateTab)
			{
				// Hide Split's
				ShowWindow(GetDlgItem(hDlg, gbRecreateSplit), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplitNone), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplit2Right), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplit2Bottom), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, stRecreateSplit), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, tRecreateSplit), SW_HIDE);
			}
			else
			{
				// Fill splits
				SetDlgItemInt(hDlg, tRecreateSplit, (1000-pArgs->nSplitValue)/10, FALSE);
				CheckRadioButton(hDlg, rbRecreateSplitNone, rbRecreateSplit2Bottom, rbRecreateSplitNone+pArgs->eSplit);
				EnableWindow(GetDlgItem(hDlg, tRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
				EnableWindow(GetDlgItem(hDlg, stRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
			}

			// Спрятать флажок "New window"
			bool bRunInNewWindow_Hidden = (pArgs->aRecreate == cra_EditTab || pArgs->aRecreate == cra_RecreateTab);
			ShowWindow(GetDlgItem(hDlg, cbRunInNewWindow), bRunInNewWindow_Hidden ? SW_HIDE : SW_SHOWNORMAL);


			const wchar_t *pszUser = pArgs->pszUserName;
			const wchar_t *pszDomain = pArgs->pszDomain;
			bool bResticted = (pArgs->RunAsRestricted == crb_On);
			int nChecked = rbCurrentUser;
			DWORD nUserNameLen = countof(pDlg->ms_CurUser);

			if (!GetUserName(pDlg->ms_CurUser, &nUserNameLen)) pDlg->ms_CurUser[0] = 0;

			wchar_t szRbCaption[MAX_PATH*3];
			lstrcpy(szRbCaption, L"Run as current &user: "******"UPN format" остается в pszUser
							lstrcpyn(szOtherUser, pszUser, MAX_PATH);
							wcscat_c(szOtherUser, L"@");
							lstrcpyn(szOtherUser+_tcslen(szOtherUser), pszDomain, MAX_PATH);
						}
						else
						{
							// "Старая" нотация domain\user
							lstrcpyn(szOtherUser, pszDomain, MAX_PATH);
							wcscat_c(szOtherUser, L"\\");
							lstrcpyn(szOtherUser+_tcslen(szOtherUser), pszUser, MAX_PATH);
						}
					}
					else
					{
						lstrcpyn(szOtherUser, pszUser, countof(szOtherUser));
					}

					SetDlgItemText(hDlg, tRunAsPassword, pArgs->szUserPassword);
				}
			}

			SetDlgItemText(hDlg, tRunAsUser, (nChecked == rbAnotherUser) ? szOtherUser : L"");
			CheckRadioButton(hDlg, rbCurrentUser, rbAnotherUser, nChecked);
			RecreateDlgProc(hDlg, UM_USER_CONTROLS, 0, 0);

			if (gOSVer.dwMajorVersion < 6)
			{
				// В XP и ниже это просто RunAs - с возможностью ввода имени пользователя и пароля
				//apiShowWindow(GetDlgItem(hDlg, cbRunAsAdmin), SW_HIDE);
				SetDlgItemTextA(hDlg, cbRunAsAdmin, "&Run as..."); //GCC hack. иначе не собирается
				// И уменьшить длину
				RECT rcBox; GetWindowRect(GetDlgItem(hDlg, cbRunAsAdmin), &rcBox);
				SetWindowPos(GetDlgItem(hDlg, cbRunAsAdmin), NULL, 0, 0, (rcBox.right-rcBox.left)/2, rcBox.bottom-rcBox.top,
				             SWP_NOMOVE|SWP_NOZORDER);
			}
			else if (gpConEmu->mb_IsUacAdmin || (pArgs && (pArgs->RunAsAdministrator == crb_On)))
			{
				CheckDlgButton(hDlg, cbRunAsAdmin, BST_CHECKED);

				if (gpConEmu->mb_IsUacAdmin)  // Только в Vista+ если GUI уже запущен под админом
				{
					EnableWindow(GetDlgItem(hDlg, cbRunAsAdmin), FALSE);
				}
				else if (gOSVer.dwMajorVersion < 6)
				{
					RecreateDlgProc(hDlg, WM_COMMAND, cbRunAsAdmin, 0);
				}
			}

			//}
			SetClassLongPtr(hDlg, GCLP_HICON, (LONG_PTR)hClassIcon);

			RECT rcBtnBox = {0};
			if (pArgs->aRecreate == cra_RecreateTab)
			{
				//GCC hack. иначе не собирается
				SetDlgItemTextA(hDlg, IDC_RESTART_MSG, "About to restart console");
				SendDlgItemMessage(hDlg, IDC_RESTART_ICON, STM_SETICON, (WPARAM)LoadIcon(NULL,IDI_EXCLAMATION), 0);
				// Выровнять флажок по кнопке
				GetWindowRect(GetDlgItem(hDlg, IDC_START), &rcBtnBox);
				lbRc = TRUE;
			}
			else
			{
				//GCC hack. иначе не собирается
				SetDlgItemTextA(hDlg, IDC_RESTART_MSG,  "Create new console");

				// Если ВЫКЛЮЧЕН "Multi consoles in one window"
				// - Check & Disable "New window" checkbox
				CheckDlgButton(hDlg, cbRunInNewWindow, (pArgs->aRecreate == cra_CreateWindow || !gpSetCls->IsMulti()) ? BST_CHECKED : BST_UNCHECKED);
				EnableWindow(GetDlgItem(hDlg, cbRunInNewWindow), gpSetCls->IsMulti());

				//
				SendDlgItemMessage(hDlg, IDC_RESTART_ICON, STM_SETICON, (WPARAM)LoadIcon(NULL,IDI_QUESTION), 0);
				POINT pt = {0,0};
				MapWindowPoints(GetDlgItem(hDlg, IDC_TERMINATE), hDlg, &pt, 1);
				DestroyWindow(GetDlgItem(hDlg, IDC_TERMINATE));
				SetWindowPos(GetDlgItem(hDlg, IDC_START), NULL, pt.x, pt.y, 0,0, SWP_NOSIZE|SWP_NOZORDER);
				SetDlgItemText(hDlg, IDC_START, (pArgs->aRecreate == cra_EditTab) ? L"&Save" : L"&Start");
				DestroyWindow(GetDlgItem(hDlg, IDC_WARNING));
				// Выровнять флажок по кнопке
				GetWindowRect(GetDlgItem(hDlg, IDC_START), &rcBtnBox);
			}

			if (rcBtnBox.left)
			{
				// Выровнять флажок по кнопке
				MapWindowPoints(NULL, hDlg, (LPPOINT)&rcBtnBox, 2);
				RECT rcBox; GetWindowRect(GetDlgItem(hDlg, cbRunAsAdmin), &rcBox);
				POINT pt;
				pt.x = rcBtnBox.left - (rcBox.right - rcBox.left) - 5;
				pt.y = rcBtnBox.top + ((rcBtnBox.bottom-rcBtnBox.top) - (rcBox.bottom-rcBox.top))/2;
				SetWindowPos(GetDlgItem(hDlg, cbRunAsAdmin), NULL, pt.x, pt.y, 0,0, SWP_NOSIZE|SWP_NOZORDER);
			}

			// Correct cbRunInNewWindow position
			if (!bRunInNewWindow_Hidden)
			{
				POINT pt = {};
				MapWindowPoints(GetDlgItem(hDlg, cbRunAsAdmin), hDlg, &pt, 1);
				RECT rcBox2; GetWindowRect(GetDlgItem(hDlg, cbRunInNewWindow), &rcBox2);
				SetWindowPos(GetDlgItem(hDlg, cbRunInNewWindow), NULL,
					pt.x-(rcBox2.right-rcBox2.left), pt.y, 0,0, SWP_NOSIZE);
			}


			// Ensure, it will be "on screen"
			RECT rect; GetWindowRect(hDlg, &rect);
			RECT rcCenter = CenterInParent(rect, pDlg->mh_Parent);
			MoveWindow(hDlg, rcCenter.left, rcCenter.top,
			           rect.right - rect.left, rect.bottom - rect.top, false);


			// Была отключена обработка CConEmuMain::OnFocus (лишние телодвижения)
			PostMessage(hDlg, (WM_APP+1), 0,0);


			// Default focus control
			if (pArgs->aRecreate == cra_RecreateTab)
				SetFocus(GetDlgItem(hDlg, IDC_START)); // Win+~ (Recreate tab), Focus on "Restart" button"
			else if ((pArgs->pszUserName && *pArgs->pszUserName) && !*pArgs->szUserPassword)
				SetFocus(GetDlgItem(hDlg, tRunAsPassword)); // We need password, all other fields are ready
			else
				SetFocus(GetDlgItem(hDlg, IDC_RESTART_CMD)); // Set focus in command-line field

			return lbRc;
		}
		case (WM_APP+1):
			//TODO: Не совсем корректно, не учитывается предыдущее значение флажка
			gpConEmu->SetSkipOnFocus(false);
			return FALSE;
		case WM_CTLCOLORSTATIC:

			if (GetDlgItem(hDlg, IDC_WARNING) == (HWND)lParam)
			{
				SetTextColor((HDC)wParam, 255);
				HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
				SetBkMode((HDC)wParam, TRANSPARENT);
				return (INT_PTR)hBrush;
			}

			break;
		//case WM_GETICON:

		//	if (wParam==ICON_BIG)
		//	{
		//		/*SetWindowLong(hWnd2, DWL_MSGRESULT, (LRESULT)hClassIcon);
		//		return 1;*/
		//	}
		//	else
		//	{
		//		SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LRESULT)hClassIconSm);
		//		return 1;
		//	}

		//	return 0;

		case UM_FILL_CMDLIST:
		{
			RConStartArgs* pArgs = pDlg->mp_Args;
			_ASSERTE(pArgs);

			pDlg->AddCommandList(pArgs->pszSpecialCmd);
			pDlg->AddCommandList(pDlg->mpsz_SysCmd, pArgs->pszSpecialCmd ? -1 : 0);
			pDlg->AddCommandList(pDlg->mpsz_CurCmd);
			pDlg->AddCommandList(pDlg->mpsz_DefCmd);

			// Может быть позван после очистки истории из меню, тогда нет смысла и дергаться
			if (wParam)
			{
				LPCWSTR pszHistory = gpSet->HistoryGet();

				if (pszHistory)
				{
					while (*pszHistory)
					{
						pDlg->AddCommandList(pszHistory);

						pszHistory += _tcslen(pszHistory)+1;
					}
				}
			}

			// Tasks
			int nGroup = 0;
			const Settings::CommandTasks* pGrp = NULL;
			while ((pGrp = gpSet->CmdTaskGet(nGroup++)))
			{
				pDlg->AddCommandList(pGrp->pszName);
			}
		}
		return 0;

		case UM_USER_CONTROLS:
		{
			if (SendDlgItemMessage(hDlg, rbCurrentUser, BM_GETCHECK, 0, 0))
			{
				EnableWindow(GetDlgItem(hDlg, cbRunAsRestricted), TRUE);
				//BOOL lbText = SendDlgItemMessage(hDlg, cbRunAsRestricted, BM_GETCHECK, 0, 0) == 0;
				EnableWindow(GetDlgItem(hDlg, tRunAsUser), FALSE);
				EnableWindow(GetDlgItem(hDlg, tRunAsPassword), FALSE);
			}
			else
			{
				if (SendDlgItemMessage(hDlg, tRunAsUser, CB_GETCOUNT, 0, 0) == 0)
				{
					DWORD dwLevel = 3, dwEntriesRead = 0, dwTotalEntries = 0, dwResumeHandle = 0;
					NET_API_STATUS nStatus;
					USER_INFO_3 *info = NULL;
					nStatus = ::NetUserEnum(NULL, dwLevel, FILTER_NORMAL_ACCOUNT, (PBYTE*) & info,
					                        MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);

					if (nStatus == NERR_Success)
					{
						wchar_t *pszAdmin = NULL, *pszLikeAdmin = NULL, *pszOtherUser = NULL;

						for (DWORD i = 0; i < dwEntriesRead; ++i)
						{
							// usri3_logon_server	"\\*"	wchar_t *
							if (!(info[i].usri3_flags & UF_ACCOUNTDISABLE) && info[i].usri3_name && *info[i].usri3_name)
							{
								SendDlgItemMessage(hDlg, tRunAsUser, CB_ADDSTRING, 0, (LPARAM)info[i].usri3_name);

								if (info[i].usri3_priv == 2/*USER_PRIV_ADMIN*/)
								{
									if (!pszAdmin && (info[i].usri3_user_id == 500))
										pszAdmin = lstrdup(info[i].usri3_name);
									else if (!pszLikeAdmin && (lstrcmpi(pDlg->ms_CurUser, info[i].usri3_name) != 0))
										pszLikeAdmin = lstrdup(info[i].usri3_name);
								}
								else if (!pszOtherUser
									&& (info[i].usri3_priv == 1/*USER_PRIV_USER*/)
									&& (lstrcmpi(pDlg->ms_CurUser, info[i].usri3_name) != 0))
								{
									pszOtherUser = lstrdup(info[i].usri3_name);
								}
							}
						}

						if (GetWindowTextLength(GetDlgItem(hDlg, tRunAsUser)) == 0)
						{
							// Try to suggest "Administrator" account
							SetDlgItemText(hDlg, tRunAsUser, pszAdmin ? pszAdmin : pszLikeAdmin ? pszLikeAdmin : pszOtherUser ? pszOtherUser : pDlg->ms_CurUser);
						}

						::NetApiBufferFree(info);
						SafeFree(pszAdmin);
						SafeFree(pszLikeAdmin);
					}
					else
					{
						// Добавить хотя бы текущего
						SendDlgItemMessage(hDlg, tRunAsUser, CB_ADDSTRING, 0, (LPARAM)pDlg->ms_CurUser);
					}
				}

				EnableWindow(GetDlgItem(hDlg, cbRunAsRestricted), FALSE);
				EnableWindow(GetDlgItem(hDlg, tRunAsUser), TRUE);
				EnableWindow(GetDlgItem(hDlg, tRunAsPassword), TRUE);
			}

			if (wParam == rbAnotherUser)
				SetFocus(GetDlgItem(hDlg, tRunAsUser));
		}
		return 0;

		case WM_SYSCOMMAND:
			switch (LOWORD(wParam))
			{
			case ID_RESETCMDHISTORY:
				// Подтверждение спросит ResetCmdHistory
				if (gpSetCls->ResetCmdHistory(hDlg))
				{
                	wchar_t* pszCmd = GetDlgItemText(hDlg, IDC_RESTART_CMD);
                	SendDlgItemMessage(hDlg, IDC_RESTART_CMD, CB_RESETCONTENT, 0,0);
                	SendMessage(hDlg, UM_FILL_CMDLIST, FALSE, 0);
                	if (pszCmd)
                	{
                		SetDlgItemText(hDlg, IDC_RESTART_CMD, pszCmd);
                		free(pszCmd);
                	}
				}
				SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
				return 1;
			case ID_STORECMDHISTORY:
				if (MsgBox(gpSet->isSaveCmdHistory ? L"Do you want to disable history?" : L"Do you want to enable history?", MB_YESNO|MB_ICONQUESTION, NULL, hDlg) == IDYES)
				{
					gpSetCls->SetSaveCmdHistory(!gpSet->isSaveCmdHistory);
					HMENU hSysMenu = GetSystemMenu(hDlg, FALSE);
					CheckMenuItem(hSysMenu, ID_STORECMDHISTORY, MF_BYCOMMAND|(gpSet->isSaveCmdHistory ? MF_CHECKED : 0));
				}
				SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
				return 1;
			}
			break;

		case WM_COMMAND:

			if (HIWORD(wParam) == BN_CLICKED)
			{
				switch (LOWORD(wParam))
				{
					case IDC_CHOOSE:
					{
						wchar_t *pszFilePath = SelectFile(L"Choose program to run", NULL, hDlg, L"Executables (*.exe)\0*.exe\0All files (*.*)\0*.*\0\0", true, false, false);
						if (pszFilePath)
						{
							SetDlgItemText(hDlg, IDC_RESTART_CMD, pszFilePath);
							SafeFree(pszFilePath);
						}
						return 1;
					}
					case IDC_CHOOSE_DIR:
					{
						wchar_t* pszDefFolder = GetDlgItemText(hDlg, IDC_STARTUP_DIR);
						wchar_t* pszFolder = SelectFolder(L"Choose startup directory", pszDefFolder, hDlg, false, false);
						if (pszFolder)
						{
							SetDlgItemText(hDlg, IDC_STARTUP_DIR, pszFolder);
							SafeFree(pszFolder);
						}
						SafeFree(pszDefFolder);
						return 1;
					}
					case cbRunAsAdmin:
					{
						// BCM_SETSHIELD = 5644
						BOOL bRunAs = SendDlgItemMessage(hDlg, cbRunAsAdmin, BM_GETCHECK, 0, 0);

						if (gOSVer.dwMajorVersion >= 6)
						{
							SendDlgItemMessage(hDlg, IDC_START, 5644/*BCM_SETSHIELD*/, 0, bRunAs && (pDlg->mp_Args->aRecreate != cra_EditTab));
						}

						if (bRunAs)
						{
							CheckRadioButton(hDlg, rbCurrentUser, rbAnotherUser, rbCurrentUser);
							CheckDlgButton(hDlg, cbRunAsRestricted, BST_UNCHECKED);
							RecreateDlgProc(hDlg, UM_USER_CONTROLS, 0, 0);
						}

						return 1;
					}
					case rbCurrentUser:
					case rbAnotherUser:
					case cbRunAsRestricted:
					{
						RecreateDlgProc(hDlg, UM_USER_CONTROLS, LOWORD(wParam), 0);
						return 1;
					}
					case rbRecreateSplitNone:
					case rbRecreateSplit2Right:
					case rbRecreateSplit2Bottom:
					{
						RConStartArgs* pArgs = pDlg->mp_Args;
						switch (LOWORD(wParam))
						{
						case rbRecreateSplitNone:
							pArgs->eSplit = RConStartArgs::eSplitNone; break;
						case rbRecreateSplit2Right:
							pArgs->eSplit = RConStartArgs::eSplitHorz; break;
						case rbRecreateSplit2Bottom:
							pArgs->eSplit = RConStartArgs::eSplitVert; break;
						}
						EnableWindow(GetDlgItem(hDlg, tRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
						EnableWindow(GetDlgItem(hDlg, stRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
						if (pArgs->eSplit != pArgs->eSplitNone)
							SetFocus(GetDlgItem(hDlg, tRecreateSplit));
						return 1;
					}
					case IDC_START:
					{
						RConStartArgs* pArgs = pDlg->mp_Args;
						_ASSERTE(pArgs);
						SafeFree(pArgs->pszUserName);
						SafeFree(pArgs->pszDomain);

						//SafeFree(pArgs->pszUserPassword);
						if (SendDlgItemMessage(hDlg, rbAnotherUser, BM_GETCHECK, 0, 0))
						{
							pArgs->RunAsRestricted = crb_Off;
							pArgs->pszUserName = GetDlgItemText(hDlg, tRunAsUser);

							if (pArgs->pszUserName)
							{
								//pArgs->pszUserPassword = GetDlgItemText(hDlg, tRunAsPassword);
								// Попытаться проверить правильность введенного пароля и возможность запуска
								bool bCheckPwd = pArgs->CheckUserToken(GetDlgItem(hDlg, tRunAsPassword));
								DWORD nErr = bCheckPwd ? 0 : GetLastError();
								if (!bCheckPwd)
								{
									DisplayLastError(L"Invalid user name or password was specified!", nErr, MB_ICONSTOP, NULL, hDlg);
									return 1;
								}
							}
						}
						else
						{
							pArgs->RunAsRestricted = SendDlgItemMessage(hDlg, cbRunAsRestricted, BM_GETCHECK, 0, 0) ? crb_On : crb_Off;
						}

						// Vista+ (As Admin...)
						pArgs->RunAsAdministrator = SendDlgItemMessage(hDlg, cbRunAsAdmin, BM_GETCHECK, 0, 0) ? crb_On : crb_Off;

						// StartupDir (may be specified as argument)
						wchar_t* pszDir = GetDlgItemText(hDlg, IDC_STARTUP_DIR);
						wchar_t* pszExpand = (pszDir && wcschr(pszDir, L'%')) ? ExpandEnvStr(pszDir) : NULL;
						LPCWSTR pszDirResult = pszExpand ? pszExpand : pszDir;
						// Another user? We may fail with access denied. Check only for "current user" account
						if (!pArgs->pszUserName && pszDirResult && *pszDirResult && !DirectoryExists(pszDirResult))
						{
							wchar_t* pszErrInfo = lstrmerge(L"Specified directory does not exists!\n", pszDirResult, L"\n" L"Do you want to choose another directory?\n\n");
							DWORD nErr = GetLastError();
							int iDirBtn = DisplayLastError(pszErrInfo, nErr, MB_ICONEXCLAMATION|MB_YESNO, NULL, hDlg);
							if (iDirBtn == IDYES)
							{
								SafeFree(pszDir);
								SafeFree(pszExpand);
								SafeFree(pszErrInfo);
								return 1;
							}
							// User want to run "as is". Most likely it will fail, but who knows...
						}
						SafeFree(pArgs->pszStartupDir);
						pArgs->pszStartupDir = pszExpand ? pszExpand : pszDir;
						if (pszExpand)
						{
							SafeFree(pszDir)
						}

						// Command
						// pszSpecialCmd мог быть передан аргументом - умолчание для строки ввода
						SafeFree(pArgs->pszSpecialCmd);

						// GetDlgItemText выделяет память через calloc
						pArgs->pszSpecialCmd = GetDlgItemText(hDlg, IDC_RESTART_CMD);

						if (pArgs->pszSpecialCmd)
							gpSet->HistoryAdd(pArgs->pszSpecialCmd);

						if ((pArgs->aRecreate != cra_RecreateTab) && (pArgs->aRecreate != cra_EditTab))
						{
							if (SendDlgItemMessage(hDlg, cbRunInNewWindow, BM_GETCHECK, 0, 0))
								pArgs->aRecreate = cra_CreateWindow;
							else
								pArgs->aRecreate = cra_CreateTab;
						}
						if (((pArgs->aRecreate == cra_CreateTab) || (pArgs->aRecreate == cra_EditTab))
							&& (pArgs->eSplit != RConStartArgs::eSplitNone))
						{
							BOOL bOk = FALSE;
							int nPercent = GetDlgItemInt(hDlg, tRecreateSplit, &bOk, FALSE);
							if (bOk && (nPercent >= 1) && (nPercent <= 99))
							{
								pArgs->nSplitValue = (100-nPercent) * 10;
							}						
							//pArgs->nSplitPane = 0; Сбрасывать не будем?
						}
						pDlg->mn_DlgRc = IDC_START;
						EndDialog(hDlg, IDC_START);
						return 1;
					}
					case IDC_TERMINATE:
						pDlg->mn_DlgRc = IDC_TERMINATE;
						EndDialog(hDlg, IDC_TERMINATE);
						return 1;
					case IDCANCEL:
						pDlg->mn_DlgRc = IDCANCEL;
						EndDialog(hDlg, IDCANCEL);
						return 1;
				}
			}
			else if ((HIWORD(wParam) == EN_SETFOCUS) && lParam)
			{
				switch (LOWORD(wParam))
				{
				case tRecreateSplit:
				case tRunAsPassword:
					PostMessage((HWND)lParam, EM_SETSEL, 0, SendMessage((HWND)lParam, WM_GETTEXTLENGTH, 0,0));
					break;
				}
			}

			break;
		default:
			return 0;
	}
Exemplo n.º 11
0
VOID ViewNoises_OnCommand( HWND hwnd,
                           INT  id,
                           HWND hwndCtrl,
                           UINT codeNotify )
{
    INT i, j;
    HWND hwndList;
    LRESULT lResult;

    switch(id)
    {
    case IDC_NOISE_LIST:

        if (codeNotify == LBN_SELCHANGE)
        {
            ViewNoises_NoiseChanged(hwnd);
        }
        break;

    case IDC_NOISE_NEW:

        i = po->nNoises;

        if (i == MAX_NOISES)
        {
            MsgBox( hwnd,
                    MB_ICONEXCLAMATION,
                    "The limit of %d noises has been reached.",
                    MAX_NOISES );

            break;
        }

        _fmemset(szNewNoiseName, 0, sizeof(szNewNoiseName));

        wNewFlags = 0;
        nNewSoundIndex = -1;
        dNewRadius = 1000.0;
        dNewHeight = 3000.0;
        nNewDelay = 0;

        if (EditNoiseDialog(hwnd) == IDCANCEL)
        {
            break;
        }

        hwndList = GetDlgItem(hwnd, IDC_NOISE_LIST);

        ListBox_AddString(hwndList, szNewNoiseName);

        _fmemset(&po->pNoiseData[i], 0, sizeof(NOISE_DATA));

        _fstrcpy(po->pNoiseData[i].noise_name, szNewNoiseName);

        po->pNoiseData[i].flags = wNewFlags;
        po->pNoiseData[i].sound_index = nNewSoundIndex;
        po->pNoiseData[i].radius = (float)dNewRadius;
        po->pNoiseData[i].height = (float)dNewHeight;
        po->pNoiseData[i].delay = nNewDelay;

        ++po->nNoises;

        ListBox_SetCurSel(hwndList, i);
        ViewNoises_NoiseChanged(hwnd);

        bChange = TRUE;

        break;

    case IDC_NOISE_DELETE:

        hwndList = GetDlgItem(hwnd, IDC_NOISE_LIST);

        lResult = ListBox_GetCurSel(hwndList);

        if (lResult >= 0 && lResult < po->nNoises)
        {
            i = (INT)lResult;
            Object_DeleteNoise(po, i);
            ListBox_DeleteString(hwndList, i);

            if (i == 0)
                ListBox_SetCurSel(hwndList, 0);
            else
                ListBox_SetCurSel(hwndList, i - 1);

            ViewNoises_NoiseChanged(hwnd);

            bChange = TRUE;
        }

        break;

    case IDC_NOISE_EDIT:

        hwndList = GetDlgItem(hwnd, IDC_NOISE_LIST);

        lResult = ListBox_GetCurSel(hwndList);

        if (lResult >= 0 && lResult < po->nNoises)
        {
            i = (INT)lResult;

            _fstrcpy(szNewNoiseName, po->pNoiseData[i].noise_name);

            wNewFlags = po->pNoiseData[i].flags;
            nNewSoundIndex = po->pNoiseData[i].sound_index;
            dNewRadius = (double)po->pNoiseData[i].radius;
            dNewHeight = (double)po->pNoiseData[i].height;
            nNewDelay = po->pNoiseData[i].delay;

            if (EditNoiseDialog(hwnd) == IDCANCEL)
            {
                break;
            }

            if (!szNewNoiseName[0])
            {
                MsgBox( hwnd,
                        MB_ICONEXCLAMATION,
                        "The noise must be given a name." );

                break;
            }

            _fmemset(&po->pNoiseData[i], 0, sizeof(NOISE_DATA));

            _fstrcpy(po->pNoiseData[i].noise_name, szNewNoiseName);

            po->pNoiseData[i].flags = wNewFlags;
            po->pNoiseData[i].sound_index = nNewSoundIndex;
            po->pNoiseData[i].radius = (float)dNewRadius;
            po->pNoiseData[i].height = (float)dNewHeight;
            po->pNoiseData[i].delay = nNewDelay;

            j = ListBox_GetTopIndex(hwndList);

            ListBox_ResetContent(hwndList);

            for(i = 0; i < po->nNoises; ++i)
            {
                ListBox_AddString(hwndList, po->pNoiseData[i].noise_name);
            }

            ListBox_SetTopIndex(hwndList, j);
            ListBox_SetCurSel(hwndList, (INT)lResult);

            ViewNoises_NoiseChanged(hwnd);

            bChange = TRUE;
        }

        break;

    case IDOK:
    case IDCANCEL:

        if ( hPalCommon )
        {
            DeleteObject( hPalCommon );
            hPalCommon = NULL;
        }

        EndDialog( hwnd, IDOK );
        break;
    }

} // ViewNoises_OnCommand
Exemplo n.º 12
0
void CMonsterAttr::LoadAttr(char* filename)
{
	int Token;	int n;
	if ( fopen_s(&SMDFile,filename, "r") != 0 )
	{
		MsgBox("load error %s", filename);
		return;
	}
	n= 0;
	while ( true )
	{
		Token = GetToken();

		if ( Token == END )
			break;

		if ( Token == 1 )
		{
			this->m_MonsterAttr[n].m_Index = (int)TokenNumber;

			Token = GetToken();					this->m_MonsterAttr[n].m_Rate = (int)TokenNumber;
			Token = GetToken();					strcpy_s(this->m_MonsterAttr[n].m_Name, sizeof(this->m_MonsterAttr[n].m_Name), TokenString);
			Token = GetToken();					this->m_MonsterAttr[n].m_Level = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Hp = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Mp = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_DamageMin = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_DamageMax = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Defense = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MagicDefense = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_AttackRating = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Successfulblocking = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MoveRange = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_AttackType = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_AttackRange = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_ViewRange = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MoveSpeed = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_AttackSpeed = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_RegenTime = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Attribute = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_ItemRate = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MoneyRate = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MaxItemLevel = (int)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_MonsterSkill = (DWORD)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Resistance[R_ICE]  = (BYTE)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Resistance[R_POISON] = (BYTE)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Resistance[R_LIGHTNING] = (BYTE)TokenNumber;
			Token = GetToken();					this->m_MonsterAttr[n].m_Resistance[R_FIRE] = (BYTE)TokenNumber;

			this->m_MonsterAttr[n].m_Hp = this->m_MonsterAttr[n].m_Hp - (INT)(this->m_MonsterAttr[n].m_Hp / 100.0f * gMonsterHp);
			this->m_MonsterAttr[n].m_iScriptHP = this->m_MonsterAttr[n].m_Hp;

			if ( this->m_MonsterAttr[n].m_Level <= 24 && this->m_MonsterAttr[n].m_Index < 50)
			{
				if ( this->m_MonsterAttr[n].m_Level == 13 ||
					 this->m_MonsterAttr[n].m_Level == 14 ||
					 this->m_MonsterAttr[n].m_Level == 17 ||
					 this->m_MonsterAttr[n].m_Level == 18 ||
					 this->m_MonsterAttr[n].m_Level == 19 ||
					 this->m_MonsterAttr[n].m_Level == 24 )
				{
					int modiryvalue = this->m_MonsterAttr[n].m_Hp*20/100;
					modiryvalue-= modiryvalue*gMonsterHPAdjust/100;
					this->m_MonsterAttr[n].m_Hp -= modiryvalue;
				}
				else if ( this->m_MonsterAttr[n].m_Level == 20 ||
						  this->m_MonsterAttr[n].m_Level == 22 )
				{
					int modiryvalue = this->m_MonsterAttr[n].m_Hp*30/100;
					modiryvalue-= modiryvalue*gMonsterHPAdjust/100;
					this->m_MonsterAttr[n].m_Hp -= modiryvalue;
				}
				else
				{
					int modiryvalue = this->m_MonsterAttr[n].m_Hp/2;
					modiryvalue-= modiryvalue*gMonsterHPAdjust/100;
					this->m_MonsterAttr[n].m_Hp -= modiryvalue;
				}
			}

			if ( this->m_MonsterAttr[n].m_Level  <= 19 && this->m_MonsterAttr[n].m_Index  < 50 )
			{
				if ( this->m_MonsterAttr[n].m_Level == 13 ||
					 this->m_MonsterAttr[n].m_Level == 14 ||
					 this->m_MonsterAttr[n].m_Level == 17 ||
					 this->m_MonsterAttr[n].m_Level == 18 ||
					 this->m_MonsterAttr[n].m_Level == 19 )
				 {
					int modiryvaluemin = this->m_MonsterAttr[n].m_DamageMin*30/100;
					int modiryvaluemax = this->m_MonsterAttr[n].m_DamageMax*30/100;

					modiryvaluemin -= modiryvaluemin*gMonsterHPAdjust/100;
					modiryvaluemax -= modiryvaluemax*gMonsterHPAdjust/100;

					this->m_MonsterAttr[n].m_DamageMin -= modiryvaluemin;
					this->m_MonsterAttr[n].m_DamageMax -= modiryvaluemax;
				}
				else
				{
					int modiryvaluemin = this->m_MonsterAttr[n].m_DamageMin/2;
					int modiryvaluemax = this->m_MonsterAttr[n].m_DamageMax/2;

					modiryvaluemin -= modiryvaluemin*gMonsterHPAdjust/100;
					modiryvaluemax -= modiryvaluemax*gMonsterHPAdjust/100;

					this->m_MonsterAttr[n].m_DamageMin -= modiryvaluemin;
					this->m_MonsterAttr[n].m_DamageMax -= modiryvaluemax;
				}
			}	 

			n++;
			if ( n> MAX_MONSTER_TYPE-1 )
			{
				MsgBox("Monster attribute max over %s %d", __FILE__, __LINE__);
				fclose(SMDFile);
				return;
			}
		}
	}

	fclose(SMDFile);
}
Exemplo n.º 13
0
BOOL TMonsterAIMovePath::LoadData(LPSTR lpszFileName)
{
	this->m_bDataLoad = FALSE;

	if ( !lpszFileName || !strcmp(lpszFileName, ""))
	{
		MsgBox("[Monster AI MovePath] - File load error : File Name Error");
		return FALSE;
	}

	try
	{
		SMDToken Token;
		SMDFile = fopen(lpszFileName, "r");	//ok

		if ( SMDFile == NULL )
		{
			MsgBox("[Monster AI MovePath] - Can't Open %s ", lpszFileName);
			return FALSE;
		}

		this->DelAllAIMonsterMovePath();
		int iType = -1;

		while ( true )
		{
			Token = GetToken();

			if ( Token == END )
				break;

			iType = TokenNumber;

			while ( true )
			{
				if ( iType == 2 )
				{
					int iSpotType = -1;
					int iMapNumber = -1;
					int iX = -1;
					int iY = -1;

					Token = GetToken();

					if ( !strcmp("end", TokenString))
						break;

					iSpotType = TokenNumber;

					Token = GetToken();
					iMapNumber = TokenNumber;

					Token = GetToken();
					iX = TokenNumber;

					Token = GetToken();
					iY = TokenNumber;

					this->m_MovePathInfo[this->m_iMovePathSpotCount].m_iType = iSpotType;
					this->m_MovePathInfo[this->m_iMovePathSpotCount].m_iMapNumber = iMapNumber;
					this->m_MovePathInfo[this->m_iMovePathSpotCount].m_iPathX = iX;
					this->m_MovePathInfo[this->m_iMovePathSpotCount].m_iPathY = iY;

					this->m_iMovePathSpotCount++;

					if ( this->m_iMovePathSpotCount > MAX_MONSTER_AI_MOVE_PATH )
					{
						MsgBox("[Monster AI MovePath] Exceed Max Move Path-Spot ");
						this->DelAllAIMonsterMovePath();

						return FALSE;
					}
				}
			}
		}

		fclose(SMDFile);

		LogAddC(2, "[Monster AI MovePath ] - %s file is Loaded", lpszFileName);

		this->m_bDataLoad = TRUE;
	}
	catch(DWORD)
	{
		MsgBox("[Monster AI MovePath] - Loading Exception Error (%s) File. ", lpszFileName);
	}

	return FALSE;
}
Exemplo n.º 14
0
// Start the installation process
void ViInstallProcessStart(HWND hWnd, VI_INSTALL_DLG *d)
{
	wchar_t *exew;
	bool ok;
	char instdir[MAX_PATH];
	char hamcore[MAX_PATH];
	// Validate arguments
	if (hWnd == NULL || d == NULL)
	{
		return;
	}

	ViGenerateVpnSMgrTempDirName(instdir, sizeof(instdir), ViGetSuitableArchForCpu()->Build);
	ConbinePath(hamcore, sizeof(hamcore), instdir, "hamcore.se2");

	exew = setting.DownloadedInstallerPathW;
	d->NoClose = true;

	Hide(hWnd, IDCANCEL);
	SetPos(hWnd, P_PROGRESS, 100);
	Hide(hWnd, P_PROGRESS);
	Hide(hWnd, S_SIZEINFO);
	SetText(hWnd, S_STATUS, _U(IDS_INSTALLSTART+skip));

	ok = true;

	if (setting.DownloadNotRequired == false)
	{
		if (setting.WebMode && ViCheckExeSign(hWnd, exew) == false)
		{
			// The digital signature is not reliable
			ok = false;
		}
		else
		{
			// Installation
			HANDLE hProcess;
			SHELLEXECUTEINFOW info;

			// Run
			Zero(&info, sizeof(info));
			info.cbSize = sizeof(info);
			info.lpVerb = L"open";
			info.lpFile = exew;
			info.fMask = SEE_MASK_NOCLOSEPROCESS;
			info.lpParameters = L"/HIDESTARTCOMMAND:1 /DISABLEAUTOIMPORT:1 /ISWEBINSTALLER:1";
			info.nShow = SW_SHOWNORMAL;
			if (ShellExecuteExW(&info) == false)
			{
				MsgBox(hWnd, MB_ICONSTOP, _U(IDS_INSTALLSTART_ERROR+skip));
				ok = false;
			}
			else
			{
				hProcess = info.hProcess;

				// Wait for the install process to complete
				while (true)
				{
					if (WaitForSingleObject(hProcess, 50) != WAIT_TIMEOUT)
					{
						break;
					}

					DoEvents(hWnd);
				}
				CloseHandle(hProcess);
			}
		}
	}

	if (ok && d->WindowsShutdowning == false)
	{
		VI_SETTING_ARCH *a = ViGetSuitableArchForCpu();
		wchar_t arg[MAX_PATH];
		wchar_t exe[MAX_PATH];
		char *arg1 = "/easy";
		// Hide the screen
		Hide(hWnd, 0);

		if (setting.NormalMode)
		{
			arg1 = "/normal";
		}

		// (Just in case) start the VPN Client service
		if (MsIsServiceRunning("vpnclient") == false)
		{
			MsStartService("vpnclient");
		}

		// Wait for that the service becomes available
		SwWaitForVpnClientPortReady(0);

		if (UniIsEmptyStr(setting.DownloadedSettingPathW) == false)
		{
			// Start a connection by importing the configuration file into the VPN Client
			UniFormat(arg, sizeof(arg), L"%S \"%s\"", arg1, setting.DownloadedSettingPathW);
		}
		else
		{
			// Just start the Connection Manager
			UniFormat(arg, sizeof(arg), L"%S", arg1);
		}

		// Get the installation state
		ViLoadCurrentInstalledStatusForArch(a);

		if (a->CurrentInstalled)
		{
			HANDLE h;
			wchar_t filename[MAX_PATH];

			StrToUni(filename, sizeof(filename), a->VpnCMgrExeFileName);

			ConbinePathW(exe, sizeof(exe), a->CurrentInstalledPathW, filename);

			// Start the Connection Manager
			h = MsRunAsUserExW(exe, arg, false);
			if (h != NULL)
			{
				if (UniIsEmptyStr(setting.DownloadedSettingPathW) == false)
				{
					sleep_before_exit = true;
				}

				CloseHandle(h);
			}
		}
	}

	d->NoClose = false;
	Close(hWnd);
}
Exemplo n.º 15
0
extern bool DoMainLoop( dlg_state * state )
/*****************************************/
{
    const char          *diag_list[MAX_DIAGS + 1];
    const char          *diags;
    const char          *dstdir;
    int                 dstlen;
    bool                got_disk_sizes = FALSE;
    int                 i;
    char                newdst[_MAX_PATH];
    char                *next;
    bool                ret = FALSE;

    SetupTitle();

    // display initial dialog
    diags = GetVariableStrVal( "DialogOrder" );
    if( stricmp( diags, "" ) == 0 ) {
        diags = "Welcome";
    }
    i = 0;
    for( ;; ) {
        diag_list[i] = diags;
        next = strchr( diags, ',' );
        if( next == NULL ) break;
        *next = '\0';
        diags = next + 1;
        ++i;
    }
    diag_list[i + 1] = NULL;
    /* process installation dialogs */

    i = 0;
    for( ;; ) {
        if( i < 0 ) break;
        if( diag_list[i] == NULL ) {
            if( GetVariableIntVal( "DoCopyFiles" ) == 1 ) {
                if( !CheckDrive( TRUE ) ) {
                    i = 0;
                }
            }
            if( GetVariableByName( "SetupPath" ) != NO_VAR ) {
                ret = TRUE;
                break;
            }
            if( diag_list[i] == NULL ) {
                    StatusShow( TRUE );
                    ret = SetupOperations();
                    StatusShow( FALSE );
                    if( ret ) DoDialog( "Finished" );
                    break;
            }
        }
        if( stricmp( diag_list[i], "GetDiskSizesHere" ) == 0 ) {
            if( *state == DLG_NEXT ) {

                dstdir = GetVariableStrVal( "DstDir" );
                dstlen = strlen( dstdir );
                if( dstlen != 0 &&
                    (dstdir[dstlen - 1] == '\\' || dstdir[dstlen - 1] == '/') ) {
                    strcpy( newdst, dstdir );
                    if( dstlen == 3 && dstdir[1] == ':' ) {
                        newdst[dstlen] = '.';
                        newdst[dstlen + 1] = '\0';
                    } else {
                        newdst[dstlen - 1] = '\0';
                    }
                    SetVariableByName( "DstDir", newdst );
                }
                SimSetNeedGetDiskSizes();
                ResetDiskInfo();
                got_disk_sizes = TRUE;

            }
        } else {
            *state = DoDialog( diag_list[i] );
            GUIWndDirty( NULL );
            StatusCancelled();
        }
        if( *state == DLG_CAN ) {
            if( MsgBox( NULL, "IDS_QUERYABORT", GUI_YES_NO ) == GUI_RET_YES ) {
                CancelSetup = TRUE;
                break;
            }
        } else if( *state == DLG_DONE ) {
            CancelSetup = TRUE;
            break;
        }
        if( got_disk_sizes ) {
            if( !CheckDrive( FALSE ) ) {
                break;
            }
        }
        if( *state == DLG_SAME ) {
            /* nothing */
        } else if( *state == DLG_NEXT || *state == DLG_SKIP ) {
            if( SkipDialogs ) {
                ++i;
            } else {
                for( ;; ) {
                    ++i;
                    if( diag_list[i] == NULL ) break;
                    if( CheckDialog( diag_list[i] ) ) break;
                }
            }
        } else if( *state == DLG_PREV ) {
            for( ;; ) {
                --i;
                if( i < 0 ) break;
                if( CheckDialog( diag_list[i] ) ) break;
            }
        } else if( *state == DLG_START ) {
            i = 0;
        }
    } /* for */

    return( ret );
}
Exemplo n.º 16
0
/**
 * name:	DlgProcPspAbout()
 * desc:	dialog procedure
 *
 * return:	0 or 1
 **/
INT_PTR CALLBACK PSPProcContactProfile(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HWND hList = GetDlgItem(hDlg, LIST_PROFILE);
	LPLISTCTRL pList;

	switch (uMsg) {
		case WM_INITDIALOG:
		{
			LVCOLUMN lvc;
			RECT rc;
			LOGFONT lf;
			HFONT hFont;
			TOOLINFO ti;

			if (!hList || !(pList = (LPLISTCTRL)mir_alloc(sizeof(LISTCTRL)))) 
				return FALSE;
			ZeroMemory(pList, sizeof(LISTCTRL));

			TranslateDialogDefault(hDlg);
			Ctrl_InitTextColours();

			// init info structure
			pList->hList = hList;
			pList->nType = CTRL_LIST_PROFILE;
			ZeroMemory(&pList->labelEdit, sizeof(pList->labelEdit));
			SetUserData(hList, pList);

			// set new window procedure
			OldListViewProc = (WNDPROC)SetWindowLongPtr(hList, GWLP_WNDPROC, (LONG_PTR)&ProfileList_SubclassProc);
			
			// remove static edge in aero mode
			if (IsAeroMode())
				SetWindowLongPtr(hList, GWL_EXSTYLE, GetWindowLongPtr(hList, GWL_EXSTYLE)&~WS_EX_STATICEDGE);

			// insert columns into the listboxes					
			ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);


			PSGetBoldFont(hDlg, hFont);
			SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hFont, 0);

			// set listfont
			pList->hFont = (HFONT)SendMessage(hList, WM_GETFONT, 0, 0);
			pList->wFlags |= LVF_EDITLABEL;
			GetObject(pList->hFont, sizeof(lf), &lf);
			lf.lfHeight -= 6;
			hFont = CreateFontIndirect(&lf);
			SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0);

			GetClientRect(hList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);

			// initiate the tooltips
			pList->hTip = CreateWindowEx(WS_EX_TOPMOST,	TOOLTIPS_CLASS, NULL,
				WS_POPUP|TTS_BALLOON|TTS_NOPREFIX|TTS_ALWAYSTIP,
				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
				hList, NULL, ghInst, NULL);
			if (pList->hTip) {
				SetWindowPos(pList->hTip, HWND_TOPMOST,
					CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
					SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

				ZeroMemory(&ti, sizeof(TOOLINFO));
				ti.cbSize = sizeof(TOOLINFO);
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS|TTF_TRANSPARENT;
				ti.hinst = ghInst;
				ti.hwnd = hList;
				ti.uId = (UINT_PTR)hList;
				SendMessage(pList->hTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);
				SendMessage(pList->hTip, TTM_ACTIVATE, FALSE, (LPARAM)&ti);
			}		

			// insert columns into the listboxes					
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right / 8 * 3;
			ListView_InsertColumn(hList, 0, &lvc);
			lvc.cx = rc.right / 8 * 5;
			ListView_InsertColumn(hList, 1, &lvc);
			return TRUE;
		}

		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLORDLG:
			if (IsAeroMode())
				return (INT_PTR)GetStockBrush(WHITE_BRUSH);
			break;

		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->idFrom) {
				case 0:
				{
					HANDLE hContact = (HANDLE)((LPPSHNOTIFY)lParam)->lParam;
					LPCSTR pszProto;
					
					if (!PtrIsValid(pList = (LPLISTCTRL)GetUserData(hList))) break;

					switch (((LPNMHDR)lParam)->code) {
						// some account data may have changed so reread database
						case PSN_INFOCHANGED:
						{
							BYTE msgResult = 0;
							LPIDSTRLIST idList;
							UINT nList;
							BYTE i;
							INT iItem = 0,
								iGrp = 0,
								numProtoItems,
								numUserItems;

							if (!(pList->wFlags & CTRLF_CHANGED) && PSGetBaseProto(hDlg, pszProto) && *pszProto != 0) {
								ProfileList_Clear(hList);

								// insert the past information
								for (i = 0; i < 3; i++) {
									pFmt[i].GetList((WPARAM)&nList, (LPARAM)&idList);
									if ((numProtoItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, pszProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASPROTO)) < 0)
										return FALSE;

									// scan all basic protocols for the subcontacts
									if (DB::Module::IsMetaAndScan(pszProto)) {
										INT iDefault = CallService(MS_MC_GETDEFAULTCONTACTNUM, (WPARAM)hContact, NULL);
										HANDLE hSubContact, hDefContact;
										LPCSTR pszSubBaseProto;
										INT j, numSubs;
										
										if ((hDefContact = (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, iDefault)) &&
											 (pszSubBaseProto = DB::Contact::Proto(hDefContact)))
										{
											if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hDefContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
												return FALSE;

											// copy the missing settings from the other subcontacts
											numSubs = CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, NULL);
											for (j = 0; j < numSubs; j++) {
												if (j == iDefault) continue;
												if (!(hSubContact = (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, j))) continue;
												if (!(pszSubBaseProto = DB::Contact::Proto(hSubContact))) continue;
												if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
													return FALSE;
												//if ((numUserItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
												//	return FALSE;
											}
										}
									}
									if ((numUserItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASCUSTOM)) < 0)
										return FALSE;
									if (numUserItems || numProtoItems) {
										msgResult = PSP_CHANGED;
										ProfileList_AddGroup(hList, pFmt[i].szGroup, iGrp);
										iGrp = ++iItem;
									}
								}
							}
							SetWindowLongPtr(hDlg, DWLP_MSGRESULT, msgResult);
							break;
						}
						// user swiches to another propertysheetpage
						case PSN_KILLACTIVE:
							ProfileList_EndLabelEdit(hList, TRUE);
							break;
						// user selected to apply settings to the database
						case PSN_APPLY:
							if (pList->wFlags & CTRLF_CHANGED) {
								BYTE iFmt = -1;
								INT iItem;
								LVITEM lvi;
								TCHAR szGroup[MAX_PATH];
								CHAR pszSetting[MAXSETTING];
								LPLCITEM pItem;
								LPSTR pszModule = USERINFO;

								if (!hContact) PSGetBaseProto(hDlg, pszModule);

								*szGroup = 0;
								lvi.mask = LVIF_TEXT|LVIF_PARAM;
								lvi.pszText = szGroup;
								lvi.cchTextMax = MAX_PATH;

								for (iItem = lvi.iItem = lvi.iSubItem = 0; ListView_GetItem(hList, &lvi); lvi.iItem++) {
									if (!PtrIsValid(pItem = (LPLCITEM)lvi.lParam)) {
										// delete reluctant items
										if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
											DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem);
											DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem);
										}
										// find information about the group
										for (iFmt = 0; iFmt < SIZEOF(pFmt); iFmt++) {
											if (!_tcscmp(szGroup, pFmt[iFmt].szGroup)) {
												break;
											}
										}
										// indicate, no group was found. should not happen!!
										if (iFmt == SIZEOF(pFmt)) {
											*szGroup = 0;
											iFmt = -1;
										}
										iItem = 0;
									}
									else
									if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
										// save value
										if (!pItem->pszText[1] || !*pItem->pszText[1])
											continue;
										if (!(pItem->wFlags & (CTRLF_HASPROTO|CTRLF_HASMETA))) {
											mir_snprintf(pszSetting, MAXSETTING, pFmt[iFmt].szValFmt, iItem);
											DB::Setting::WriteTString(hContact, pszModule, pszSetting, pItem->pszText[1]);
											// save category
											mir_snprintf(pszSetting, MAXSETTING, pFmt[iFmt].szCatFmt, iItem);
											if (pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount)
												DB::Setting::WriteAString(hContact, pszModule, pszSetting, (LPSTR)pItem->idstrList[pItem->iListItem].pszText);
											else 
											if (pItem->pszText[0] && *pItem->pszText[0])
												DB::Setting::WriteTString(hContact, pszModule, pszSetting, (LPTSTR)pItem->pszText[0]);
											else									
												DB::Setting::Delete(hContact, pszModule, pszSetting);
											// redraw the item if required
											if (pItem->wFlags & CTRLF_CHANGED) {
												pItem->wFlags &= ~CTRLF_CHANGED;
												ListView_RedrawItems(hList, lvi.iItem, lvi.iItem);
											}
											iItem++;
										}
									}
								}
								// delete reluctant items
								if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
									DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem);
									DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem);
								}

								pList->wFlags &= ~CTRLF_CHANGED;
							}
							break;
					}
					break;
				}

				//
				// handle notification messages from the list control
				//
				case LIST_PROFILE:
				{
					LPLISTCTRL pList = (LPLISTCTRL)GetUserData(((LPNMHDR)lParam)->hwndFrom);

					switch (((LPNMHDR)lParam)->code) {
						case NM_RCLICK:
						{
							HMENU hMenu = CreatePopupMenu();
							MENUITEMINFO mii;
							HANDLE hContact;
							LVHITTESTINFO hi;
							LPLCITEM pItem;
							POINT pt;
							
							if (!hMenu) return 1;
							PSGetContact(hDlg, hContact);
							GetCursorPos(&pt);
							hi.pt = pt;
							ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hi.pt);
							ListView_SubItemHitTest(((LPNMHDR)lParam)->hwndFrom, &hi);
							pItem = ProfileList_GetItemData(((LPNMHDR)lParam)->hwndFrom, hi.iItem);

							// insert menuitems
							ZeroMemory(&mii, sizeof(MENUITEMINFO));
							mii.cbSize = sizeof(MENUITEMINFO);
							mii.fMask = MIIM_ID|MIIM_STRING;
							// insert "Add" Menuitem
							mii.wID = BTN_ADD_intEREST;
							mii.dwTypeData = TranslateT("Add Interest");
							InsertMenuItem(hMenu, 0, TRUE, &mii);
							mii.wID = BTN_ADD_AFFLIATION;
							mii.dwTypeData = TranslateT("Add Affliation");
							InsertMenuItem(hMenu, 1, TRUE, &mii);
							mii.wID = BTN_ADD_PAST;
							mii.dwTypeData = TranslateT("Add Past");
							InsertMenuItem(hMenu, 2, TRUE, &mii);

							if (hi.iItem != -1 && PtrIsValid(pItem) && !(hContact && (pItem->wFlags & CTRLF_HASPROTO))) {
								// insert separator
								mii.fMask = MIIM_FTYPE;
								mii.fType = MFT_SEPARATOR;
								InsertMenuItem(hMenu, 3, TRUE, &mii);
								// insert "Delete" Menuitem
								mii.fMask = MIIM_ID|MIIM_STRING;
								mii.wID = BTN_EDIT_CAT;
								mii.dwTypeData = TranslateT("Edit Category");
								InsertMenuItem(hMenu, 4, TRUE, &mii);
								mii.wID = BTN_EDIT_VAL;
								mii.dwTypeData = TranslateT("Edit Value");
								InsertMenuItem(hMenu, 5, TRUE, &mii);
								mii.fMask = MIIM_FTYPE;
								mii.fType = MFT_SEPARATOR;
								InsertMenuItem(hMenu, 6, TRUE, &mii);
								// insert "Delete" Menuitem
								mii.fMask = MIIM_ID|MIIM_STRING;
								mii.wID = BTN_DEL;
								mii.dwTypeData = TranslateT("Delete");
								InsertMenuItem(hMenu, 7, TRUE, &mii);
							}
							TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hDlg, 0);
							DestroyMenu(hMenu);
							return 0;
						}
						/*case LVN_BEGINSCROLL:
							SetFocus(((LPNMHDR)lParam)->hwndFrom);
							break;
							*/
						case LVN_GETDISPINFO:
							if (pList->labelEdit.iTopIndex != ListView_GetTopIndex(hList))
								ProfileList_EndLabelEdit(((LPNMHDR)lParam)->hwndFrom, FALSE);
							break;
						case NM_CUSTOMDRAW:
						{
							LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam;
							LPLCITEM pItem = (LPLCITEM)cd->nmcd.lItemlParam;
							RECT rc;

							switch (cd->nmcd.dwDrawStage) {
								case CDDS_PREPAINT:
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
									return TRUE;
								
								case CDDS_ITEMPREPAINT:
									ListView_GetItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, &rc, LVIR_BOUNDS);
									if (!PtrIsValid(pItem)) {
										HFONT hBold, hFont;
										TCHAR szText[MAX_PATH];
										
										PSGetBoldFont(hDlg, hBold);
										hFont = (HFONT)SelectObject(cd->nmcd.hdc, hBold);
										SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW));
										ProfileList_GetItemText(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 0, szText, MAX_PATH);
										rc.left += 6;
										DrawText(cd->nmcd.hdc, TranslateTS(szText), -1, &rc, DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);

										rc.bottom -= 2;
										rc.top = rc.bottom - 1;
										rc.left -= 6;
										DrawEdge(cd->nmcd.hdc, &rc, BDR_SUNKENOUTER, BF_RECT);

										SelectObject(cd->nmcd.hdc, hFont);
										SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
										return TRUE;
									}
									// draw selected item
									if ((cd->nmcd.uItemState & CDIS_SELECTED) || (pList->labelEdit.iItem == cd->nmcd.dwItemSpec)) {
										SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
										FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT));
									}
									// draw background of unselected item
									else {
										SetTextColor(cd->nmcd.hdc, 
											(pItem->wFlags & CTRLF_CHANGED) 
												? clrChanged : (pItem->wFlags & CTRLF_HASMETA)
													? clrMeta : ((pItem->wFlags & (CTRLF_HASCUSTOM)) && (pItem->wFlags & CTRLF_HASPROTO))
														? clrBoth : (pItem->wFlags & CTRLF_HASCUSTOM)
															? clrCustom	: clrNormal);
										FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
									}
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW);
									return TRUE;
								
								case CDDS_SUBITEM|CDDS_ITEMPREPAINT:
								{
									HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, pList->hFont);

									ListView_GetSubItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, cd->iSubItem, LVIR_BOUNDS, &rc);
									if (cd->iSubItem == 0) {
										RECT rc2;
										ListView_GetSubItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rc2);
										rc.right = rc2.left;
									}
									rc.left += 3;
									DrawText(cd->nmcd.hdc,
										pItem->pszText[cd->iSubItem] 
											? pItem->pszText[cd->iSubItem] 
											: (cd->iSubItem == 0 && pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount)
												? pItem->idstrList[pItem->iListItem].ptszTranslated
												: TranslateT("<empty>"),
										-1, &rc, DT_END_ELLIPSIS|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
									return TRUE;
								}
							} /* switch (cd->nmcd.dwDrawStage) */
							break;
						} /* case NM_CUSTOMDRAW: */
					} /* (((LPNMHDR)lParam)->code) */
					break;
				}
			}
			break; /* case WM_NOTIFY: */

		case WM_COMMAND:
		{
			switch (LOWORD(wParam)) {
				case BTN_ADD_intEREST:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[2]);
				case BTN_ADD_AFFLIATION:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[1]);
				case BTN_ADD_PAST:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[0]);
				case BTN_EDIT_CAT:
					ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 0);
					break;
				case BTN_EDIT_VAL:
					ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 1);
					break;
				case BTN_DEL:
					if (IDYES == MsgBox(hDlg, MB_YESNO|MB_ICON_QUESTION, LPGENT("Question"), LPGENT("Delete an entry"), LPGENT("Do you really want to delete this entry?"))) {
						INT iItem = ListView_GetSelectionMark(hList);
						LPLISTCTRL pList = (LPLISTCTRL)GetUserData(hList);

						ProfileList_DeleteItem(hList, iItem);
						if (PtrIsValid(pList)) pList->wFlags |= CTRLF_CHANGED;
						SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL);
						// check if to delete any devider
						if (!ProfileList_GetItemData(hList, iItem--) && !ProfileList_GetItemData(hList, iItem))
							ListView_DeleteItem(hList, iItem);
					}
					break;
			}
			break;
		}
	}
	return FALSE;
}
Exemplo n.º 17
0
/********************************** 功能说明 ***********************************
*	系统配置 -> 大气压
*******************************************************************************/
static	void	menu_Configure_Ba( void )
{
    static const struct uMenu menu[] =
    {
        { 0x0301u, "配置大气压" },
        { 0x0802u, "方式" },
        { 0x1002u, "预测大气压" },
        { 0x1802u, "输入" }
    };
		static const struct uMenu menu1[] =
    {
        { 0x0101u, "配置大气压" },
        { 0x0802u, "方式" },
     
    };
    uint8_t item = 1u;
    BOOL	need_redraw = TRUE;

    uint8_t 	Mothed_Ba = Configure.Mothed_Ba;
    uint16_t	set_Ba    = Configure.set_Ba;
    BOOL	changed = FALSE;

    do
    {
        if ( need_redraw )
        {
            cls();
           if( Mothed_Ba == enumUserInput )
            Menu_Redraw( menu );
					else
						Menu_Redraw( menu1 );
            need_redraw = FALSE;
        }
				if( Mothed_Ba == enumUserInput )
					ShowI16U( 0x180Cu, set_Ba, 0x0602u, "kPa" );

        switch ( Mothed_Ba )
        {
        default:
        case enumUserInput:
            Lputs( 0x080Cu, "[预测输入]" );
            break;
        case enumMeasureBa:
            Lputs( 0x080Cu, "[实时测量]" );
            break;
        }
        if( Mothed_Ba == enumUserInput )
					item = Menu_Select( menu, item, NULL );
				else
					item = Menu_Select( menu1, item, NULL );

        switch ( item )
        {
        case 0:
					if ( changed )
					{
							need_redraw = TRUE;
							switch( MsgBox( "保存修改结果 ?", vbYesNoCancel + vbDefaultButton3 ))
							{
							case vbYes:
									Configure.Mothed_Ba = Mothed_Ba;
									Configure.set_Ba    = set_Ba;
									ConfigureSave();
									break;
							case vbNo:
									break;
							case vbCancel:
									item = 1u;
									break;
							default:
									break;
							}
					}
					break;

        case 1:
					switch ( Mothed_Ba )
					{
					default:
					case enumUserInput:
							Mothed_Ba = enumMeasureBa;
							break;
					case enumMeasureBa:
							Mothed_Ba = enumUserInput;
							break;
					}
					changed = TRUE;
					need_redraw = TRUE;	 
					break;
        case 2:
					if( Mothed_Ba == enumUserInput )
          {
						cls();
            Lputs( 0x0202u, "测量大气压" );
            do
            {
                FP32 Ba = get_Ba();
                set_Ba = Ba * 100.0f + 0.5f;
                if ( set_Ba > 12000u )
                {
                    set_Ba = 12000u;
                }
                if ( set_Ba <  3000u )
                {
                    set_Ba =  3000u;
                }
                ShowI16U( 0x0C05u, set_Ba, 0x0602u, "kPa" );
            }
            while ( ! hitKey( 100u ));
            ( void ) getKey();
            changed = TRUE;
					}
            need_redraw = TRUE;
            break;
        case 3:
           if ( EditI16U( 0x180Cu, &set_Ba, 0x0602u ))
            {
                changed = TRUE;
            }
            if ( set_Ba > 12000u )
            {
                set_Ba = 12000u;
            }
            if ( set_Ba <  3000u )
            {
                set_Ba =  3000u;
            }break;

        default:
            break;
        }
    }
    while ( 0u != item );
}
Exemplo n.º 18
0
void CGambleSystem::Load(char* filename) //0049B9D0  (Identical)
{
	this->bLoad = FALSE;
	this->m_iGambleBagCount = 0;

	SMDFile = fopen(filename, "r");	//ok

	if ( SMDFile == NULL )
	{
		LogAdd(lMsg.Get(453), filename);
		return;
	}
	SMDToken Token;

	int n = 0;
	int iProbability = 0;
	int Count = 0;

	while(true)
	{
		Token = GetToken();

		if ( Token == END )
		{
			break;
		}

		if ( Token == 1 )
		{
			int Type = TokenNumber;

			if (Type == 0)
			{
				Count = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							break;
						}
					}

					if ( Count > GAMBLE_MAX_ITEM_INFO )
					{
						MsgBox("Load Script Error %s",filename);
						break;
					}

					m_GamblingInfo[Count].m_iSkillRate = TokenNumber;

					Token = GetToken();
					m_GamblingInfo[Count].m_iLuckRate = TokenNumber;

					Token = GetToken();
					m_GamblingInfo[Count].m_iOptionRate = TokenNumber;

					Token = GetToken();
					m_GamblingInfo[Count].m_iExcRate = TokenNumber;

					Token = GetToken();
					m_GamblingInfo[Count].m_iSortItemRate = TokenNumber;
					
					Count++;
				}
			}
			else if (Type == 1)
			{
				Count = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							break;
						}
					}
					if ( Count > GAMBLE_MAX_SECRET_ITEM_CLASS )
					{
						MsgBox("Load Script Error %s",filename);
						break;
					}

					this->m_iBagItemOptionRate[Count] = TokenNumber;

					Count++;
				}
			}
			else if (Type == 2)
			{
				Count = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							break;
						}
					}

					if ( Count > GAMBLE_MAX_NORMAL_ITEM )
					{
						MsgBox("Load Script Error %s",filename);
						break;
					}

					this->m_dwSpecialItemRate[Count] = TokenNumber;

					Count++;
				}
			}
			else if (Type == 3)
			{
				Count = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							break;
						}
					}
					if ( Count > GAMBLE_MAX_SECRET_ITEM_CLASS )
					{
						MsgBox("Load Script Error %s",filename);
						break;
					}

					this->m_iBagItemExcRate[Count] = TokenNumber;

					Count++;
				}
			}
			else if (Type == 4)
			{
				Count = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							break;
						}
					}

					if ( Count > GAMBLE_MAX_SECRET_ITEM_TYPE )
					{
						MsgBox("Load Script Error %s",filename);
						break;
					}

					this->m_iExcRatePerItemKind[Count] = TokenNumber;

					Token = GetToken();
					this->m_iGeneralExcRate[Count] = TokenNumber;

					Count++;
				}
			}
			else if (Type >= 5)
			{
				n = 0;

				while(true)
				{
					Token = GetToken();

					if( Token == 0 )
					{
						if (strcmp("end",TokenString) == 0)
						{
							this->m_iDropRatePerItemCount[iProbability] = n;
							break;
						}
					}
					
					this->BagObject[m_iGambleBagCount].m_type = TokenNumber;
						
					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_index = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_minLevel = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_maxLevel = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_isskill = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_isluck = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_isoption = TokenNumber;

					Token = GetToken();
					this->BagObject[m_iGambleBagCount].m_isexitem = TokenNumber;

					if(this->BagObject[m_iGambleBagCount].m_minLevel > this->BagObject[m_iGambleBagCount].m_maxLevel )
					{
						MsgBox("Load Script Error %s",filename);
						return;
					}
					
					n++;
					this->m_iGambleBagCount++;

					if (this->m_iGambleBagCount > GAMBLE_MAX_ITEM-1 )
					{
						break;
					}

				}

				iProbability++;

				if(iProbability > GAMBLE_MAX_ITEM_INFO-1)
				{
					break;
				}

				this->m_iRateKindCount = iProbability;
			}
		}
	}

	fclose(SMDFile);
	LogAdd(lMsg.Get(454), filename);
	this->bLoad = TRUE;
}
Exemplo n.º 19
0
static	void	Configure_Heater( void )
{
    static	struct	uMenu	const	menu[] =
    {
        {	0x0201u, "配置加热器"	},
        {	0x0C02u, "开  关"	},
				{	0x1802u, "设置温度"	},
    };
		 static	struct	uMenu	const	menu1[] =
    {
        {	0x0101u, "配置加热器"	},
				{	0x0C02u, "开  关"	},
    };
static	CHAR  const * const HeaterSW[] = {"[停用]", "[启用]" };
			
    uint8_t 	item = 1u;
		uint8_t 		state  = Configure.Heater_SW;          //	加热器开关
    uint16_t	SetTemp = Configure.Heater_SetTemp;			//	加热器恒温温度
    BOOL		changed = FALSE;
    BOOL		need_redraw = TRUE;
   
    do {
        if ( need_redraw )
        {
            cls();
            if( state == FALSE )
							Menu_Redraw( menu1 );
						else
							Menu_Redraw( menu );
            need_redraw = FALSE;
        }
				if( state == TRUE )
					ShowI16U( 0x0C14U, SetTemp, 0x0501U, "℃" );
        Lputs( 0x0C19, HeaterSW[state] );
       if( state == FALSE )
					item = Menu_Select( menu1, item, NULL );
				else
					item = Menu_Select( menu, item, NULL );
        switch( item )
        {
        case 1u:
					need_redraw = TRUE;
					state = ! state; 
					changed = TRUE;
					break;
         case 2u: /* 注意: 因为恒温箱的设置温度范围是正数, 所以才可以使用无符号数编辑程序进行编辑 */
					if( state == TRUE )
					 if ( EditI16U( 0x1814U, &SetTemp, 0x0501U ))
						{
							if ( SetTemp <  150u )
							{
								SetTemp = 150u;
								beep();
							}
							if ( SetTemp >  350u )
							{
								SetTemp = 350u;
								beep();
							}
							changed = TRUE;
						}	
					need_redraw = TRUE;
					break;
        case 0u:
				if ( changed )
				{
						need_redraw = TRUE;
						switch ( MsgBox( "保存配置数据 ?", vbYesNoCancel + vbDefaultButton3 ))
						{
						case vbYes:
								Configure.Heater_SetTemp = SetTemp;
								Configure.Heater_SW = state;
								ConfigureSave();
								set_HeaterTemp( Configure.Heater_SetTemp * 0.1f );
								break;
						case vbNo:
								ConfigureLoad();
								break;
						case vbCancel:
								item = 1u;
								break;
						default:
								break;
						}
					}
					break;
        default:
					break;
        }
    }
    while ( enumSelectESC != item );
}
Exemplo n.º 20
0
	LONG MsgBox(LPCTSTR lpszContent,LPCTSTR lpszTitle)
	{
		return MsgBox(lpszContent,lpszTitle,MB_OK);
	}
Exemplo n.º 21
0
static	void	Configure_Flow_KB2400( void )
{
    static	struct  uMenu  const  menu[] =
    {
        { 0x0201u, "设置采样流量" },
        { 0x0C00u, "日均A" },
        { 0x1400u, "日均B" },

    };
    uint8_t	item = 0u;
    BOOL	changed = FALSE;
    BOOL	need_redraw = TRUE;

    do
    {
        if ( need_redraw )
        {
            cls();
            Menu_Redraw( menu );
            need_redraw = FALSE;
        }

        ShowI16U( 0x0C0Fu, Configure.SetFlow[PP_R24_A], 0x0503u, " L/m" );
        ShowI16U( 0x140Fu, Configure.SetFlow[PP_R24_B], 0x0503u, " L/m" );

        item = Menu_Select( menu, item + 1u, NULL );
        switch( item )
        {
        case 0:
            if ( changed )
            {
                need_redraw = TRUE;
                switch( MsgBox( "保存修改结果 ?", vbYesNoCancel + vbDefaultButton3 ))
                {
                case vbYes:
                    ConfigureSave();
                    break;
                case vbNo:
                    ConfigureLoad();
                    break;
                case vbCancel:
                    item = 1u;
                    break;
                default:
                    break;
                }
            }
            break;
        case 1:
            if( EditI16U( 0x0C0Fu, & Configure.SetFlow[PP_R24_A], 0x0503u ))
            {
                if ( Configure.SetFlow[PP_R24_A] >  300u )
                {
                    Configure.SetFlow[PP_R24_A] =  300u;
                }
                if ( Configure.SetFlow[PP_R24_A] <  100u )
                {
                    Configure.SetFlow[PP_R24_A] =  100u;
                }
                changed = TRUE;
            }
            break;
        case 2:
            if( EditI16U( 0x140Fu, & Configure.SetFlow[PP_R24_B], 0x0503u ))
            {
                if ( Configure.SetFlow[PP_R24_B] >  300u )
                {
                    Configure.SetFlow[PP_R24_B] =  300u;
                }
                if ( Configure.SetFlow[PP_R24_B] <  100u )
                {
                    Configure.SetFlow[PP_R24_B] =  100u;
                }
                changed = TRUE;
            }
            break;
        default:
            break;
        }
    }
    while( enumSelectESC != item );
}
Exemplo n.º 22
0
	LONG MsgBox(LPCTSTR lpszContent)
	{
		return MsgBox(lpszContent,MB_OK);
	}
Exemplo n.º 23
0
static	void	Configure_Flow_KB6120C( void )
{
    static	struct  uMenu  const  menu[] =
    {
        { 0x0401u, "设置采样流量" },
        { 0x0800u, "日均A" },
				{ 0x0C00u, "日均B" },
        { 0x1200u, "粉 尘" },
        { 0x1600u, "限 压" },
    };
    uint8_t	item = 0u;
    BOOL	changed = FALSE;
    BOOL	need_redraw = TRUE;

    do
    {
			if ( need_redraw )
			{
				cls();
				Menu_Redraw( menu );
				need_redraw = FALSE;
			}

			ShowI16U( 0x080Fu, Configure.SetFlow[PP_R24_A], 0x0503u, " L/m" );
			ShowI16U( 0x0C0Fu, Configure.SetFlow[PP_R24_B], 0x0503u, " L/m" );
			ShowI16U( 0x120Fu, Configure.SetFlow[PP_TSP  ], 0x0501u, " L/m" );
			if ( Configure.TSP_Pr_Portect != 0u )
			{
				ShowI16U( 0x1611u, Configure.TSP_Pr_Portect , 0x0502u," kPa" );
			}
			else
			{
				Lputs( 0x1611, "[停用]      " );
			}

        item = Menu_Select( menu, item + 1u, NULL );
        switch( item )
        {
        case 0:
					if ( changed )
					{
							need_redraw = TRUE;
							switch( MsgBox( "保存修改结果 ?", vbYesNoCancel + vbDefaultButton3 ))
							{
							case vbYes:
									ConfigureSave();
									break;
							case vbNo:
									ConfigureLoad();
									break;
							case vbCancel:
									item = 1u;
									break;
							default:
									break;
							}
					}
					break;
        case 1:
          if( EditI16U( 0x080Fu, & Configure.SetFlow[PP_R24_A], 0x0503u ))
					{
							if ( Configure.SetFlow[PP_R24_A] >  300u )
							{
									Configure.SetFlow[PP_R24_A] =  300u;
							}
							if ( Configure.SetFlow[PP_R24_A] <  100u )
							{
									Configure.SetFlow[PP_R24_A] =  100u;
							}
							changed = TRUE;
					}
					break;
				case 2:
					if( EditI16U( 0x0C0Fu, & Configure.SetFlow[PP_R24_B], 0x0503u ))
            {
                if ( Configure.SetFlow[PP_R24_B] >  300u )
                {
                    Configure.SetFlow[PP_R24_B] =  300u;
                }
                if ( Configure.SetFlow[PP_R24_B] <  100u )
                {
                    Configure.SetFlow[PP_R24_B] =  100u;
                }
                changed = TRUE;
            }
           break;
        case 3:
           if( EditI16U( 0x120Fu, & Configure.SetFlow[PP_TSP  ], 0x0501u ))
            {
                if ( Configure.SetFlow[PP_TSP  ] > 1400u )
                {
                    Configure.SetFlow[PP_TSP  ] = 1400u;
                }
                if ( Configure.SetFlow[PP_TSP  ] <  600u )
                {
                    Configure.SetFlow[PP_TSP  ] =  600u;
                }
                changed = TRUE;
            }
           break;  
        case 4:
           if( EditI16U( 0x1611u, &Configure.TSP_Pr_Portect , 0x0502u ) )
					{
						if ( Configure.TSP_Pr_Portect > 2000u )
						{
							Configure.TSP_Pr_Portect = 2000u;
						}
						changed = TRUE;
					}
					break;
        default:
            break;
        }
    }
    while( enumSelectESC != item );
}
Exemplo n.º 24
0
	LONG MsgBox(LPCTSTR lpszContent,LONG type)
	{  
		return MsgBox(lpszContent,AfxGetAppName(),
			type);
	}
Exemplo n.º 25
0
BOOL USBPrint_TSP( uint16_t FileNum, struct uFile_TSP  const * pFile )
{
    struct	tm	t_tm;
    time_t	now;
    CHAR	sbuffer[512];
    CHAR	sbuffert[40];
    uint32_t s;
    s = ByteGetSize("\\USB_TSP\\TSP.TXT") / 512 ;
    memset( sbuffer, 0x00, 512 );
    sprintf( sbuffert, "\r\n%s型%s\r\n",szTypeIdent[Configure.InstrumentType],szNameIdent[Configure.InstrumentName] );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "粉尘采样记录\r\n");
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "文件:%3u [第%2u次/共%2u次]\r\n", FileNum, pFile->run_loops, pFile->set_loops );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    (void)_localtime_r ( &pFile->sample_begin, &t_tm );
    sprintf( sbuffert, "开始时间:%2d月%2d日 %02d:%02d\r\n", t_tm.tm_mon + 1, t_tm.tm_mday, t_tm.tm_hour, t_tm.tm_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "设置采样时间: %02u:%02u\r\n", pFile->set_time / 60u, pFile->set_time % 60u );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "设置采样流量: %5.1f L/m\r\n", pFile->set_flow * 0.1f );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "累计采样时间: %02u:%02u\r\n", pFile->sum_min / 60u, pFile->sum_min % 60u );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "采样体积(工): %7.1f L\r\n", pFile->vd  );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "采样体积(标): %7.1f L\r\n", pFile->vnd );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "平均流量(工): %6.2f L/m\r\n", (FP32)pFile->vd  / pFile->sum_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "平均流量(标): %6.2f L/m\r\n", (FP32)pFile->vnd / pFile->sum_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "平均计前温度: %6.2f ℃\r\n", pFile->sum_tr / pFile->sum_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "平均计前压力: %6.2f kPa\r\n", pFile->sum_pr / pFile->sum_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    sprintf( sbuffert, "平均大气压力: %6.2f kPa\r\n", pFile->sum_Ba / pFile->sum_min );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    now = get_Now( );
    (void)_localtime_r ( &now, &t_tm );
    sprintf( sbuffert, "  == %4d/%2d/%2d %02d:%02d:%02d ==\r\n",
             t_tm.tm_year + 1900, t_tm.tm_mon + 1, t_tm.tm_mday, t_tm.tm_hour, t_tm.tm_min, t_tm.tm_sec );
    strcat( sbuffer, sbuffert );
    memset( sbuffert, 0x00, 40 );
    delay_us(1);
    if( !USBSave("\\USB_TSP\\TSP.TXT", s + 1, ( uint8_t *)sbuffer, ( sizeof( sbuffer ) + 511 ) / 512 ) )
    {
        SD_Init();
        return FALSE;
    }
    SD_Init();
    MsgBox( "OK! 请拔出U盘 !", vbOKOnly );
    return TRUE;
}
Exemplo n.º 26
0
BOOL CCastleDeepEvent::Load(char * lpszFileName)
{	
	//DebugLog("%s START",__FUNCTION__);
	if( lpszFileName == NULL ) return FALSE;
		
	SMDFile = fopen(lpszFileName, "r");
	
	if ( SMDFile == FALSE )
	{
		MsgBox("[CastleDeep Event] Info file Load Fail [%s]", lpszFileName);
		
		//DebugLog("%s END",__FUNCTION__);
		return FALSE;
	}
	EnterCriticalSection(&this->m_critEventData);

	this->m_vtAssultType.clear();
	this->m_vtAssultTypeRate.clear();
	this->m_mapSpawnTime.clear();
	this->m_mapMonsterInfo.clear();
	this->m_vtEventTime.clear();
	this->m_vtAssultTypeRate.clear();
	this->m_mapRunCheck.clear();

	LeaveCriticalSection(&this->m_critEventData);

	this->m_bHasData = FALSE;
	int type = -1;
	SMDToken Token;

	while( true )
	{
		Token = GetToken();
		if( Token == 2 )
		{
			break;
		}

		if( Token == NUMBER )
		{
			while(true)
			{
				//Token = GetToken();
				type = TokenNumber;

				if( type == 0 )
				{
					while(true)
					{
						Token = GetToken();
					
						if( strcmp("end", TokenString) == 0 ) 
						{
							type++;
							break;
						}
					
						CASTLEDEEP_EVENTTIME m_EventTime;

						m_EventTime.m_iHour = TokenNumber; 
						Token = GetToken();
						m_EventTime.m_iMinute = TokenNumber;

						this->m_vtEventTime.push_back(m_EventTime);
					}
				}
				else if( type == 1 )
				{
					while(true)
					{
						std::vector<CASTLEDEEP_MONSTERINFO> vecMonsterInfo;
						std::vector<CASTLEDEEP_SPAWNTIME> vecEventSpawnTime;
						Token = GetToken();

						if( strcmp("end", TokenString) == 0 ) 
						{
							vecMonsterInfo.clear();
							vecEventSpawnTime.clear();
							type++;
							break;
						}
						CASTLEDEEP_SPAWNTIME	m_SpawnTime;

						m_SpawnTime.m_iMonsterGroup = TokenNumber;
						
						Token = GetToken();
						m_SpawnTime.m_iMonsterSpawnMinute = TokenNumber;

						this->m_mapMonsterInfo.insert( std::pair<int, std::vector<CASTLEDEEP_MONSTERINFO> >(m_SpawnTime.m_iMonsterGroup,vecMonsterInfo) );
						this->m_mapSpawnTime.insert( std::pair<int, std::vector<CASTLEDEEP_SPAWNTIME> >(m_SpawnTime.m_iMonsterGroup, vecEventSpawnTime ) );
					
						this->m_vtAssultType.push_back(m_SpawnTime.m_iMonsterGroup);
						this->m_vtAssultTypeRate.push_back(m_SpawnTime.m_iMonsterSpawnMinute);
					}
				}
				else if(type == 2)
				{
					while(true)
					{
						Token = GetToken();
						if( strcmp("end", TokenString) == 0 ) 
						{
							type++;
							break;
						}

						CASTLEDEEP_SPAWNTIME	m_SpawnTime;
						int m_iSpawnTimeIndex;

						m_iSpawnTimeIndex = TokenNumber;

						Token = GetToken();
						m_SpawnTime.m_iMonsterGroup = TokenNumber;

						Token = GetToken();
						m_SpawnTime.m_iMonsterSpawnMinute = TokenNumber;

						EnterCriticalSection(&this->m_critEventData);

						std::map<int, std::vector<CASTLEDEEP_SPAWNTIME> >::iterator it = this->m_mapSpawnTime.find(m_iSpawnTimeIndex);

						if( it != this->m_mapSpawnTime.end() )
						{
							it->second.push_back(m_SpawnTime);
						}
					
						LeaveCriticalSection(&this->m_critEventData);
					}
				}
				else if(type == 3)
				{
					while(true)
					{
						Token = GetToken();
						if( strcmp("end", TokenString) == 0 ) 
						{
							break;
						}

						CASTLEDEEP_MONSTERINFO	m_MonsterInfo;
						int m_iMonsterInfoIndex;

						m_iMonsterInfoIndex = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iMonsterGroup = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iMonsterType = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iMonsterNumber = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iSX = TokenNumber;
						
						Token = GetToken();
						m_MonsterInfo.m_iSY = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iDX = TokenNumber;

						Token = GetToken();
						m_MonsterInfo.m_iDY = TokenNumber;

						EnterCriticalSection(&this->m_critEventData);

						std::map<int, std::vector<CASTLEDEEP_MONSTERINFO> >::iterator it = this->m_mapMonsterInfo.find(m_iMonsterInfoIndex);
						if( it != this->m_mapMonsterInfo.end() )
						{
							it->second.push_back(m_MonsterInfo);
						}
					
						LeaveCriticalSection(&this->m_critEventData);
					}
				}
				break;
			}
		}
	}

	fclose(SMDFile);

	LogAdd("%s file load!",lpszFileName);

	this->m_bHasData = TRUE;

	//DebugLog("%s END",__FUNCTION__);
	return TRUE;
}
Exemplo n.º 27
0
static BOOL PrepareToConfig()
{
    BOOL bMustExit = FALSE;

    // Use a local copy of the config info to decide what should be configured
    // or unconfigured.  We do this so that if the user cancels for some reason,
    // the real config state will still be what the user expects (what was
    // previously read from the system plus the user's changes).
    CONFIG_STATE configFS = g_CfgData.configFS;     // File server
    CONFIG_STATE configDB = g_CfgData.configDB;     // Database server
    CONFIG_STATE configBak = g_CfgData.configBak;   // Backup server
    CONFIG_STATE configSCS = g_CfgData.configSCS;   // System Control server
    CONFIG_STATE configSCC = g_CfgData.configSCC;   // System Control client

    BOOL bWorkToDo = FALSE;

    bWorkToDo |= PrepareToConfig(configFS, bFsRunning, bFsOn, IDC_FS_SERVICE);
    bWorkToDo |= PrepareToConfig(configDB, bDbRunning, bDbOn, IDC_DB_SERVICE);
    bWorkToDo |= PrepareToConfig(configBak, bBakRunning, bBakOn, IDC_BK_SERVICE);
    bWorkToDo |= PrepareToConfig(configSCS, bScsRunning, bScsOn, IDC_SCS);
    bWorkToDo |= PrepareToConfig(configSCC, bSccRunning, bSccOn, IDC_SCC);

    // If there is nothing to do, then just return TRUE.
    if (!bWorkToDo)
        return TRUE;

    // If we are unconfiguring the last DB server:
    //		1) Warn user and ask for confirmation
    //		2) Unconfigure all other servers that are running on this machine
    //		3) Tell them (after unconfiguring) that they must run the Wizard if they
    //		   wish to reconfigure the machine, then exit the program.
    if (configDB == CS_UNCONFIGURE) {
	if (g_CfgData.bLastDBServer) {
	    int nChoice = MsgBox(hDlg, IDS_LAST_DB_SERVER, GetAppTitleID(), MB_YESNO | MB_ICONEXCLAMATION);
	    if (nChoice == IDNO)
		return FALSE;

	    // Make sure these all get unconfigured as well.  If they are not configured, then
	    // nothing bad will happen because the config calls are idempotent.
	    configFS = CS_UNCONFIGURE;
	    configBak = CS_UNCONFIGURE;
	    configSCS = CS_UNCONFIGURE;
	    configSCC = CS_UNCONFIGURE;
	}
    }

    // Get additional needed information from the user
    GET_ADMIN_INFO_OPTIONS eOptions;
    BOOL bDB = (ShouldConfig(configDB) || ShouldUnconfig(configDB));

    // Use this as our default
    eOptions = GAIO_LOGIN_ONLY;

    // If we already have a sys control machine, then we don't need to ask for it
    if (ShouldConfig(configSCC)) {
	if (szScMachine[0] == 0) {
	    ShowWarning(hDlg, IDS_MUST_ENTER_SCS_NAME);
	    return FALSE;
	}
	lstrcpy(g_CfgData.szSysControlMachine, szScMachine);
    } else if (bDB && !g_CfgData.bLastDBServer) {
        // We need to know the name of the SCM machine.  Are we the SCM machine?
        if (bScsRunning)
            lstrcpy(g_CfgData.szSysControlMachine, g_CfgData.szHostname);
        else	
	    eOptions = GAIO_GET_SCS;
    }	

    // If doing a login only and the admin info is reusable
    if ((eOptions != GAIO_LOGIN_ONLY) || !g_CfgData.bReuseAdminInfo) {
    	if (!GetAdminInfo(hDlg, eOptions))
	    return FALSE;

        // Use the admin info to get new handles
        if (!GetHandles(hDlg))
            return FALSE;
    }	

    // Now that we are ready to configure, copy our local config info
    // into the structure that the config engine uses.
    g_CfgData.configFS = configFS;
    g_CfgData.configDB = configDB;
    g_CfgData.configBak = configBak;
    g_CfgData.configSCS = configSCS;
    g_CfgData.configSCC = configSCC;

    // Configure the server
    BOOL bConfigSucceeded = Configure(hDlg, bMustExit);
    if (bConfigSucceeded) {
        if (bMustExit) {
	    PostQuitMessage(0);
	    return TRUE;
	}
        g_CfgData.bReuseAdminInfo = TRUE;
    } else
        g_CfgData.szAdminPW[0] = 0;

    // Get current config status
    BOOL bCanceled = FALSE;
    DWORD dwStatus = GetCurrentConfig(hDlg, bCanceled);
    if (dwStatus || bCanceled) {
	if (!bCanceled)
	    ErrorDialog(dwStatus, IDS_CONFIG_CHECK_FAILED);
    }	

    // Show the initial services config
    ShowInitialConfig();
    ShowServiceStates();

    return TRUE;
}
Exemplo n.º 28
0
void CcdrawDoc::FancyEnforcePSLG(double tol)
{
	/*  
		need to enforce:
		1) no duplicate point;
		2) no intersections between line segments, lines and arcs, or arcs;
		3) no duplicate block labels;
		4) no overlapping lines or arcs.

		can do this by cleaning out the various lists, and rebuilding them
		using the ``add'' functions that ensure that things come out right.
	*/

	CArray< CNode, CNode&>             newnodelist;
	CArray< CSegment, CSegment&>       newlinelist;
	CArray< CArcSegment, CArcSegment&> newarclist;
	CArray< CBlockLabel, CBlockLabel&> newblocklist;
	int i,k;
	CComplex p0,p1;
	double d;

	bLinehook=ImportDXF;  // kludge to stop the program from giving a crash if
					// the user tries to exit during a dxf import.

	CcdrawView *pView;
	POSITION pos;
	pos=GetFirstViewPosition();
	pView=(CcdrawView *)GetNextView(pos);

	FirstDraw=TRUE;
//	pView->lua_zoomnatural();
	dxf_line_hook();
	pView->EditAction=4;

	newnodelist.RemoveAll();
	newlinelist.RemoveAll();
	newarclist.RemoveAll();
	newblocklist.RemoveAll();

	for(i=0;i<nodelist.GetSize();i++) newnodelist.Add(nodelist[i]);
	for(i=0;i<linelist.GetSize();i++) newlinelist.Add(linelist[i]);
	for(i=0;i<arclist.GetSize();i++) newarclist.Add(arclist[i]);
	for(i=0;i<blocklist.GetSize();i++) newblocklist.Add(blocklist[i]);

	nodelist.RemoveAll();
	linelist.RemoveAll();
	arclist.RemoveAll();
	blocklist.RemoveAll();
	
	pView->InvalidateRect(NULL);
	dxf_line_hook();

	// find out what tolerance is so that there are not nodes right on
	// top of each other;
	if(tol==0){
		if (newnodelist.GetSize()<2) d=1.e-08;
		else{
			p0=newnodelist[0].CC();
			p1=p0;
			for(i=1;i<newnodelist.GetSize();i++)
			{
				if(newnodelist[i].x<p0.re) p0.re=newnodelist[i].x;
				if(newnodelist[i].x>p1.re) p1.re=newnodelist[i].x;
				if(newnodelist[i].y<p0.im) p0.im=newnodelist[i].y;
				if(newnodelist[i].y>p1.im) p1.im=newnodelist[i].y;
			}
			d=abs(p1-p0)*CLOSE_ENOUGH;
		}
	}
	else d=tol;

	// put in all of the lines;
	for(i=0;i<newlinelist.GetSize();i++)
	{
		// Add in endpoints of the proposed line;
		AddNode(newnodelist[newlinelist[i].n0],d);
		AddNode(newnodelist[newlinelist[i].n1],d);

		// Add in the proposed line itself;
		p0=newnodelist[newlinelist[i].n0].CC();
		p1=newnodelist[newlinelist[i].n1].CC();
		if(AddSegment(p0,p1,newlinelist[i],d)==TRUE)
		{
			pView->DrawPSLG();	
			if(dxf_line_hook()){
				bLinehook=FALSE;
				return;
			}
		}
	}

	// put in all of the arcs;
	for(i=0;i<newarclist.GetSize();i++)
	{

		// Add in endpoints of the proposed line;
		AddNode(newnodelist[newarclist[i].n0],d);
		AddNode(newnodelist[newarclist[i].n1],d);

		// Add in the proposed arc inself;
		p0=newnodelist[newarclist[i].n0].CC();
		p1=newnodelist[newarclist[i].n1].CC();
		if(AddArcSegment(p0,p1,newarclist[i],d)==TRUE)
		{
			pView->DrawPSLG();	
			if(dxf_line_hook()){
				bLinehook=FALSE;
				return;
			}
		}
	}

	UnselectAll();

	// do one last check to eliminate shallow arcs that
	// link up the same two points as a line segment;
	for(i=0;i<arclist.GetSize();i++)
	{
		if (arclist[i].ArcLength<=22.5)
		{
			for(k=0;k<linelist.GetSize();k++)
			{
				if ((arclist[i].n0==linelist[k].n0) &&
					(arclist[i].n1==linelist[k].n1)) 
					arclist[i].IsSelected=TRUE;
				if ((arclist[i].n1==linelist[k].n0) &&
					(arclist[i].n0==linelist[k].n1)) 
					arclist[i].IsSelected=TRUE;
				if (arclist[i].IsSelected) k=(int) linelist.GetSize();
			}
		}
	}
	DeleteSelectedArcSegments();

	// put in all of the block labels;
	for(i=0;i<newblocklist.GetSize();i++) AddBlockLabel(newblocklist[i],d);
	
	if(SelectOrphans())
	{
		CString msg;
		msg ="There are lines or arcs with \"Orphaned\" end points.\n";
		msg+="The lines or arcs could be glitches in the DXF import\n";
		msg+="import, so they should be examined manually.\n";
		msg+="These points and lines will be shown as selected.\n";
		msg+="To redisplay the orphaned points and lines, select\n";
		msg+="View|Show Orphans off of the main menu.";
		MsgBox(msg);
	}

	bLinehook=FALSE;

	return;
}
Exemplo n.º 29
0
VOID EditItem_OnCommand( HWND hwnd,
                         INT  id,
                         HWND hwndCtrl,
                         UINT codeNotify )
{
  INT i;
  CHAR szBuf[128];
  LRESULT lResult;

  switch(id)
  {
    case IDC_EDIT_ITEM_ELEMENTS:

      if ( codeNotify == LBN_SELCHANGE )
      {
        EditItem_ElementChanged( hwnd );
      }
      break;

    case IDC_EDIT_ITEM_RESOURCES:

      if ( codeNotify == LBN_SELCHANGE )
      {
        lResult = ListBox_GetCurSel( hwndCtrl );

        i = (INT)lResult;

        lResult = ListBox_GetCurSel( GetDlgItem( hwnd, IDC_EDIT_ITEM_ELEMENTS ) );

        if ( lResult != LB_ERR )
        {
          nNewIndex[lResult] = i;
        }

        if ( nListContent == 0 && i >= 0 && i < po->nBitmaps )
        {
          PreviewBitmap( hwnd,
                         IDC_EDIT_ITEM_PREVIEW,
                         IDC_EDIT_ITEM_BITMAP_SIZE,
                         &po->pBitmapData[i],
                         po->pPalette );
        }
        else
        {
          PreviewBitmap( hwnd,
                         IDC_EDIT_ITEM_PREVIEW,
                         IDC_EDIT_ITEM_BITMAP_SIZE,
                         NULL,
                         NULL );
        }
      }
      break;

    case IDC_EDIT_ITEM_TYPE:

      if ( codeNotify == CBN_SELCHANGE )
      {
        lResult = ComboBox_GetCurSel( hwndCtrl );

        if ( lResult >= 0 && lResult < NUM_ITEM_TYPES )
        {
          nNewItemType = (INT)lResult;

          EditItem_TypeChanged( hwnd );
        }
      }
      break;

    case IDC_EDIT_ITEM_PIXEL_SIZE:

      if ( codeNotify == EN_CHANGE )
      {
        SendMessage( hwndCtrl,
                     WM_GETTEXT,
                     (WPARAM)sizeof(szBuf),
                     (LPARAM)((LPSTR)szBuf) );

        dNewPixelSize = atof( szBuf );
      }
      break;

    case IDC_EDIT_ITEM_NAME:

      if ( codeNotify == EN_CHANGE )
      {
        SendMessage( hwndCtrl,
                     WM_GETTEXT,
                     (WPARAM)sizeof(szNewItemName),
                     (LPARAM)((LPSTR)szNewItemName) );
      }
      break;
      
    case IDOK:

      if ( nNewItemType == -1 )
      {
        MsgBox( hwnd,
                MB_ICONEXCLAMATION,
                "The item must be assigned a type." );

        break;
      }

      if ( !szNewItemName[0] )
      {
        MsgBox( hwnd,
                MB_ICONEXCLAMATION,
                "The item must be given a name." );

        break;
      }

      EndDialog( hwnd, id );
      break;
      
    case IDCANCEL:

      EndDialog( hwnd, id );
      break;
  }
  
} // EditItem_OnCommand
Exemplo n.º 30
0
// IDYES    - Close All consoles
// IDNO     - Close active console only
// IDCANCEL - As is
int ConfirmCloseConsoles(const ConfirmCloseParam& Parm)
{
	DontEnable de;

	wchar_t szText[512], *pszText;
	int nBtn = IDCANCEL;

	static LONG lCounter = 0;
	LONG l = InterlockedIncrement(&lCounter);
	if (l > 1)
	{
		if (l == 2)
		{
			_ASSERTE(FALSE && "Confirm stack overflow!");
		}
		goto wrap;
	}

	if (Parm.rpLeaveConEmuOpened) *Parm.rpLeaveConEmuOpened = false;

	// Use TaskDialog?
	if (gOSVer.dwMajorVersion >= 6)
	{
		// must be already initialized: CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

		wchar_t szMessage[128];
		if (Parm.asSingleConsole)
			lstrcpyn(szMessage, Parm.asSingleConsole, countof(szMessage));
		else if (Parm.bForceKill)
			wcscpy_c(szMessage, L"Confirm killing?");
		else if (Parm.bGroup)
			wcscpy_c(szMessage, L"Confirm closing group?");
		else
			wcscpy_c(szMessage, L"Confirm closing?");

		wchar_t szWWW[MAX_PATH]; _wsprintf(szWWW, SKIPLEN(countof(szWWW)) L"<a href=\"%s\">%s</a>", gsHomePage, gsHomePage);

		wchar_t szCloseAll[MAX_PATH*2]; wchar_t *pszText;
		if (Parm.asSingleConsole)
		{
			wcscpy_c(szCloseAll, L"Yes\n");
			pszText = szCloseAll + _tcslen(szCloseAll);
			lstrcpyn(pszText, Parm.asSingleTitle, min(MAX_PATH,(countof(szCloseAll)-(pszText-szCloseAll))));
			pszText += _tcslen(pszText);
		}
		else
		{
			_wsprintf(szCloseAll, SKIPLEN(countof(szCloseAll))
				(Parm.bGroup && (Parm.nConsoles>1))
					? ((Parm.bGroup == ConfirmCloseParam::eGroup)
						? L"Close group (%u consoles)"
						: L"Close (%u consoles)")
					: (Parm.nConsoles>1)
						? L"Close all %u consoles."
						: L"Close %u console.",
				Parm.nConsoles);
			pszText = szCloseAll + _tcslen(szCloseAll);
		}
		if ((Parm.asSingleConsole == NULL) || (Parm.nOperations || Parm.nUnsavedEditors))
		{
			//if (nOperations)
			{
				_wsprintf(pszText, SKIPLEN(countof(szCloseAll)-(pszText-szCloseAll)) L"\nIncomplete operations: %i", Parm.nOperations);
				pszText += _tcslen(pszText);
			}
			//if (nUnsavedEditors)
			{
				_wsprintf(pszText, SKIPLEN(countof(szCloseAll)-(pszText-szCloseAll)) L"\nUnsaved editor windows: %i", Parm.nUnsavedEditors);
				pszText += _tcslen(pszText);
			}
		}

		wchar_t szCloseOne[MAX_PATH];
		wcscpy_c(szCloseOne, L"Close active console only");
		if (Parm.nConsoles > 1)
		{
			CVConGuard VCon;
			int iCon = gpConEmu->GetActiveVCon(&VCon);
			if (iCon >= 0)
			{
				pszText = szCloseOne + _tcslen(szCloseOne);
				_wsprintf(pszText, SKIPLEN(countof(szCloseOne)-(pszText-szCloseOne)) L"\n#%u: ", (iCon+1));
				pszText += _tcslen(pszText);
				lstrcpyn(pszText, VCon->RCon()->GetTitle(true), countof(szCloseOne)-(pszText-szCloseOne));
			}
		}

		const wchar_t* szCancel = L"Cancel\nDon't close anything";


		int nButtonPressed                  = 0;
		TASKDIALOGCONFIG config             = {sizeof(config)};
		TASKDIALOG_BUTTON buttons[]   = {
			{ IDYES,    szCloseAll },
			{ IDNO,     szCloseOne },
			{ IDCANCEL, szCancel },
		};
		config.cButtons                     = countof(buttons);
		if (Parm.nConsoles <= 1)
		{
			buttons[1] = buttons[2];
			config.cButtons--;
		}

		config.hwndParent                   = ghWnd;
		config.hInstance                    = NULL /*g_hInstance*/;
		config.dwFlags                      = TDF_USE_HICON_MAIN|TDF_USE_COMMAND_LINKS|TDF_ALLOW_DIALOG_CANCELLATION
		                                      |TDF_ENABLE_HYPERLINKS; //|TDIF_SIZE_TO_CONTENT|TDF_CAN_BE_MINIMIZED;
		//config.pszMainIcon                  = MAKEINTRESOURCE(IDI_ICON1);
		config.hMainIcon                    = hClassIcon;
		config.pszWindowTitle               = gpConEmu->GetDefaultTitle();
		config.pszMainInstruction           = szMessage;
		//config.pszContent                 = L"...";
		config.pButtons                     = buttons;
		config.nDefaultButton               = IDYES;
		config.pszFooter                    = szWWW;

		//{
		//	config.dwFlags |= TDF_VERIFICATION_FLAG_CHECKED;
		//	config.pszVerificationText = L"Text on checkbox";
		//}

		HRESULT hr = TaskDialog(&config, &nButtonPressed, NULL, NULL);

		if (hr == S_OK)
		{
			switch (nButtonPressed)
			{
			case IDCANCEL: // user cancelled the dialog
			case IDYES:
			case IDNO:
				nBtn = nButtonPressed;
				goto wrap;

			default:
				_ASSERTE(nButtonPressed==IDCANCEL||nButtonPressed==IDYES||nButtonPressed==IDNO);
				break; // should never happen
			}
		}
	}

	// Иначе - через стандартный MessageBox

	if (Parm.asSingleConsole)
	{
		lstrcpyn(szText,
			Parm.asSingleConsole ? Parm.asSingleConsole : Parm.bForceKill ? L"Confirm killing?" : L"Confirm closing?",
			min(128,countof(szText)));
		wcscat_c(szText, L"\r\n\r\n");
		int nLen = lstrlen(szText);
		lstrcpyn(szText+nLen, Parm.asSingleTitle, countof(szText)-nLen);
	}
	else
	{
		_wsprintf(szText, SKIPLEN(countof(szText)) L"About to close %u console%s.\r\n", Parm.nConsoles, (Parm.nConsoles>1)?L"s":L"");
	}
	pszText = szText+_tcslen(szText);

	if (Parm.nOperations || Parm.nUnsavedEditors)
	{
		*(pszText++) = L'\r'; *(pszText++) = L'\n'; *(pszText) = 0;

		if (Parm.nOperations)
		{
			_wsprintf(pszText, SKIPLEN(countof(szText)-(pszText-szText)) L"Incomplete operations: %i\r\n", Parm.nOperations);
			pszText += _tcslen(pszText);
		}
		if (Parm.nUnsavedEditors)
		{
			_wsprintf(pszText, SKIPLEN(countof(szText)-(pszText-szText)) L"Unsaved editor windows: %i\r\n", Parm.nUnsavedEditors);
			pszText += _tcslen(pszText);
		}
	}

	if (Parm.nConsoles > 1)
	{
		wcscat_c(szText,
			L"\r\nPress button <No> to close active console only\r\n"
			L"\r\nProceed with close ConEmu?");
	}

	nBtn = MsgBox(szText, (/*rpPanes ? MB_OKCANCEL :*/ (Parm.nConsoles>1) ? MB_YESNOCANCEL : MB_OKCANCEL)|MB_ICONEXCLAMATION,
		gpConEmu->GetDefaultTitle(), ghWnd);

	if (nBtn == IDOK)
	{
		nBtn = IDYES; // для однозначности
	}

wrap:
	InterlockedDecrement(&lCounter);
	return nBtn;
}