elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Consulta J#
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Consulta J#  (Leído 1,944 veces)
Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
Consulta J#
« en: 5 Junio 2010, 01:14 am »

Hola, queria saber si es posible controlar el volumen de windows con J#.net


En línea

[D4N93R]
Wiki

Desconectado Desconectado

Mensajes: 1.646


My software never has bugs. Its just features!


Ver Perfil WWW
Re: Consulta J#
« Respuesta #1 en: 5 Junio 2010, 02:10 am »

Ven por eso decía que hay que tener el subforo de .Net, para poner todas estas cosas, porque J# es parte de .Net igual que vb.Net C# IronPython etc..

Con respecto al post: Una forma que se me ocurre es enviando el Key del volumen del teclado, lo puedes hacer haciendo referencia a keybd_event que esta en user32.

Info de la funcion: http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx

Entonces le pasas System.Windows.Forms.Keys.VolumeDown o VolumeUp.

Te pongo el código que hice en C#
Código
  1. [DllImport("user32")]
  2. public static extern void keybd_event(byte bvk, byte bScan, int dwFlags, int dwExtraInfo);
  3.  
  4. void VolumeDown()
  5. {
  6.    keybd_event((byte)System.Windows.Forms.Keys.VolumeDown, 0, 0, 0);
  7. }
  8.  

Otra cosa, te recomiendo que no uses F# para estas cosas, para eso usas C# y trabajas usando los dos lenguajes. Como sabes es para programción funcional y se hace un poco complicado codear cosas rutinarias, por lo que puedes mezclar sin problemas una solución con proyectos en dos lenguajes.

EDIT: No leas el párrafo anterior, leí F# en vez de J#, LOL

Un saludo!


« Última modificación: 5 Junio 2010, 05:53 am por D4N93R » En línea

43H4FH44H45H4CH49H56H45H
Wiki

Desconectado Desconectado

Mensajes: 502



Ver Perfil
Re: Consulta J#
« Respuesta #2 en: 5 Junio 2010, 05:46 am »

Hola, queria saber si es posible controlar el volumen de windows con J#.net

Si se puede, este ejemplo en c#.net disminuye el volumen general de windows puedes pasarlo a J#.NET y modificarlo a tu gusto, hay muchos mas en la red.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Media;
  10. using System.Runtime.InteropServices;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.    public partial class Form1 : Form
  15.    {
  16.        public const int MMSYSERR_NOERROR = 0;
  17.        public const int MAXPNAMELEN = 32;
  18.        public const int MIXER_LONG_NAME_CHARS = 64;
  19.        public const int MIXER_SHORT_NAME_CHARS = 16;
  20.        public const int MIXER_GETLINEINFOF_COMPONENTTYPE = 0x3;
  21.        public const int MIXER_GETCONTROLDETAILSF_VALUE = 0x0;
  22.        public const int MIXER_GETLINECONTROLSF_ONEBYTYPE = 0x2;
  23.        public const int MIXER_SETCONTROLDETAILSF_VALUE = 0x0;
  24.        public const int MIXERLINE_COMPONENTTYPE_DST_FIRST = 0x0;
  25.        public const int MIXERLINE_COMPONENTTYPE_SRC_FIRST = 0x1000;
  26.        public const int MIXERLINE_COMPONENTTYPE_DST_SPEAKERS =
  27.        (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4);
  28.        public const int MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE =
  29.        (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3);
  30.        public const int MIXERLINE_COMPONENTTYPE_SRC_LINE =
  31.        (MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2);
  32.        public const int MIXERCONTROL_CT_CLASS_FADER = 0x50000000;
  33.        public const int MIXERCONTROL_CT_UNITS_UNSIGNED = 0x30000;
  34.        public const int MIXERCONTROL_CONTROLTYPE_FADER =
  35.        (MIXERCONTROL_CT_CLASS_FADER | MIXERCONTROL_CT_UNITS_UNSIGNED);
  36.        public const int MIXERCONTROL_CONTROLTYPE_VOLUME =
  37.        (MIXERCONTROL_CONTROLTYPE_FADER + 1);
  38.  
  39.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  40.        private static extern int mixerClose(int hmx);
  41.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  42.        private static extern int mixerGetControlDetailsA(int hmxobj, ref
  43. MIXERCONTROLDETAILS pmxcd, int fdwDetails);
  44.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  45.        private static extern int mixerGetDevCapsA(int uMxId, MIXERCAPS
  46.        pmxcaps, int cbmxcaps);
  47.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  48.        private static extern int mixerGetID(int hmxobj, int pumxID, int
  49.        fdwId);
  50.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  51.        private static extern int mixerGetLineControlsA(int hmxobj, ref
  52. MIXERLINECONTROLS pmxlc, int fdwControls);
  53.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  54.        private static extern int mixerGetLineInfoA(int hmxobj, ref
  55. MIXERLINE pmxl, int fdwInfo);
  56.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  57.        private static extern int mixerGetNumDevs();
  58.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  59.        private static extern int mixerMessage(int hmx, int uMsg, int
  60.        dwParam1, int dwParam2);
  61.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  62.        private static extern int mixerOpen(out int phmx, int uMxId,
  63.        int dwCallback, int dwInstance, int fdwOpen);
  64.        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]
  65.        private static extern int mixerSetControlDetails(int hmxobj, ref
  66. MIXERCONTROLDETAILS pmxcd, int fdwDetails);
  67.  
  68.        public struct MIXERCAPS
  69.        {
  70.            public int wMid;
  71.            public int wPid;
  72.            public int vDriverVersion;
  73.            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXPNAMELEN)]
  74.            public string szPname;
  75.            public int fdwSupport;
  76.            public int cDestinations;
  77.        }
  78.  
  79.        public struct MIXERCONTROL
  80.        {
  81.            public int cbStruct;
  82.            public int dwControlID;
  83.            public int dwControlType;
  84.            public int fdwControl;
  85.            public int cMultipleItems;
  86.            [MarshalAs(UnmanagedType.ByValTStr,
  87.            SizeConst = MIXER_SHORT_NAME_CHARS)]
  88.            public string szShortName;
  89.            [MarshalAs(UnmanagedType.ByValTStr,
  90.            SizeConst = MIXER_LONG_NAME_CHARS)]
  91.            public string szName;
  92.            public int lMinimum;
  93.            public int lMaximum;
  94.            [MarshalAs(UnmanagedType.U4, SizeConst = 10)]
  95.            public int reserved;
  96.        }
  97.  
  98.        public struct MIXERCONTROLDETAILS
  99.        {
  100.            public int cbStruct;
  101.            public int dwControlID;
  102.            public int cChannels;
  103.            public int item;
  104.            public int cbDetails;
  105.            public IntPtr paDetails;
  106.        }
  107.  
  108.        public struct MIXERCONTROLDETAILS_UNSIGNED
  109.        {
  110.            public int dwValue;
  111.        }
  112.  
  113.        public struct MIXERLINE
  114.        {
  115.            public int cbStruct;
  116.            public int dwDestination;
  117.            public int dwSource;
  118.            public int dwLineID;
  119.            public int fdwLine;
  120.            public int dwUser;
  121.            public int dwComponentType;
  122.            public int cChannels;
  123.            public int cConnections;
  124.            public int cControls;
  125.            [MarshalAs(UnmanagedType.ByValTStr,
  126.            SizeConst = MIXER_SHORT_NAME_CHARS)]
  127.            public string szShortName;
  128.            [MarshalAs(UnmanagedType.ByValTStr,
  129.            SizeConst = MIXER_LONG_NAME_CHARS)]
  130.            public string szName;
  131.            public int dwType;
  132.            public int dwDeviceID;
  133.            public int wMid;
  134.            public int wPid;
  135.            public int vDriverVersion;
  136.            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXPNAMELEN)]
  137.            public string szPname;
  138.        }
  139.  
  140.        public struct MIXERLINECONTROLS
  141.        {
  142.            public int cbStruct;
  143.            public int dwLineID;
  144.  
  145.            public int dwControl;
  146.            public int cControls;
  147.            public int cbmxctrl;
  148.            public IntPtr pamxctrl;
  149.        }
  150.  
  151.        private bool GetVolumeControl(int hmixer, int componentType,
  152.        int ctrlType, out MIXERCONTROL mxc, out int vCurrentVol)
  153.            {
  154.            // This function attempts to obtain a mixer control.
  155.            // Returns True if successful.
  156.            MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS();
  157.            MIXERLINE mxl = new MIXERLINE();
  158.            MIXERCONTROLDETAILS pmxcd = new MIXERCONTROLDETAILS();
  159.            MIXERCONTROLDETAILS_UNSIGNED du = new
  160.                MIXERCONTROLDETAILS_UNSIGNED();
  161.            mxc = new MIXERCONTROL();
  162.            int rc;
  163.            bool retValue;
  164.            vCurrentVol = -1;
  165.            mxl.cbStruct = Marshal.SizeOf(mxl);
  166.            mxl.dwComponentType = componentType;
  167.            rc = mixerGetLineInfoA(hmixer,ref mxl,
  168.                MIXER_GETLINEINFOF_COMPONENTTYPE );
  169.            if(MMSYSERR_NOERROR == rc)
  170.                {
  171.                int sizeofMIXERCONTROL = 152;
  172.                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
  173.                mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
  174.                mxlc.cbStruct = Marshal.SizeOf(mxlc);
  175.                mxlc.dwLineID = mxl.dwLineID;
  176.                mxlc.dwControl = ctrlType;
  177.                mxlc.cControls = 1;
  178.                mxlc.cbmxctrl = sizeofMIXERCONTROL;
  179.                // Allocate a buffer for the control
  180.                mxc.cbStruct = sizeofMIXERCONTROL;
  181.                // Get the control
  182.                rc = mixerGetLineControlsA(hmixer,ref mxlc,
  183.                    MIXER_GETLINECONTROLSF_ONEBYTYPE);
  184.                if(MMSYSERR_NOERROR == rc)
  185.                    {
  186.                    retValue = true;
  187.                    // Copy the control into the destination structure
  188.                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
  189.                        mxlc.pamxctrl,typeof(MIXERCONTROL));
  190.                    }
  191.                    else
  192.                    {
  193.                    retValue = false;
  194.                    }
  195.                int sizeofMIXERCONTROLDETAILS =
  196.                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
  197.                int sizeofMIXERCONTROLDETAILS_UNSIGNED =
  198.                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED ));
  199.                pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS;
  200.                pmxcd.dwControlID = mxc.dwControlID;
  201.                pmxcd.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED) ;
  202.                pmxcd.cChannels = 1;
  203.                pmxcd.item = 0;
  204.                pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;
  205.                rc = mixerGetControlDetailsA(hmixer,ref pmxcd,
  206.                    MIXER_GETCONTROLDETAILSF_VALUE);
  207.                du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(
  208.                    pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
  209.                vCurrentVol = du.dwValue;
  210.                return retValue;
  211.                }
  212.            retValue = false;
  213.            return retValue;
  214.            }
  215.        private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc, int volume)
  216.            {
  217.            // This function sets the value for a volume control.
  218.            // Returns True if successful
  219.            bool retValue;
  220.            int rc;
  221.            MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
  222.            MIXERCONTROLDETAILS_UNSIGNED vol = new
  223.            MIXERCONTROLDETAILS_UNSIGNED();
  224.            mxcd.item = 0;
  225.            mxcd.dwControlID = mxc.dwControlID;
  226.            mxcd.cbStruct = Marshal.SizeOf(mxcd);
  227.            mxcd.cbDetails = Marshal.SizeOf(vol);
  228.  
  229.            // Allocate a buffer for the control value buffer
  230.            mxcd.cChannels = 1;
  231.            vol.dwValue = volume;
  232.  
  233.            // Copy the data into the control value buffer
  234.            mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(
  235.            typeof(MIXERCONTROLDETAILS_UNSIGNED)));
  236.            Marshal.StructureToPtr(vol, mxcd.paDetails, false);
  237.  
  238.            // Set the control value
  239.            rc = mixerSetControlDetails(hmixer, ref mxcd,
  240.            MIXER_SETCONTROLDETAILSF_VALUE);
  241.  
  242.            if (MMSYSERR_NOERROR == rc)
  243.            {
  244.                retValue = true;
  245.            }
  246.            else
  247.            {
  248.                retValue = false;
  249.            } return retValue;
  250.        }
  251.  
  252.        public int GetVolume()
  253.        {
  254.            int mixer;
  255.            MIXERCONTROL volCtrl = new MIXERCONTROL();
  256.            int currentVol;
  257.            mixerOpen(out mixer, 0, 0, 0, 0);
  258.            int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
  259.            GetVolumeControl(mixer,
  260.            MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
  261.            mixerClose(mixer);
  262.            return currentVol;
  263.        }
  264.  
  265.        public void SetVolume(int vVolume)
  266.        {
  267.            int mixer;
  268.            MIXERCONTROL volCtrl = new MIXERCONTROL();
  269.            int currentVol;
  270.            mixerOpen(out mixer, 0, 0, 0, 0);
  271.            int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
  272.            GetVolumeControl(mixer,
  273.            MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
  274.            if (vVolume > volCtrl.lMaximum) vVolume = volCtrl.lMaximum;
  275.            if (vVolume < volCtrl.lMinimum) vVolume = volCtrl.lMinimum;
  276.            SetVolumeControl(mixer, volCtrl, vVolume);
  277.            GetVolumeControl(mixer,
  278.            MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
  279.            if (vVolume != currentVol)
  280.            {
  281.                throw new Exception("Cannot Set Volume");
  282.            }
  283.            mixerClose(mixer);
  284.  
  285.        }
  286.        public Form1()
  287.        {
  288.            InitializeComponent();
  289.        }
  290.  
  291.        private void Form1_Load(object sender, EventArgs e)
  292.        {
  293.  
  294.        }
  295.  
  296.        private void button1_Click(object sender, EventArgs e)
  297.        {
  298.            MessageBox.Show( this.GetVolume().ToString());
  299.            //set the master volume
  300.             this.SetVolume(1000);
  301.            //Display the new volume
  302.            MessageBox.Show(this.GetVolume().ToString());
  303.        }
  304.    }
  305. }
  306.  
En línea


-R IP
:0100
-A 100 
2826:0100 MOV AH,09
2826:0102 MOV DX,109
2826:0105 INT 21
2826:0105 MOV AH,08
2826:0105 INT 21
2826:0107 INT 20
2826:0109 DB 'MI NICK ES CODELIVE.$' 
2826:0127 
-R BX
:0000
-R CX
:20
-N CODELIVE.COM
-W
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines