Click here to Skip to main content
15,885,916 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
findwindow: I said findwindow a find VALORANT window, but even anywhere it triggers events under findwindow, I want it to run only in VALORANT window

What I have tried:

int hwnd = FindWindow("VALORANT", null);
                SetForegroundWindow(hwnd);
                SendKeys.SendWait("+{ENTER}gg{ENTER}");

but work any window
Posted
Updated 17-Aug-21 2:55am
Comments
Maciej Los 17-Aug-21 9:01am    
Do you want to find a window of your apllication? If yes, then you have to loop through the collection of Application.OpenForms Property (System.Windows.Forms) | Microsoft Docs[^]

1 solution

You're not checking the value returned from FindWindow, which could be 0 if the window was not found.

Also, FindWindow returns a handle, which needs to be declared as IntPtr, not int. So I suspect your P/Invoke declarations are wrong.
 
Share this answer
 
Comments
Maciej Los 17-Aug-21 8:58am    
5ed!
Muhammed Yeter 17-Aug-21 9:09am    
yes not find the window , but window already open , why not find window?? (sry, i not know winform and fnidwindow)
Richard Deeming 17-Aug-21 9:11am    
As I said, your P/Invoke declarations are wrong.

Beyond that, we have no way of telling. Are you sure the window class name is "VALORANT", and you're not looking for the window title instead?
Muhammed Yeter 17-Aug-21 9:20am    
yes i want find the window title "VALORANT", but not find i test this, meessagebox.show(hwnd.tostring()); and messagebox says 0 :(
Richard Deeming 17-Aug-21 9:23am    
Well there's your problem then!

The first parameter to FindWindow is the class name. If you want to find the window by title, swap the parameters around:
IntPtr hwnd = FindWindow(null, "VALORANT");

FindWindowA function (winuser.h) - Win32 apps | Microsoft Docs[^]

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