Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Embedd notepad++ in my windows form. Through which i want to control notepad++ with my own function.
So far i did,
C#
public static extern bool SetForegroundWindow(IntPtr hWnd);
       [DllImport("user32.dll")]
       public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
       [DllImport("user32.dll")]
       public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
       [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)] //
       public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
       [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
       public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam,
       int lparam);
       [DllImport("User32.dll", CharSet = CharSet.Auto)]
       extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, [In] string lpClassName, [In] string lpWindowName);
       [DllImport("User32.dll", EntryPoint = "SendMessage")]
       extern static int SendMessageGetTextLength(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
       [DllImport("User32.dll")]
       public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
       public Process proc;

private void Form1_Load(object sender, EventArgs e)
       {
           Process[] pProcess = System.Diagnostics.Process.GetProcessesByName();
           foreach (Process p in pProcess)
           {
               p.Kill();

           }
           proc = Process.Start("notepad++.EXE");
           proc.WaitForInputIdle();
           Thread.Sleep(200);
           SetParent(proc.MainWindowHandle, splitContainer1.Panel2.Handle);
           SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
          // SetForegroundWindow(proc.MainWindowHandle);
          // SendKeys.Send("{F11}");
       }

internal void replaceToolStripMenuItem_Click(object sender, EventArgs e)
       {
 SetForegroundWindow(proc.MainWindowHandle);

Win32.SendMessage(proc.MainWindowHandle, SciMsg.SCI_INSERTTEXT,0, "Hello, Notepad++... from .NET!");
        }


i cant edit or insert any text to my notepad++ panel in windows form.
Could anyone help me?
Posted
Updated 23-Nov-14 21:33pm
v3
Comments
BillWoodruff 19-Nov-14 7:32am    
We can't see your screen, and watch you code: what happens here: does NotePad++ appear in a Panel ? Are there error messages when you try to edit/insert Text ?
Member 11246099 20-Nov-14 7:49am    
@BillWoodruff: ya. notepad++ appear on the panel. what i am expect is, i use one button in my form. whenever i click that button, replacing will occur in notepad++ for a single word.
ex, text in notepad++ is,
"This is a file testing for replacing a word in notepad++ through Windows form."

i want to replace a word "This" to "It".
can anyone help me?

Expected Output appear in notepad++ is,
"It is a file testing for replacing a word in notepad++ through Windows form."

i am using split container.
In panel1--i have a button.
In panel2--notepad++ appear when the form loading.
Redgum 20-Nov-14 19:00pm    
First question needed to be asked is 'What problem are you trying to solve?'
If you are simply looking to replace strings within a file(s) there are far more elegant and less dangerous ways to do this in code. While interesting that you've embedded Notepad++ into a WinForms app, the first question needs to be asked in earnest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900