Пример #1
0
        /// <summary>
        /// Shows <see cref="VoiceRecorder">Voice Recorder</see> control for a specific filename.
        /// </summary>
        /// <param name="fileName"></param>
        public void Show(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(fileName, "FileName must be set");
            }

            base.Show();

#if !NDOC && !DESIGN
            _filename = fileName;
            CleanFileName();

            _vrd.lpszRecordFileName = MarshalEx.StringToHGlobalUni(_filename);
            _vrd.hwndParent         = HostHandle;
            _vrd.Styles             = _styles;

            _vr = VoiceRecorder_Create(_vrd);
            ShowWindow(_vr, 1);
            UpdateWindow(_vr);

            Rectangle r = Win32.Win32Window.GetWindowRect(_vr);
            Width  = r.Width;
            Height = r.Height;
#else
            Width  = 127;
            Height = 26;
#endif
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="netRes"></param>
        /// <param name="shareName"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public static void Add(IntPtr hwnd, string netRes, string shareName, string userName, string password)
        {
            var netresource = new NETRESOURCE();
            var ptr         = IntPtr.Zero;

            try
            {
                netresource.Scope       = RESOURCE_GLOBALNET | RESOURCE_REMEMBERED;
                netresource.Type        = RESOURCETYPE_DISK;
                netresource.DisplayType = RESOURCEDISPLAYTYPE_SHARE;
                netresource.Usage       = RESOURCEUSAGE_CONNECTABLE;
                netresource.RemoteName  = MarshalEx.StringToHGlobalUni(netRes);
                netresource.LocalName   = MarshalEx.StringToHGlobalUni(shareName);
                netresource.Comment     = IntPtr.Zero;
                netresource.Provider    = IntPtr.Zero;

                ptr = Marshal.AllocHGlobal(Marshal.SizeOf(netresource));
                Marshal.StructureToPtr(netresource, ptr, false);

                var ret = NativeMethods.WNetAddConnection3(hwnd, ptr, password, userName, 1);
                if (ret != 0)
                {
                    throw new Win32Exception(ret, ((NetworkErrors)ret).ToString());
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
                Marshal.FreeHGlobal(netresource.RemoteName);
                Marshal.FreeHGlobal(netresource.LocalName);
            }
        }
Пример #3
0
        /// <summary>
        /// Finds the first item after the specified index that matches the specified string.
        /// <para><b>New in v1.3</b></para>
        /// </summary>
        /// <param name="s">The <see cref="System.String"/> to search for.</param>
        /// <param name="startIndex">The zero-based index of the item before the first item to be searched. Set to -1 to search from the beginning of the control.</param>
        /// <returns>The zero-based index of the first item found; returns -1 if no match is found.</returns>
        public int FindStringExact(string s, int startIndex)
        {
            int    index   = -1;
            IntPtr pString = MarshalEx.StringToHGlobalUni(s);

            index = (int)Win32Window.SendMessage(this.Handle, (int)CB.FINDSTRINGEXACT, startIndex, pString);
            MarshalEx.FreeHGlobal(pString);
            return(index);
        }
        public static int FindString(this ComboBox combo, string s, int startIndex)
        {
            var lParam = MarshalEx.StringToHGlobalUni(s);
            var find   = (int)Win32Window.SendMessage(combo.Handle, (int)CB.FINDSTRING, startIndex, lParam);

            Marshal.FreeHGlobal(lParam);

            return(find);
        }
Пример #5
0
        /// <summary>
        /// Loads the document at the specified URL into the <see cref="WebBrowser"/> control, replacing the previous document.
        /// </summary>
        /// <param name="url">The URL of the document to load.</param>
        public void Navigate(string url)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(url + '\0');

            //send message to native control
            Win32Window.SendMessage(ChildHandle, (int)DTM.NAVIGATE, 0, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Пример #6
0
        /// <summary>
        /// Instruct the WebBrowser to jump to the indicated anchor.
        /// <para><b>New in v1.3</b></para>
        /// </summary>
        /// <param name="anchor">The name of the anchor to which the HTML control is to jump.</param>
        /// <remarks>If the anchor is already in the document, the jump occurs immediately.
        /// If the specified anchor is not in the document, the request will be remembered such that, if the anchor is added, the jump will occur as soon as the anchor is available.
        /// While there is a pending anchor, any navigation commands from the user, such as keyboard scrolling or using the scroll bar, aborts the pending anchor jump.</remarks>
        public void JumpToAnchor(string anchor)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(anchor + '\0');

            //send message to native control adding to current text
            Win32Window.SendMessage(ChildHandle, (int)DTM.ANCHORW, 0, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Пример #7
0
        /// <summary>
        /// Sets the symbols to use with the control on Smartphone.
        /// </summary>
        /// <param name="control">Control for which Symbol collection is to be used.</param>
        /// <param name="symbols">Collection of characters to be used as symbols.</param>
        public void SetSymbols(Control control, string symbols)
        {
            if (control is TextBox)
            {
                //get the handle to the child (native) control
                control.Capture = true;
                IntPtr hwnd = Win32Window.GetWindow(Win32Window.GetCapture(), GW.CHILD);
                control.Capture = false;

                IntPtr pSymbols = MarshalEx.StringToHGlobalUni(symbols);
                IntPtr result   = Win32Window.SendMessage(hwnd, EM_SETSYMBOLS, IntPtr.Zero, pSymbols.ToInt32());
                MarshalEx.FreeHGlobal(pSymbols);
            }
        }
Пример #8
0
        /// <summary>
        /// Reloads the document currently displayed in the WebBrowser control by checking the server for an updated version.
        /// </summary>
        public override void Refresh()
        {
            //only refresh if an address has been set
            if (m_url != null)
            {
#if !DESIGN
                //allocate temporary native buffer
                IntPtr stringptr = MarshalEx.StringToHGlobalUni(m_url + '\0');

                //send message to native control
                Win32Window.SendMessage(ChildHandle, (int)DTM.NAVIGATE, (int)NAVIGATEFLAG.REFRESH, (int)stringptr);

                //free native memory
                MarshalEx.FreeHGlobal(stringptr);
#endif
            }
        }
Пример #9
0
        /// <summary>
        /// Adds text to the WebBrowser control.
        /// </summary>
        /// <param name="text">Text to be added.</param>
        /// <param name="plain">If TRUE text is treated as plain text, else treated as HTML Source.</param>
        public void AddText(string text, bool plain)
        {
#if !DESIGN
            //allocate temporary native buffer
            IntPtr stringptr = MarshalEx.StringToHGlobalUni(text + '\0');

            int iplain = 0;

            if (plain)
            {
                iplain = -1;
            }

            //send message to native control adding to current text
            Win32Window.SendMessage(ChildHandle, (int)DTM.ADDTEXTW, iplain, (int)stringptr);

            //free native memory
            MarshalEx.FreeHGlobal(stringptr);
#endif
        }
Пример #10
0
        /// <summary>
        /// Maps the network resouce to the specified share name
        /// </summary>
        /// <param name="hwnd">Owner window handle</param>
        /// <param name="netRes">Network resource to connect</param>
        /// <param name="shareName">Share name</param>
        /// <param name="userName">User name</param>
        /// <param name="password">Password</param>
        public static void MapDrive(IntPtr hwnd, string netRes, string shareName, string userName, string password)
        {
            NETRESOURCE NetRes = new NETRESOURCE();

            NetRes.dwScope       = RESOURCE_GLOBALNET | RESOURCE_REMEMBERED;
            NetRes.dwType        = RESOURCETYPE_DISK;
            NetRes.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE;
            NetRes.dwUsage       = RESOURCEUSAGE_CONNECTABLE;
            NetRes.lpRemoteName  = MarshalEx.StringToHGlobalUni(netRes);
            NetRes.lpLocalName   = MarshalEx.StringToHGlobalUni(shareName);
            NetRes.lpComment     = IntPtr.Zero;
            NetRes.lpProvider    = IntPtr.Zero;

            int ret = WNetAddConnection3(hwnd, NetRes, password, userName, 1);

            if (ret != 0)
            {
                throw new System.ComponentModel.Win32Exception(ret, ((NetworkErrors)ret).ToString());
            }
        }
Пример #11
0
        //called when a change occurs in the bound collection
        private void ComboBoxEx_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (m_updatable)
            {
                if (e.ListChangedType == ListChangedType.ItemChanged)
                {
                    //update the item

                    //delete old item
                    Win32Window.SendMessage(this.Handle, CB_DELETESTRING, e.NewIndex, 0);
                    //get display text for new item
                    string newval = this.GetItemText(this.Items[e.NewIndex]);
                    //marshal to native memory
                    IntPtr pString = MarshalEx.StringToHGlobalUni(newval);
                    //send message to native control
                    Win32Window.SendMessage(this.Handle, CB_INSERTSTRING, e.NewIndex, pString);
                    //free native memory
                    MarshalEx.FreeHGlobal(pString);
                }
            }
        }
Пример #12
0
        private void Show()
        {
            m_data.pszHTML    = MarshalEx.StringToHGlobalUni(mText);
            m_data.pszTitle   = MarshalEx.StringToHGlobalUni(mCaption);
            m_data.hicon      = mIcon;
            m_data.csDuration = mDuration;

            if (mDuration == 0)
            {
                m_data.npPriority = SHNP.ICONIC;
            }
            else
            {
                m_data.npPriority = SHNP.INFORM;
            }

            if (mCritical)
            {
                m_data.grfFlags |= SHNF.CRITICAL;
            }
            else
            {
                m_data.grfFlags ^= (m_data.grfFlags & SHNF.CRITICAL);
            }

            int hresult = SHNotificationAdd(ref m_data);

            if (m_data.pszTitle != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(m_data.pszTitle);
                m_data.pszTitle = IntPtr.Zero;
            }
            if (m_data.pszHTML != IntPtr.Zero)
            {
                MarshalEx.FreeHGlobal(m_data.pszHTML);
                m_data.pszHTML = IntPtr.Zero;
            }
        }
Пример #13
0
        /// <summary>
        /// Places nonpersistent data on the system clipboard.
        /// </summary>
        /// <param name="data">The data to place on the clipboard.</param>
        /// <exception cref="System.ArgumentNullException">The value of data is null.</exception>
        public static void SetDataObject(IDataObject data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("The value of data is null");
            }
            else
            {
                if (!OpenClipboard(IntPtr.Zero))
                {
                    throw new System.Runtime.InteropServices.ExternalException("Could not open Clipboard");
                }

                if (!EmptyClipboard())
                {
                    throw new System.Runtime.InteropServices.ExternalException("Unable to empty Clipboard");
                }

                //from here on we are only supporting unicode text, but it would be possible to support other formats
                if (data.GetDataPresent(DataFormats.UnicodeText))
                {
                    string unicodedata;
                    IntPtr hClipboard;

                    try
                    {
                        //extract unicode string from supplied data
                        unicodedata = data.GetData(DataFormats.UnicodeText).ToString();
                    }
                    catch
                    {
                        throw new FormatException("Clipboard data not in a recognised format");
                    }

                    //marshall the string
                    hClipboard = MarshalEx.StringToHGlobalUni(unicodedata);

                    //pass data to clipboard
                    if (SetClipboardData(ClipboardFormats.UnicodeText, hClipboard) == IntPtr.Zero)
                    {
                        throw new System.Runtime.InteropServices.ExternalException("Could not put data on Clipboard");
                    }
                }
                else if (data.GetDataPresent(DataFormats.Bitmap))
                {
                    System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)data.GetData(DataFormats.Bitmap);

                    int bs = bmp.Width * 3 * bmp.Height;
                    //allocate unmanaged memory
                    IntPtr hClipboard = MarshalEx.AllocHGlobal(bs + 41);
                    byte[] buffer     = new byte[40];

                    MemoryStream strm = new MemoryStream(buffer);
                    BinaryWriter wr   = new BinaryWriter(strm);
                    wr.Write(40);
                    wr.Write(bmp.Width);
                    wr.Write(bmp.Height);
                    wr.Write((short)1);
                    wr.Write((short)0x18);
                    // remaining bytes will be 0
                    wr.Close();

                    MarshalEx.WriteByteArray(hClipboard, 0, buffer);
                    int pos = 40;
                    for (int r = bmp.Height - 1; r >= 0; r--)
                    {
                        for (int c = 0; c < bmp.Width; c++)
                        {
                            int color = bmp.GetPixel(c, r).ToArgb();

                            byte red   = (byte)((color & 0x00ff0000) >> 16);
                            byte green = (byte)((color & 0x0000ff00) >> 8);
                            byte blue  = (byte)(color & 0x000000ff);

                            MarshalEx.WriteByte(hClipboard, pos++, blue);
                            MarshalEx.WriteByte(hClipboard, pos++, green);
                            MarshalEx.WriteByte(hClipboard, pos++, red);
                        }
                    }


                    //pass data to clipboard
                    if (SetClipboardData(ClipboardFormats.Bitmap, hClipboard) == IntPtr.Zero)
                    {
                        throw new System.Runtime.InteropServices.ExternalException("Could not put data on Clipboard");
                    }
                }

                if (!CloseClipboard())
                {
                    throw new System.Runtime.InteropServices.ExternalException("Could not close Clipboard");
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Enumerates network resources.
        /// </summary>
        /// <param name="remoteName">The name of the server</param>
        /// <returns>Array of NetworkResource class</returns>
        public static NetworkResource[] GetNetworkResources(string remoteName)
        {
            NETRESOURCE netRes = new NETRESOURCE();

            netRes.dwScope      = RESOURCE_GLOBALNET;
            netRes.dwType       = RESOURCETYPE_DISK;
            netRes.dwUsage      = RESOURCEUSAGE_CONTAINER;
            netRes.lpRemoteName = MarshalEx.StringToHGlobalUni(remoteName);
            netRes.lpLocalName  = MarshalEx.StringToHGlobalUni("");
            netRes.lpComment    = IntPtr.Zero;
            netRes.lpProvider   = IntPtr.Zero;

            IntPtr hEnum = IntPtr.Zero;

            int ret = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, netRes, ref hEnum);

            if (ret != 0)
            {
                throw new System.ComponentModel.Win32Exception(ret, ((NetworkErrors)ret).ToString());
            }

            //Allocate memory for NETRESOURCE array
            int    bufferSize = 16384;
            IntPtr buffer     = MarshalEx.AllocHLocal(bufferSize);

            if (buffer == IntPtr.Zero)
            {
                throw new OutOfMemoryException("There's not enough native memory.");
            }

            uint c = 0xFFFFFFFF;

            int       count   = (int)c;
            int       size    = Marshal.SizeOf(typeof(NETRESOURCE));
            ArrayList arrList = new ArrayList();

            ret = WNetEnumResource(hEnum, ref count, buffer, ref bufferSize);
            if (ret == 0)
            {
                IntPtr currPtr = buffer;
                for (int i = 0; i < count; i++)
                {
                    netRes = (NETRESOURCE)Marshal.PtrToStructure(currPtr, typeof(NETRESOURCE));
                    NetworkResource res = new NetworkResource("", Marshal.PtrToStringUni(netRes.lpRemoteName));
                    //res.RemoteName = Marshal.PtrToStringUni(netRes.lpRemoteName);

                    arrList.Add(res);
                    currPtr = new IntPtr((int)currPtr + size);
                }
            }
            else
            {
                //clean up
                MarshalEx.FreeHLocal(buffer);
                throw new System.ComponentModel.Win32Exception(ret, ((NetworkErrors)ret).ToString());
            }

            //clean up
            MarshalEx.FreeHLocal(buffer);

            return((NetworkResource[])arrList.ToArray(typeof(NetworkResource)));
        }