CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    30

    C# FindWondow not recognized

    Hi. I'm having issues with FindWondow not being recognized in the code. I have not programmed in C++/C# for over 20 years, all of my recent programming has been in VBA. I have found code which I cludged together and the only issue is the FindWindow not being recognized even though it is defined correctly. Any input would be very helpful.

    Code:
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Timers;
    
    //public bool bTimerOn = FALSE;
    //public unsigned long ulWait = ullWait;
    
    
    namespace VbaEventEPIQspace
    {
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("EB2637FE-E07F-4071-8472-B531030FD6B7")]
        //[InterfaceType(ComInterfaceType.InterfaceIsDual)]
        public interface _DEventInterface
        {
    
            [DispId(1)]
            void EPIQ_Init(long lWait);
    
            [DispId(2)]
            void EPIQ_StartTimer();
    
            [DispId(3)]
            void EPIQ_StopTimer();
    
            [DispId(4)]
            void EPIQ_SetTimer();
    
            [DispId(5)]
            void EPIQ_ExecuteProc();
    
        }
    
        [ProgId("EPIQ_Utils.Utils")]
        [ComSourceInterfaces(typeof(_DEventInterface))]
        [Guid("9BAED3EE-BB01-4605-9C22-EEAE5BA7141B")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ComVisible(true)]
    
    
    
    
        public class EPIQ_Utils
        {
     //       bool bTimerOn;
     //       long lWait;
            const int BM_CLICK = 0xF5;
            private static Timer timer;
    
            //MessageBox(NULL, (LPCWSTR)"Made it here", (LPCWSTR)"We made it", NULL);
            [DllImport("user32.dll")] 
            public static extern int FindWindow(string lpClassName, String lpWindowName);
    
            [DllImport("user32.dll")]
            public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
    
            [DllImport("user32.dll", CharSet = CharSet.Unicode)]
            static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
    
            [DllImport("user32.dll")]
            private static extern IntPtr SetActiveWindow(IntPtr hwnd);
    
            public EPIQ_Utils()
            {
                timer = new System.Timers.Timer();
                timer.Interval = 1000;
                timer.Elapsed += OnTimerEvent;
                timer.AutoReset = true;
                timer.Enabled = false;
            }
            private void OnTimerEvent(object source, System.Timers.ElapsedEventArgs e) 
            { 
                //create two structures to hold our Main Window handle
                //and the Button's handle
                IntPtr WindowHandle;
                IntPtr ButtonHandle;
    
                //this window's caption is "File Download", so we search for it's handle using the FindWindow API		
                WindowHandle = FindWindow(null, "Message from webpage");
    
                SetActiveWindow(WindowHandle);
    
                //the Button's Caption is "OK" and it is a "Button".  SPYXX.exe that comes with Microsoft Visual Studio will reveal this information to you
                ButtonHandle = FindWindowEx(WindowHandle, IntPtr.Zero, "Button", "OK");
    
                //send a message to the button that you are "clicking" it.  Surprisingly C++ understands what BM_CLICK is without having to set it.  Different than VB
                SendMessage(ButtonHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
    
            }
    
    
    
    
    
    
     //           void EPIQ_InitializeTimer(long ltime)
     //           {
                    
     //           }
    
     //       void EPIQ_SetTimer() 
     //       {
     //           if (bTimerOn)
     //           {
    
     //           }
             
     //      }
    
     //       void EPIQ_ExecuteProc()
     //       {
     //           if (bTimerOn)
     //           {
     //               TimerProc;
     //               EPIQ_SetTimer;
    
     //           }
     //       }
    
     //       void EPIQ_StopTimer()
     //       {
     //           bTimerOn = false;
     //       }
        }
    }
    Last edited by VictorN; March 8th, 2025 at 09:00 AM. Reason: added CODE tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,425

    Re: C# FindWondow not recognized

    Quote Originally Posted by funkmonkey View Post
    I have found code which I cludged together and the only issue is the FindWindow not being recognized even though it is defined correctly.
    What line in your code snippet produces this error message?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured