C# Programming

Image�ȒP�ȃ��o�C���A�v���P�[�V�����J��1 �`�@WZero3StatusMeter

�J���‹��F Visual Studio 2005�@

�P�D�ڎ�

�P�D�ڎ�
�Q�D�ړI
�R�D�Q�l��
�S�D����
�T�D�_�E�����[�h
�U�D�\�[�X�R�[�h
�V�D��������

�Q�D�ړI

W-Zero3�p��Windows Mobile �̊ȒP�ȃA�v���P�[�V�����Ƃ��āA�悭����@�\��CPU �̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂ��O���t�B�J���ɕ\������悤�ɂ��܂��B

Image

�����ł͒P�@�\�̂��̂���钆�� �AWindows Mobile�ł̊J���Œ��ӂ��ׂ����ƂȂǂ�����������Ǝv���܂��B

�R�D�Q�l��

  1. C#������.Live Space / W-ZERO3
  2. MSDN .NET Compact Framework �����̕\�������؂�ւ��Ή�����э�dpi�Ή��A�v���P�[�V�����̊J��

�S�D����

�S�D�P�@��{�I�ȃf�U�C���⓮������߂�

�P��CPU�̏�Ԃ�\������Ƃ����Ă��A�\�����@�Ƃ��ẮATask Manager�݂����Ɏ��Ԏ��ŕ\�����Ă������@��A�^�R���[�^�݂������A���^�C���ɕ\��������@������܂��B�܂��A�\�����@���A�_�O���t�ɂ���̂��A�܂���O���t�ɂ���̂��A���[�^�[�\���ɂ���̂�LED�\���ɂ���̂��A���낢��ȕ\�����@������܂��B

���ꂩ���낤�Ƃ���A�v���P�[�V�����̊�{�I�ȃf�U�C���⓮��Ȃǂ̊�{�݌v���ӂ�ӂ炵�Ă���ƁA���Ƃ���̏C�������ɑ�ςɂȂ�A�ꍇ�ɂ���Ă͍�蒼���Ƃ������ƂɂȂ�܂��B�܂��́A�ǂ̂悤�ȃf�U�C���⓮��ɂ���̂��������茈�߂܂��B

�����ł́A�_�O���t��CPU �̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂ�\�����邱�Ƃɂ��܂��B

�S�D�Q�@���i�̓���m�F

CPU �̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂ��擾�ł��邱�Ƃ��K�{�ł��B�����ŁA���̂��߂̃N���X�̎����ƁA�e�X�g�� ��s���čs���܂��B���̃N���X�P�̂Ő��������삷�邱�Ƃ��m�F�ł��Ȃ��ƁA���Ƃ�UI���̖��Ȃ̂��؂蕪�����ʓ|�ɂȂ�܂��̂ŁA�P�̃e�X�g�����{���A�m���ɓ��삷��悤�ɂ��܂��B

�Ȃ��A�����CPU �̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂ��擾���邽�߂̃N���X�́A�U�D�P�͂Ƀ\�[�X�R�[�h���L�ڂ��Ă��܂��BInterOp���Ă���ȒP�ȃ��b�p�[�N���X�Ȃ̂ŁA���ɐ����͕K�v�͂Ȃ��Ǝv���܂��B

�S�D�R�@�摜�p�[�c�̍쐬

��{�I�ȃf�U�C���ɏ]���āA��ʃp�[�c���쐬���܂��B���̏ꍇ�A�����ȃf�U�C���c�[���Ȃǎ����Ă��Ȃ��̂ŁAPowerPoint�ő�p���܂����B����y�ɍ�镪�ɂ͂���Ȃ�Ɏg���܂��B���̂悤�ɁA�P���ڂ����C���y�[�W�̃f�U�C���A�Q���ڂ��O���t���ǂ̂悤�ɕ\�����邩�̃f�U�C���A�R���ڂ�About��ʂ̃f�U�C���ł��B

Image

���̂悤��UI�̃A�v���P�[�V���������ۂɋC���‚��Ȃ���΂����Ȃ��̂��AUI�̃f�U�C���ɈӊO�Ǝ��Ԃ�������Ƃ������Ƃł��B�ςȂƂ���ɋÂ�����A�F���C�ɓ���Ȃ�������A�T�C�Y������Ȃ�������A�R���g���[����t�H���g�̃T�C�Y�̔��������K�v�������肵�āA���Ɏ��Ԃ�������܂��B

����g�p����摜�̃p�[�c�͎��̂悤�ȁA�w�i�摜�ALED�̐ԁALED�̐AAbout��ʂ̂S�‚����ł��B \

Image

����̒��x�̃A�v���P�[�V�����ł���΁AVisual Studio��C#�̎����Ɋ��ꂽ���Ȃ�A�Q�|�R���Ԃ� �����ł���ł��傤�B�������A���̂������S�‚̉摜�̃f�U�C����R���g���[���Ƃ̈ʒu���킹�̂ق������Ԃ��������Ă��܂��B

��l�ō���Ă��Ă����̎n���ł�����A�����̐l�ō��ꍇ��A�ʂ̐l�ɒ񋟂���ꍇ�ɂ́A���Ƃ���u��������Ȃ��v�A�u��������Ȃ��v�Ȃǂƌ����Ă��܂��̂Œ��ӂ��K�v�ł��B

�摜�̃p�[�c�̃T�C�Y���厖�ł��B�傫������ƁA�A�v���P�[�V�����̃T�C�Y���傫���Ȃ�܂��B����������ƁA�����������Ă��܂��܂��B�܂��A�ꍇ�ɂ���Ă͉𑜓x�̈Ⴂ�ɂ�胂�A�����������Ă��܂��ꍇ������ł��傤�B�ł���΁A�\���T�C�Y�Ǝ��ۂ̃f�U�C���̃T�C�Y����v���Ă���̂��]�܂����ł��B

�S�D�S�@�v���W�F�N�g�̍쐬

  1. �v���W�F�N�g�̐V�K�쐬
    Visual Studio�̃��j���[����v���W�F�N�g�̐V�K�쐬�ŁA�v���W�F�N�g�̎�ނ� [�X�}�[�g�f�o�C�X] �� [�f�o�C�X�A�v���P�[�V����] ��I�����܂��B
    �@
  2. �^�[�Q�b�g�f�o�C�X�̐ݒ�
    �G�~�����[�^�ł��”\�ł����A�G�~�����[�^�ł̓��X�|���X�������A�������邢�ł��B�����ŁAWindows Mobile 5.0 Pocket PC Device���w�肵�āA���@��ŊJ�����܂��B
    �@
  3. Form�� [FormFactor]�v���p�e�B
    [Windows Mobile 5.0 Pocket PC VGA] ���w�肵�܂��B
    �@

�S�D�T�@����

CPU�̎g�p���̎������ɂƂ�������s���܂��B�������g�p�ʁA�f�B�X�N�g�p�ʂ̎����́A�قړ����ł��B

  1. PictureBox�̓\��t��
    �w�i�摜�𒣂�t���邽�߂ɁAPicture ��Form�ɓ\��t���܂��BDock�v���p�e�B�� Top �Ƃ��܂��B����ɂ��A�c�^�A���^�ł̃f�U�C�����y�ɂȂ�܂��B
    �@
  2. �w�i�摜�̓\��t��
    �P�Œ���t���� PictureBox�� Image �v���p�e�B�ɁA�S�D�R�͂ō쐬�����摜��\��t���܂��B�����܂łŁA�‚��̂悤�ɂȂ�܂��B

    Image
    �@
  3. CPU�̎g�p���N���X�̒lj�
    CPU�̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂł����A.NET Framework ���璼�ڎ擾�ł��܂���B�����ŁAInterOp�Ŏ擾����K�v������܂��B�����ŁA���ꂼ��̃��b�p�[�N���X���쐬���邱�Ƃɂ��܂��B�\�����[�V�����G�N�X�v���[���[�ŁACPUStatus.cs�ADiskStatus.cs�AMemoryStatus.cs �̂R�‚�C# �N���X��lj����܂��B�N���X�̎����ɂ‚��ẮA�U�D�P�͂ɋL�ڂ��܂��B
    �@
  4. �^�C�}�[�̒lj�
    �����莞�Ԃ��ƂɁACPU�̎g�p�����X�V���邽�߂ɁA�^�C�}�[��lj����܂��B�^�C�}�[�� Interval �v���p�e�B�� 1000�i�P�b�j�Ƃ��܂��B
    �@
  5. �^�C�}�[�̃C�x���g�n���h����lj�
    �^�C�}�[�ɃC�x���g�n���h���lj����܂��BCPU�̖_�O���t�́APictureBox�ɕ`�悷�邱�Ƃɂ��܂��B�����ŁApictureBoxCPU��lj����܂��B�^�C�}�[�̏����ł́ApictureBoxCPU��CPU�̖_�O���t��`�悵�A�����Refresh()�ōĕ`��w�������܂��B private void timer1_Tick(object sender, EventArgs e)
    {
    �@�@�@�@RedrawCPU();
    �@�@�@�@pictureBoxCPU.Refresh();
    }
    �@
  6. CPU�_�O���t�̂��߂�PictureBox��\��t����
    CPU�_�O���t��\�����邽�߂ɁApictureBoxCPU�����̂悤�ɓ\��t���܂��B���� pictureBoxCPU �ɐԂ�LED��CPU�̎g�p���̕������`�悵�A�c��͔�_���̐‚�LED��`�� ����悤�ɂ��܂��B�w�i�F�́A���ɂ��܂��B
    Image

    �@
  7. CPU�_�O���t�̎���
    pictureBoxCPU�ɐԂ�LED��CPU�̎g�p�������`�悵�A�c��͔�_���̐‚�LED��`�悵�܂��B���W�b�N�͊ȒP�Ŏ��̒ʂ�ł��B�����ł́A�����I�Ȋg���i����̂��H�j���l���āAImageList�ŁA�Ԃ�LED�Ɛ‚�LED��lj����Ă��܂����A����Bitmap���g�p���Ă���肠��܂���B

    private
    CPUStatus cpuStat = new CPUStatus();

    private void RedrawCPU()
    {
     
    using (Graphics gimg = Graphics.FromImage(pictureBoxCPU.Image))
      {
       
    CPUStatus cpuStat = new CPUStatus();

       
    uint val = cpuStat.GetCPU();
       
    for (int i = 0; i < pictureBoxCPU.Image.Width; i += 20)
        {
         
    if (val > 100 * i / pictureBoxCPU.Image.Width)
            gimg.DrawImage(imageList1.Images[0], i, 0);
         
    else
           
    gimg.DrawImage(imageList1.Images[1], i, 0);
        }
      }
    }

    �@
  8. ����̊m�F
    �����܂łŁA���s���Ă݂Ă��������BCPU�_�O���t���\��������OK�ł��B
    �@
  9. �������g�p�ʁA�f�B�X�N�g�p�ʂ̖_�O���t�̎���
    ���Ƃ͓��l�ɁA�������g�p�ʁA�f�B�X�N�g�p�ʂ̖_�O���t���������܂��B�����ACPU�Ɠ��l�ɂP�b���Ƃɖ_�O���t��`�悷��悤�ɂ��ƁA���Ȃ�CPU��H���Ă��܂��܂��B�������g�p�ʁA�f�B�X�N�g�p�ʂ́A�P�b���ƂɍX�V����K�v�͂Ȃ��ł���ˁH�����ŁA�����P�ƒ^�C�}�[��lj����āA�P�O�b���ƂɍX�V����悤�ɂ��āA���ׂ������Ă����܂� �B

�S�D�U�@�c�^�A���^���C�A�E�g�̒���

Windows Mobile �f�o�C�X�̏ꍇ�A�c�^�A���^�̃��C�A�E�g���”\�Ȃ̂ŁA��ʂ̃��C�A�E�g���ς��ƁA�R���g���[���̔z�u���ς���K�v������܂��B ���̂��߁A�c�^�A���^�̂ǂ���ł����������C�A�E�g�ł���悤�ɁA�Ȃ�ׂ������i�K�ŁA��ʂ̐݌v���ł߂Ă������Ƃ��ƂĂ��d�v�ł��B �c�^�A���^�̃��C�A�E�g�́A���̃{�^���ŕύX���”\�ł��B�ǂ���̏ꍇ�ł��������\���ł���悤�ɒ������܂��傤�B

Image

�܂��A�v���p�e�B�����ŏc�^�A���^�̃��C�A�E�g�̒������ł��Ȃ��ꍇ�́A�����őΉ�����K�v������܂��B���̕��@�͎Q�l�����i�Q�j���Q�Ƃ��Ă��������B

�S�D�V�@���C�����j���[�̒lj�

  1. ���C�����j���[�F�@���{�^��
    ���{�^�����������Ƃ��̃C�x���g�n���h��ŁAApplication.Exit()�����s����悤�ɂ��܂��B

    private void menuItemTerminate_Click(object sender, EventArgs e)
    {
       
    Application.Exit();
    }
    �@
  2. ���C�����j���[�F�@�E�{�^��
    About �{�^�� ����������AAbout��ʂ�\������悤�ɂ��܂��B�v���W�F�N�g�ɁAFormAbout�t�H�[����lj����܂��B���̃t�H�[���ɁAPictureBox��DOCK�v���p�e�B��FILL�œ\��t���܂��BPictureBox��Image�v���p�e�B�ɂ́A��ɍ����About�̉摜��\��t���܂��B
    ���C�����j���[�E�{�^���̃C�x���g�n���h����lj����AFormAbout�� ShowDialog() ���Ăяo���܂��B

    private void menuItemAbout_Click(object sender, EventArgs e)
    {
       
    FormAbout formAbout = new FormAbout();
        formAbout.ShowDialog();
    }

    ����ŁA���̂悤�� About��ʂ�lj����܂��BAbout��ʂ́A�摜�ł���K�v�͑S������܂���B�����A�J�b�R�ǂ���낤�Ǝv���ƁA�摜�𒣂�t�����ق����ȒP�ł��B


    Image

�S�D�W�@�A�C�R���̒lj�

�V�������ڂ̒lj��ŁA�A�C�R����lj����܂��B

Image

�A�C�R���̃T�C�Y�́A16x16��32x32��p�ӂ��A�r���h�A�N�V������"���ߍ��܂ꂽ���\�[�X"�ɂ��܂��B

Image

�S�D�X�@�o�[�W�������̕\��

  1. �o�[�W�������̕\��
    �A�v���P�[�V�����̃o�[�W������\�����܂��B���x��(labelVersion)��\��t���A���̂悤�Ƀo�[�W��������\������悤�ɂ��܂��B

    Assembly
    assembly = Assembly.GetExecutingAssembly();
    labelVersion.Text =
    "V." + assembly.GetName().Version.ToString();
    �@
  2. ���̂��߂ɂ́A�A�Z���u�����ŃA�Z���u���o�[�W�����𐳂������͂��Ă����K�v������܂��B
    �A�Z���u�����́A[�v���W�F�N�g]��[�v���p�e�B]��[�A�v���P�[�V����]��\�����܂��B
    Image
    �@
  3. [�A�Z���u�����]�{�^���������A�_�C�A���O����ݒ�ł��܂��B

    Image

�S�D�P�P�@�C���X�g�[���̒lj�

�V�����v���W�F�N�g�� [���̑��̃v���W�F�N�g�̎��]��[�Z�b�g�A�b�v�E�B�U�[�h]��I������B���̂Ƃ��̃v���W�F�N�g���� "WZero3StatusMeterCab" �Ƃ������O��t����B���̏ꍇ�A"WZero3StatusMeterCab.cab"�Ƃ����t�@�C��������邱�ƂɂȂ�B

Image

"WZero3StatusMeterCab"�v���W�F�N�g��I�����A���C�����j���[��[�\��]��[�v���p�e�B�E�B���h�E]�Ńv���p�e�B�E�B���h�E���J���܂��B�����ŁAManufacturer�AProductName���C�����܂��B���� ProductName �ɏ]���āA"Program Files\ProductName"�t�H���_������܂��̂Œ��ӂ��Ă��������B

Image

���l�ɁA�\�����[�V�����G�N�X�v���[������@"WZero3StatusMeterCab"�v���W�F�N�g��I�����A�E�N���b�N�������A�v���p�e�B��I�����܂��B����Ǝ��̂悤�ȁA�v���p�e�B�y�[�W���J���܂��B�����ŁA�o�̓t�@�C�������A"WZero3StatusMeterCab.cab"�Ƃ����Ԕ����ȃt�@�C�����ɂȂ��Ă���̂ŁA�K�؂ɏC�����܂��B

Image

�A�v���P�[�V�����t�H���_�ɁA"�v���C�}���o��"��lj����܂��B

Image

�T�D�@�_�E�����[�h

Version 1.0.0.1  2007/3/27 WZero3StatusMeter.cab

�U�D�@�\�[�X�R�[�h

��ȃ\�[�X�R�[�h�ł��B

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;

namespace Uchukamen.WZero3
{
    public partial class FormWZero3Meter : Form
    {
        public FormWZero3Meter()
        {
            InitializeComponent();

            CreateImages();

            Assembly assembly = Assembly.GetExecutingAssembly();
            labelVersion.Text = "V." + assembly.GetName().Version.ToString();
        }

        private void CreateImages()
        {
            if (pictureBoxCPU.Image == null)
                pictureBoxCPU.Image = new Bitmap(640, 64);

            if (pictureBoxMem.Image == null)
                pictureBoxMem.Image = new Bitmap(640, 64);

            if (pictureBoxDisk.Image == null)
                pictureBoxDisk.Image = new Bitmap(640, 64);
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            RedrawCPU();
            pictureBoxCPU.Refresh();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            RedrawMem();
            pictureBoxMem.Refresh();
            RedrawDisk();
            pictureBoxDisk.Refresh();
            System.GC.Collect();
        }

        private CPUStatus cpuStat = new CPUStatus();

        private void RedrawCPU()
        {
            using (Graphics gimg = Graphics.FromImage(pictureBoxCPU.Image))
            {
                uint val = cpuStat.GetCPU();
                labelCPU.Text = val.ToString();

                for (int i = 0; i < pictureBoxCPU.Image.Width; i += 20)
                {
                    if (val > 100 * i / pictureBoxCPU.Image.Width)
                        gimg.DrawImage(imageList1.Images[0], i, 0);
                    else
                        gimg.DrawImage(imageList1.Images[1], i, 0);
                }
            }
        }

        private MemoryStatus mstat = new MemoryStatus();

        private void RedrawMem()
        {
            using (Graphics gimg = Graphics.FromImage(pictureBoxMem.Image))
            {
                mstat.Get();
                uint val = 100 - (uint)(100 * mstat.AvailPhysicalMB / mstat.TotalPhysicalMB);
                labelMem.Text = mstat.AvailPhysicalMB.ToString("n2") + " MB / " +
                    mstat.TotalPhysicalMB.ToString("n2") + " MB";

                for (int i = 0; i < pictureBoxMem.Image.Width; i += 20)
                {
                    if (val > 100 * i / pictureBoxMem.Image.Width)
                        gimg.DrawImage(imageList1.Images[0], i, 0);
                    else
                        gimg.DrawImage(imageList1.Images[1], i, 0);

                }
            }
        }

        private DiskStatus dstat = new DiskStatus();

        private void RedrawDisk()
        {
            using (Graphics gimg = Graphics.FromImage(pictureBoxDisk.Image))
            {
                dstat.Get("\\");
                uint val = 100 - (uint)(100 * dstat.FreeMB / dstat.TotalMB);
                labelDisk.Text = dstat.FreeMB.ToString("n2") + " MB / "
                    + dstat.TotalMB.ToString("n2") + " MB";

                for (int i = 0; i < pictureBoxDisk.Image.Width; i += 20)
                {
                    if (val > 100 * i / pictureBoxDisk.Image.Width)
                        gimg.DrawImage(imageList1.Images[0], i, 0);
                    else
                        gimg.DrawImage(imageList1.Images[1], i, 0);

                }
            }
        }

        private void menuItemTerminate_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void menuItemAbout_Click(object sender, EventArgs e)
        {
            FormAbout formAbout = new FormAbout();
            formAbout.ShowDialog();
        }

        private void FormWZero3Meter_Activated(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer2.Enabled = true;
        }

        private void FormWZero3Meter_Deactivate(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer2.Enabled = false;
        }

        private void FormWZero3Meter_Load(object sender, EventArgs e)
        {
            RedrawCPU();
            RedrawDisk();
            RedrawMem();
        }
    }
}

�U�D�P�@CPU �̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂ̎擾�N���X

���āACPU�̎g�p���A�������g�p�ʁA�f�B�X�N�g�p�ʂł����A.NET Framework ����擾�ł��܂���B�����ŁAInterOp�Ŏ擾����K�v������܂��B�����ŁA���ꂼ��̃��b�p�[�N���X���쐬���邱�Ƃɂ��܂��B

�\�����[�V�����G�N�X�v���[���[�ŁA���̂R�‚�C# �N���X��lj����܂��B

CPU�̎g�p���擾�N���X

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Uchukamen.WZero3
{
    class CPUStatus
    {
        [DllImport("COREDLL.DLL")]
        private extern static uint GetTickCount();

        [DllImport("COREDLL.DLL")]
        private extern static uint GetIdleTime();

        private static uint dwStartTick = 0;
        private static uint dwIdleSt = 0;

        /// 
        /// CPU�g�p��
        /// 
        /// uint 0:�ŏ�-100:�ő�
        public uint GetCPU()
        {
            uint dwStopTick = GetTickCount();
            uint dwIdleEd = GetIdleTime();
            uint idle = ((100 * (dwIdleEd - dwIdleSt)) / (dwStopTick - dwStartTick));

            dwStartTick = dwStopTick;
            dwIdleSt = dwIdleEd;
            uint cpu = 100 - idle;
            Debug.WriteLine(cpu.ToString());
            return cpu;
        }
    }
}

�������̎g�p�ʎ擾�N���X

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Uchukamen.WZero3
{
    public class MemoryStatus
    {
        private class MEMORYSTATUS
        {
            public uint dwLength = 0;
            public uint dwMemoryLoad = 0;
            public uint dwTotalPhys = 0;
            public uint dwAvailPhys = 0;
            public uint dwTotalPageFile = 0;
            public uint dwAvailPageFile = 0;
            public uint dwTotalVirtual = 0;
            public uint dwAvailVirtual = 0;
        }

        [DllImport("CoreDll.dll")]
        private static extern void GlobalMemoryStatus
        (
        MEMORYSTATUS lpBuffer
        );

        [DllImport("CoreDll.dll")]
        public static extern int GetSystemMemoryDivision
        (
        ref uint lpdwStorePages,
        ref uint lpdwRamPages,
        ref uint lpdwPageSize
        );

        private float totalPhys = 0;
        public float TotalPhysicalMB
        {
            get { return totalPhys; }
        }

        private float availPhys = 0;
        public float AvailPhysicalMB
        {
            get { return availPhys; }
        }

        private float totalVirtual = 0;
        public float TotalVirtualMB
        {
            get { return totalVirtual; }
        }

        private float availVirtual = 0;
        public float AvailVirtualMB
        {
            get { return availVirtual; }
        }

        public void Get()
        {
            uint storePages = 0;
            uint ramPages = 0;
            uint pageSize = 0;
            int res = GetSystemMemoryDivision(ref storePages, ref ramPages, ref pageSize);

            MEMORYSTATUS memStatus = new MEMORYSTATUS();
            GlobalMemoryStatus(memStatus);

            totalPhys = memStatus.dwTotalPhys / 1024F / 1024F;
            availPhys = memStatus.dwAvailPhys / 1024F / 1024F;
            totalVirtual = memStatus.dwTotalVirtual / 1024F / 1024F;
            availVirtual = memStatus.dwAvailVirtual / 1024F / 1024F;
        }
    }
}

�f�B�X�N�̎g�p�ʎ擾�N���X

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Uchukamen.WZero3
{
    public class DiskStatus
    {
        [DllImport("coredll.dll")]
        public static extern bool GetDiskFreeSpaceEx
           (
           string directory,
           ref UInt64 lpFreeBytesAvailableToCaller,
           ref UInt64 lpTotalNumberOfBytes,
           ref UInt64 lpTotalNumberOfFreeBytes
           );

        #region �v���p�e�B
        /// 
        /// The total number of free bytes on the disk
        /// that are available to the user associated with the calling thread. 
        /// 
        private UInt64 freeBytesAvailableToCaller = 0;
        public UInt64 FreeBytesAvailableToCaller
        {
            get { return freeBytesAvailableToCaller; }
        }

        public float FreeMB
        {
            get { return (float)freeBytesAvailableToCaller / 1024F / 1024F; }
        }

        /// 
        /// The total number of bytes on the disk
        /// that are available to the user associated with the calling thread. 
        /// 
        private UInt64 totalNumberOfBytes = 0;
        public UInt64 TotalNumberOfBytes
        {
            get { return totalNumberOfBytes; }
        }

        public float TotalMB
        {
            get { return (float)totalNumberOfBytes / 1024F / 1024F; }
        }


        /// 
        /// The total number of free bytes on the disk. 
        /// 
        private UInt64 totalNumberOfFreeBytes = 0;
        public UInt64 TotalNumberOfFreeBytes
        {
            get { return totalNumberOfFreeBytes; }
        }
        #endregion

        /// 
        /// �f�B�X�N�e�ʂ��擾����B
        /// 
        /// �f�B�X�N�̃p�X
        public void Get(string path)
        {
            bool res = GetDiskFreeSpaceEx(
                path,
                ref freeBytesAvailableToCaller,
                ref totalNumberOfBytes,
                ref totalNumberOfFreeBytes);
        }
    }
}

�V�D�@��������

�������������΁ATaskManager�̂悤�ȕ\�����ȒP�ɂł��܂��B

Image

�������ACPU�⃁�����̐��񂪋����A���܂�Â������Ƃ�����ƁA��������CPU��H���‚Ԃ��Ă��܂��܂��̂ŁA�����ڂƋ@�\�̃o�����X��A���\���l�����݌v���K�v�ɂȂ�܂��B

C# Programming       Privacy Policy