- This topic has 7 replies, 2 voices, and was last updated 18 years ago by BattleStar-Galactica.
-
AuthorPosts
-
August 22, 2006 at 12:44 pm #191441nooobMember
hi all
Can anyone help me with how to set text to a textfield/textbox using e.g. the SendMessage api in C# or .NET?
The signature of the SendMessage in C# is this:
[DllImport(“user32.dll”, CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
where the wParam and lParam are both of type IntPtr (and not of type StringBuilder)…so i dont know where to put the string that I want to set to a textbox!!!
Is there another way?!
Plz…help
ty alot
nooob
August 22, 2006 at 2:27 pm #191448BattleStar-GalacticaMemberpost your question in c#.net forum, you’ll have more chance to get response but bwt i’m around here so I will give you the solution. I’m not good for explanation but check this code bellow
[DllImport(“user32.dll”, EntryPoint = “SendMessage”)]
public static extern int SendMessageByString(
#if STRING
int hwnd, uint wMsg, int wParam, string lParam);//lParam :
#else
int hwnd, uint wMsg, int wParam, StringBuilder lParam);//lParam :#endif
that’s code it work for stringbuilder and string
August 22, 2006 at 2:30 pm #191447BattleStar-GalacticaMemberor if you dont want to complicate your life, just doing like this
[DllImport(“user32.dll”, EntryPoint = “SendMessage”)]
public static extern int SendMessageByString(
int hwnd, uint wMsg, int wParam, string lParam);//lParam :the 4th parameter is string type and not stringbuilder but I like the first one
August 22, 2006 at 8:44 pm #191446nooobMemberty alot nanomachine for ur time…
below is my code:
private void btnBounce_Click(object sender, EventArgs e) { IntPtr hRoom = FindRoom("My Window Class"); PostMessage(hRoom, WM_COMMAND, (IntPtr)32947, IntPtr.Zero); //if I run the program and click the button the prog stops here...halts IntPtr hBounceWin = FindRoom("#32770"); IntPtr hEdit = FindWindowEx(hBounceWin, IntPtr.Zero, "Edit", null); SendMessageByString(hEdit, WM_SETTEXT, IntPtr .Zero, "Bounce This Person"); IntPtr hBounceBut = FindWindowEx(hBounceWin, IntPtr.Zero, "Button", "Bounce"); SendMessageLong(hBounceBut, WM_KEYDOWN, VK_SPACE, IntPtr.Zero); SendMessageLong(hBounceBut, WM_KEYUP, VK_SPACE, IntPtr.Zero); }
if I run the prog and click on the associated button then the prog stops after executing the PostMessage api…but if i debug it…then everything is fine?!?!
Am I missing something like DoEvents as in vb6?
any idea?
thx nano
nooob
August 23, 2006 at 12:35 pm #191445BattleStar-GalacticaMemberyour error maybe this line
IntPtr hBounceWin = FindRoom(“#32770”);
cuz the winclass #32770 is so many, i’m not sure you can find the right window handle with using that class in parameter
between IntPtr hBounceWin = FindRoom(“#32770”); and your postmessage
maybe do a sleep 100 milisecond to let the time window to bounce user loadedAugust 23, 2006 at 1:13 pm #191444nooobMemberok nanomachine dude…thanks alot for your replies
i will try
nooob
August 23, 2006 at 3:07 pm #191443BattleStar-GalacticaMemberwhat version of .net do u use, I’m using vs2005.
if you use same version of mine and if you dont figure it out yet, I will give a try.
to find apart of window caption use enumwindows is a good idea. here is example.
EnumWindows(EnumWindowsProc,IntPtr.Zero);
and the function EnumWindowsProc is like this
private static bool EnumWindowsProc(IntPtr hWnd, IntPtr param)
{
string tmp = GetWindowText(hWnd);
if (tmp.IndexOf(“Ready to bounce”)>-1)
{
hWndTobounce =hWnd;
return false;
}
return true;
}define api enumwindows like this
public delegate bool CallBack(IntPtr handle, IntPtr param);
[DllImport(“user32.dll”)]
public static extern bool EnumWindows(CallBack cb, IntPtr param);August 25, 2006 at 7:58 pm #191442nooobMember😀 got it…dude
nanomachine ty dude…ur previous post gave me the answer…i.e. to sleep for a few ms.
sleeping there is imporant because i load a window there…
now it works…thnx aloti use the vc#2005 express edition
i neew help with another thing as well (getting the width of a view list)..but i will make it another thread
nooob[/b]
-
AuthorPosts
Related
- You must be logged in to reply to this topic.