cannot trigger the textchanged event while using sendmessage and WM_SETTEXT but PostMessage can

StackOverflow https://stackoverflow.com/questions/19233518

سؤال

I have a problem similar to this but I still cannot solve it.

I am trying to edit a textbox for contrast and another for brightness inside an image viewer program from my wpf program. Changing the values inside these two textbox will trigger the change of the image right away. Using Spy++ allows me to get the exact window handle for both of those textbox and I've tried these following methods but still can't get what I need from my C# program.

Method 1: This method allows me to change the whole text of the textbox instantly but the change doesn't automatically trigger and reflect contrast/brightness change of the image in the image viewer.

IntPtr text = Marshal.StringToCoTaskMemUni(value.ToString());
SendMessage(window, WM_SETTEXT, 0, text);
Marshal.FreeCoTaskMem(text);

Method 2: This method gets the RECT location of the textbox, manually setting the mouse to click on that textbox and then continuously sending keys for the specific number (eg. contrast value of 100 will send keydown 3 times with vk for the number 1 once and number 0 twice). This method will successfully change the text in the textbox and trigger the contrast event when each digit is entered. The problem is that the image changes with each input of the digits. The image reflects to the first input of key1 (contrast at 1) and then key0 (contrast at 10) and then finally another key0 (contrast at 100, the actual contrast we want).

    RECT hwnd_loc = new RECT();
    GetWindowRect(w_hwnd, ref hwnd_loc);

    IntPtr lParam = (IntPtr)(((hwnd_loc.Top + 2) << 16) | (hwnd_loc.Left + 2));

    PostMessage(w_hwnd, WM_LBUTTONDOWN, 0, (int)lParam);
    PostMessage(w_hwnd, WM_LBUTTONUP, 0, (int)lParam);

    for (int i = index.Count - 1; i >= 0; i--)
    {
        PostMessage(w_hwnd, WM_KEYDOWN, key[index.ElementAt(i)], 0);
    }

So is there a way to PostMessage the whole set of numbers not using WM_keydown or if there's a way to use SendMessage but somehow allow the image viewer program to see the change and trigger the contrast event? Any help will be greatly appreciated!

هل كانت مفيدة؟

المحلول

This is mostly out of your hands. It seems like the application in question is only reacting to WM_KEYDOWN events when it calls to update the preview.

You could try to set the text with WM_SETTEXT and then send a WM_KEYDOWN as a sort of no-op (like the arrow right key or something). This is assuming that the code in question is just written as "Wait for a WM_KEYDOWN event and then parse the text of the textbox."

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top