Click here to Skip to main content
15,914,163 members
Home / Discussions / C#
   

C#

 
GeneralRe: Responsive UI - WPF with Properties Pin
SynergiAios23-Jul-13 0:18
SynergiAios23-Jul-13 0:18 
QuestionOO Design for Specifc Problem Pin
KeithF22-Jul-13 6:17
KeithF22-Jul-13 6:17 
AnswerRe: OO Design for Specifc Problem Pin
KeithF22-Jul-13 21:41
KeithF22-Jul-13 21:41 
AnswerRe: OO Design for Specifc Problem Pin
Eddy Vluggen23-Jul-13 0:30
professionalEddy Vluggen23-Jul-13 0:30 
GeneralRe: OO Design for Specifc Problem Pin
KeithF30-Jul-13 22:49
KeithF30-Jul-13 22:49 
QuestionMicrosoft Expression Encoder with IIS Live Smooth Streaming Issue Pin
Member 1003572121-Jul-13 21:46
Member 1003572121-Jul-13 21:46 
AnswerRe: Microsoft Expression Encoder with IIS Live Smooth Streaming Issue Pin
Dave Kreskowiak22-Jul-13 1:46
mveDave Kreskowiak22-Jul-13 1:46 
QuestionGetGuiThreadInfo can not get the caret's position Pin
goldli8820-Jul-13 23:12
goldli8820-Jul-13 23:12 
I want to get the caret position with my C# application.but in some cases ,GetGuiThreadInfo does not work creectly.

it works well on

1. notepad
2. ie
3. explorer
4. word

and works bad on (hwndCaret will be 0)

1. Visual Studio
2. Firefox
3. Sublime Text 2

Anyone who can helps me?

C#
public partial class Form1 : Form
        {
    
            [DllImport("user32.dll")]
            public static extern IntPtr GetForegroundWindow();
    
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
            
            [DllImport("user32.dll")]
            static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
    
            [DllImport("user32.dll")]
            static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);
    
    
            [StructLayout(LayoutKind.Sequential)]
            public struct GUITHREADINFO
            {
                public int cbSize;
                public int flags;
                public IntPtr hwndActive;
                public IntPtr hwndFocus;
                public IntPtr hwndCapture;
                public IntPtr hwndMenuOwner;
                public IntPtr hwndMoveSize;
                public IntPtr hwndCaret;
                public Rectangle rectCaret;
            }
    
            public  GUITHREADINFO? GetGuiThreadInfo(IntPtr hwnd)
            {
                if (hwnd != IntPtr.Zero)
                {
                    uint threadId = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
    
                    GUITHREADINFO guiThreadInfo = new GUITHREADINFO();
                    guiThreadInfo.cbSize = Marshal.SizeOf(guiThreadInfo);
    
                    if (GetGUIThreadInfo(threadId, ref guiThreadInfo) == false)
                        return null;
                    return guiThreadInfo;
                }
                return null;
            }
    
            public void SendText(string text)
            {
                IntPtr hwnd = GetForegroundWindow();
                if (String.IsNullOrEmpty(text))
                    return;
                GUITHREADINFO? guiInfo = GetGuiThreadInfo(hwnd);
                AddMessage("go");
                if (guiInfo != null)
                {
                    IntPtr ptr = (IntPtr)guiInfo.Value.hwndCaret;
                    AddMessage("hwndCaret = " + ptr.ToInt32());
                    if (ptr != IntPtr.Zero)
                    {
                        AddMessage("Left = " + guiInfo.Value.rectCaret.Left);
                        for (int i = 0; i < text.Length; i++)
                        {
                            SendMessage(ptr, 0x102, (IntPtr)(int)text[i], IntPtr.Zero);
                        }
                    }
                }
            }
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void AddMessage(string message)
            {
                var i = listBox1.Items.Add(message);
                listBox1.SelectedIndex = i;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Thread.Sleep(2000);
                //textBox1.Focus();
                SendText("Abcdefg");
                AddMessage("------------");
            }
        }

QuestionHow to Create Dynamic Buttons With Students Roll No. on It From Database Pin
jackspero1820-Jul-13 1:38
jackspero1820-Jul-13 1:38 
AnswerRe: How to Create Dynamic Buttons With Students Roll No. on It From Database Pin
Garth J Lancaster20-Jul-13 2:05
professionalGarth J Lancaster20-Jul-13 2:05 
QuestionC# unmanage DLL export Pin
hijeenu19-Jul-13 10:32
hijeenu19-Jul-13 10:32 
QuestionUpdate Shorthand? Pin
eddieangel19-Jul-13 8:37
eddieangel19-Jul-13 8:37 
AnswerRe: Update Shorthand? Pin
Dave Kreskowiak19-Jul-13 9:50
mveDave Kreskowiak19-Jul-13 9:50 
AnswerRe: Update Shorthand? Pin
Abhinav S19-Jul-13 18:48
Abhinav S19-Jul-13 18:48 
AnswerRe: Update Shorthand? Pin
Jean A Brandelero22-Jul-13 3:59
Jean A Brandelero22-Jul-13 3:59 
QuestionCalling VB 6 OCX from C# EXE Pin
matinon2219-Jul-13 2:18
matinon2219-Jul-13 2:18 
AnswerRe: Calling VB 6 OCX from C# EXE Pin
Dave Kreskowiak19-Jul-13 2:21
mveDave Kreskowiak19-Jul-13 2:21 
GeneralRe: Calling VB 6 OCX from C# EXE Pin
matinon2223-Jul-13 22:18
matinon2223-Jul-13 22:18 
GeneralRe: Calling VB 6 OCX from C# EXE Pin
Dave Kreskowiak24-Jul-13 3:52
mveDave Kreskowiak24-Jul-13 3:52 
QuestionGeneric collections Pin
PozzaVecia19-Jul-13 0:09
PozzaVecia19-Jul-13 0:09 
AnswerRe: Generic collections Pin
Nicholas Marty19-Jul-13 0:41
professionalNicholas Marty19-Jul-13 0:41 
GeneralRe: Generic collections Pin
PozzaVecia19-Jul-13 1:12
PozzaVecia19-Jul-13 1:12 
GeneralRe: Generic collections Pin
Nicholas Marty19-Jul-13 1:17
professionalNicholas Marty19-Jul-13 1:17 
GeneralRe: Generic collections Pin
PozzaVecia19-Jul-13 1:26
PozzaVecia19-Jul-13 1:26 
GeneralRe: Generic collections Pin
Nicholas Marty19-Jul-13 2:07
professionalNicholas Marty19-Jul-13 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.