Getting the caption of a window
#1
So, I'm trying to get the contents of the server console.
Everything goes fine, it gets the pointers without any problem.
Thing is, it doesn't get the contents. Well okay, it does. But it doesn't set the right ones(??)
My tool (winspy) gets them really fucking easy and that's even more annoying

Code:
namespace iw5test { class Program { static void Main(string[] args) { StringBuilder sbWinText = new StringBuilder(256); StringBuilder lulz = new StringBuilder(256); IntPtr form = FindWindow("IW5 WinConsole", null); IntPtr txtbox = FindWindowEx(form, IntPtr.Zero, "Edit", null); IntPtr console = FindWindowEx(form, txtbox, "Edit", null); bool f = GetWindowText(console, sbWinText, 256); bool a = GetWindowText(form, lulz, 256); bool x = SetWindowText(console, "HAX!"); bool xxx = SetWindowText(txtbox, "sv_maxclients 1337"); Console.WriteLine("console get text operation = {0}\r\nconsole set text operation = {1}\r\ncommand set text operation = {2}\r\nform get text operation\r\n", f, x, xxx, a); Console.WriteLine("CONSOLE TXT = {0}", sbWinText.ToString()); Console.WriteLine("FORM TXT = {0}", lulz.ToString()); Console.ReadLine(); } [DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Ansi)] public static extern bool GetWindowText(IntPtr hWnd, [OutAttribute()] StringBuilder strNewWindowName, Int32 maxCharCount); [DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet = CharSet.Ansi)] public static extern bool SetWindowText(IntPtr hWnd, string lpString); [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Ansi)] public static extern IntPtr FindWindow(string className, string windowName); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); } }

The output is:
Code:
console get text operation = False console set text operation = True command set text operation = True form get text operation= True CONSOLE TXT = FORM TXT = Call of Duty: Modern Warfare 3 Dedicated Server - PlayerManager Edition

And the second time I run it:
Code:
console get text operation = True console set text operation = True command set text operation = True form get text operation= True CONSOLE TXT = HAX! FORM TXT = Call of Duty: Modern Warfare 3 Dedicated Server - PlayerManager Edition tion

as you can see it gets the value i set to it.
Thing is, it doesn't change anything....
I know it's possible because WinSpy does it without any probs:
[Image: 03qHEpTGBt.png]

I really need help with this, I don't know that much about the winapi but i couldn't find anything about it on the internet


EDIT: it even changes the content without any problem Fuu
WHY CAN'T I DO THAT?!
[Image: mC2r5UJ74w.png]
EDIT: Tried InternalGetWindowText. No difference Sad

EDIT: Browsed trough winspy sourcecode, basically what I found. but what the **** is a HWND?
Code:
case IDC_SETCAPTION: // Set the target's window caption to the contents of the edit box hwndEdit1 = GetDlgItem(hwnd, IDC_CAPTION1); hwndEdit2 = GetDlgItem(hwnd, IDC_CAPTION2); // Show the combo box and hide the edit box if(IsWindowVisible(hwndEdit1)) { // Copy the contents of the edit box to the combo box GetWindowText(hwndEdit1, szCaption, sizeof(szCaption) / sizeof(TCHAR)); SetWindowText(hwndEdit2, szCaption); ShowWindow(hwndEdit2, SW_SHOW); ShowWindow(hwndEdit1, SW_HIDE); SetFocus(hwndEdit2); } hCtrl = (HWND)spy_hCurWnd; // get the original text and add it to the combo list GetWindowText(hCtrl, szCaption, sizeof(szCaption) / sizeof(TCHAR)); SendMessage(hwndEdit2, CB_ADDSTRING, 0, (LPARAM)szCaption); // now see what the new caption is to be GetWindowText(hwndEdit2, szCaption, sizeof(szCaption) / sizeof(TCHAR)); // set the text to the new string if(hCtrl != 0 && IsWindow(hCtrl)) SendMessage(hCtrl, WM_SETTEXT, 0, (LPARAM)szCaption); return TRUE; }
Reply

#2
It is a handle(H) window(WND), basicly it calls for all the other commands to gain access to a window.
Reply

#3
PLZ HALP PLZ *bump*
Reply

#4
thanks :'(
Reply

#5
Restart your computer




Troll
[Image: azuw.jpg]
Reply

#6
Fuu

damn you itsmods, after all i've done for you.....
Reply

#7
You made a thread with a question, you looked through the source, found out how it worked, asked what is HWND, @aosma8 answered, thread over.

We don't know what you wan't anymore.
[Image: MaEIQ.png]
Reply

#8
I'm still not able to retrieve the console contents....
Pretty obvious?
Reply

#9
Just read through the source some more and find out how they do it?
[Image: MaEIQ.png]
Reply

#10
Finally solved it:
Code:
unsafe string MW3Console { get { IntPtr form = *(IntPtr*)0x5933A50; IntPtr txtbox = FindWindowEx(form, IntPtr.Zero, "Edit", null); IntPtr console = FindWindowEx(form, txtbox, "Edit", null); StringBuilder sb = new StringBuilder(9999999); int result = SendMessageTimeout( console, 0x0D /*WM_GETTEXT*/, 9999999, sb, 10 /*SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG*/, 500, IntPtr.Zero); return sb.ToString(); } }
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Window view Arteq 27 14,663 05-03-2012, 11:13
Last Post: Pozzuh
  Remove MiniMap Red Dots / Remove Window Glare/Smudges?! koil 0 2,030 06-27-2011, 09:58
Last Post: koil

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.