Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:55:45+00:00 2026-06-11T13:55:45+00:00

I want to check on this code and see if you can help me

  • 0

I want to check on this code and see if you can help me implement it

if so ,
is there a way to query faster getting only
process that starts with “a” and process starts with “b”

(is it by using the filter parameter )

could it be done via other method with parameters required by

EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)

how can i call EnumDesktopWindows() with another maybe not only using native method – filtering as mentioned … kind’a “helper” method

 private const string USER32 = "user32.dll";

    internal delegate bool EnumDelegate(IntPtr hWnd, int lParam);

    [DllImport(WindowsFunctions.USER32, EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);

    [DllImport(WindowsFunctions.USER32)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool IsWindowVisible(IntPtr hWnd);

    [DllImport(WindowsFunctions.USER32)]
    internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);

    [DllImport(WindowsFunctions.USER32)]
    internal static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpfn, IntPtr lParam);







public class WindowData
{
    public string Title { get; set; }
    public long ProcessId { get; set; }
    public long ThreadId { get; set; }
    public IntPtr HWindow { get; set; }
}


        var collection = new List<WindowData>();

        EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
        {
            StringBuilder strbTitle = new StringBuilder(255);
            int nLength = WindowsFunctions.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
            string strTitle = strbTitle.ToString();

            if (IsWindowVisible(hWnd) && !string.IsNullOrEmpty(strTitle))
            {
                int pid;
                int threadId = WindowsFunctions.GetWindowThreadProcessId(hWnd, out pid);

                collection.Add(new WindowData()
                {
                    Title = strbTitle.ToString(),
                    ProcessId = pid,
                    ThreadId = threadId,
                    HWindow = hWnd
                });
            }

            return true;
        };



        if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
        {
            return collection.ToArray();
        }

        return null;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:55:46+00:00Added an answer on June 11, 2026 at 1:55 pm

    this is what i came up with as temporary solution

    public static class MyProc
        {
            public static IntPtr WoWhWnd;
            public static string WoWProcName;
            public static string WowMainWinTitle;
            public static int WowID;
            public static IntPtr MyApphWnd;
            public static string MyAppProcName;
            public static string MyAppMainWinTitle;
            public static int MyAppID;
        }
    
    
        public void bring(string handletoFront)
        {
            switch (handletoFront)
            {
                default:
    
                    SetForegroundWindow(MyProc.WoWhWnd);
    
                    break;
                case "MyApp":
    
                    SetForegroundWindow(MyProc.MyApphWnd);
                                        break;
            }
    
    
        }
    
    
               #region <<=========== Enumerating Processes   ============>>
    
            void  ShowP1(){
    
                IEnumerable<Process> processes = from p in Process.GetProcesses() where p.ProcessName.StartsWith(TBXSearchWindowTerm.Text) || p.ProcessName.StartsWith("WindowsF") orderby p.ProcessName select p;
                MyProc.MyApphWnd = processes.ElementAt(1).MainWindowHandle;
                MyProc.MyAppMainWinTitle = processes.ElementAt(1).MainWindowTitle;
                MyProc.MyAppID = processes.ElementAt(1).Id;
                MyProc.WoWhWnd = processes.ElementAt(0).MainWindowHandle;
                MyProc.WowMainWinTitle = processes.ElementAt(0).MainWindowTitle;
                MyProc.WowID = processes.ElementAt(0).Id;
                pause(350);
                SetForegroundWindow(MyProc.WoWhWnd);
                pause(850);
                SetForegroundWindow(MyProc.MyApphWnd);
            }
    

    in one of the queryies i have used a text box value so it could be one constant search and a dynamic optional one , if you see somthing that i did wrong or i could do better , please do comment . thank you .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can check for iPhone with this code: (navigator.userAgent.match(/iPhone/i)) But I want to target
i want to get the value of this td my code function check() {
How can i write this correctly ? I want to check how many days
I have an application that passes in java.util.Date. I want to check whether this
Please check this: http://img62.imageshack.us/img62/3598/ieff.png why is it more height than in FF.. i want
I have a form with: Check this if you Want to receive our newsletter:
I want add my custom sidebar next right column all page. Please check this
I came across this problem when I want to check what I input is
This is how I want it to be: Please check to this link and
I have this script that collects data from users and I want to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.