Click here to Skip to main content
15,893,486 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Make the Text Bold ?? Pin
Ravenet11-Feb-08 4:24
Ravenet11-Feb-08 4:24 
GeneralRe: How to Make the Text Bold ?? Pin
Pete O'Hanlon11-Feb-08 4:34
mvePete O'Hanlon11-Feb-08 4:34 
GeneralRe: How to Make the Text Bold ?? Pin
Ravenet11-Feb-08 4:37
Ravenet11-Feb-08 4:37 
GeneralRe: How to Make the Text Bold ?? Pin
Guffa11-Feb-08 5:17
Guffa11-Feb-08 5:17 
QuestionWriting text to an open notepad file Pin
Member 51425211-Feb-08 1:25
Member 51425211-Feb-08 1:25 
GeneralRe: Writing text to an open notepad file Pin
Martin#11-Feb-08 2:44
Martin#11-Feb-08 2:44 
GeneralRe: Writing text to an open notepad file Pin
Member 51425211-Feb-08 17:14
Member 51425211-Feb-08 17:14 
GeneralRe: Writing text to an open notepad file Pin
Martin#12-Feb-08 2:14
Martin#12-Feb-08 2:14 
Hello,

Member 514252 wrote:
Thank you Martin

Rose | [Rose]

Member 514252 wrote:
I dont want the notepad to bring to the foreground. I want to update the openned notepad file while it is in the background

OK, I understand your task and tried to find a solution, but have to admit that I didn't succeed.

What have I tried:
SendMessage in cmnbination with WM_SETTEXT.
[DllImport("user32.dll",EntryPoint="SendMessage", CharSet=CharSet.Auto)]
private static extern int SendMessage( int hwnd, int uMsg, int wParam, System.Text.StringBuilder lParam);
 		
private const int WM_SETTEXT = 0x000c;
 
SendMessage((int)procNP[0].MainWindowHandle,WM_SETTEXT, myText.Length, new System.Text.StringBuilder(myText));

Had the effect, that the FileNameChanged (HeadlineText of the Notepad) changed, not the text itselfe.

Sorry for not really helping you.

P.S.:A dirty workaround could be to reset the Foregroundwindow to your actual application
SetForegroundWindow(procNP[0].MainWindowHandle);
 
System.Threading.Thread.Sleep(100);
 
SendKeys.SendWait("Hello World!");
 
SetForegroundWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);

What you have to check is if the notepad IsIconic (minimized).
If yes, the SendKeys will not work.
private const int SW_SHOWNORMAL    = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
 
/// <summary>
/// Gets a Flag if Window is Iconic or not
/// </summary>
/// <param name="hWnd">windowhandle</param>
/// <returns>true or false</returns>
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
 
/// <summary>
/// Show a Window
/// </summary>
/// <param name="hwnd">windowhandle</param>
/// <param name="nCmdShow">parameter to set a special state</param>
/// <returns></returns>
[DllImport("user32")] 
private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
 
IntPtr handleNotePad = procNP[0].MainWindowHandle;
if(handleNotePad!=IntPtr.Zero)
{
    bool wasIconic = IsIconic(handleNotePad);
    if(wasIconic)
        ShowWindow(handleNotePad, SW_SHOWNORMAL);
 
    SetForegroundWindow(handleNotePad);
 
    System.Threading.Thread.Sleep(100);
 
    SendKeys.SendWait("Hello World!");
 
    SetForegroundWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
 
    if(wasIconic)
        ShowWindow(handleNotePad, SW_SHOWMINIMIZED);
}


All the best,

Martin

GeneralRe: Writing text to an open notepad file Pin
Member 51425213-Feb-08 18:22
Member 51425213-Feb-08 18:22 
GeneralVisual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 1:24
Ray Hayes11-Feb-08 1:24 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 3:15
Ed.Poore11-Feb-08 3:15 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 3:52
mvePete O'Hanlon11-Feb-08 3:52 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 5:07
Ed.Poore11-Feb-08 5:07 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 8:30
mvePete O'Hanlon11-Feb-08 8:30 
GeneralRe: Visual C# 2008 Express Edition Pin
Ed.Poore11-Feb-08 8:47
Ed.Poore11-Feb-08 8:47 
GeneralRe: Visual C# 2008 Express Edition Pin
Pete O'Hanlon11-Feb-08 10:28
mvePete O'Hanlon11-Feb-08 10:28 
GeneralRe: Visual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 4:24
Ray Hayes11-Feb-08 4:24 
GeneralRe: Visual C# 2008 Express Edition Pin
leppie11-Feb-08 8:14
leppie11-Feb-08 8:14 
GeneralRe: Visual C# 2008 Express Edition Pin
Ray Hayes11-Feb-08 9:09
Ray Hayes11-Feb-08 9:09 
GeneralPlugins Pin
pokabot11-Feb-08 1:18
pokabot11-Feb-08 1:18 
GeneralRe: Plugins Pin
Pete O'Hanlon11-Feb-08 2:23
mvePete O'Hanlon11-Feb-08 2:23 
GeneralRe: Plugins Pin
Ed.Poore11-Feb-08 3:17
Ed.Poore11-Feb-08 3:17 
GeneralRe: Plugins Pin
pokabot11-Feb-08 4:26
pokabot11-Feb-08 4:26 
GeneralRe: Plugins Pin
Ed.Poore11-Feb-08 5:07
Ed.Poore11-Feb-08 5:07 
GeneralRe: Plugins Pin
Pete O'Hanlon11-Feb-08 8:33
mvePete O'Hanlon11-Feb-08 8:33 

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.