Sign in to follow this  

[.net] GetWindowLong Not Working in C#

This topic is 3575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

GentleMen, I am Using Win32api in C# to get the job done I am also Creating Threads in this application Actually it is only one thread Here is the summary:- Main Programm Thread Executes the programm untill it reaches a place in the code where it has to click a buton on the internet explorer page Clicking that Opens a dialogbox ASking wheather i want to save open the file or cancel the dialog box. At this click Programm breaks into two 1) Main Programm Thread 2) Addtional thread i make to proccess dialog boxes I have made extra thread because Downloading and browsing on internet Takes time. so internet stuff is dealt with this thread once it has fetched what i want; it closes internet explorer and Main Application thread Figures out the Information i want and displays it. Brothers proccessing this dialog box and others that will follow it would be done by this extra thread. Now it handles well :- Sort of thing which goes in this thread is like this
ThreadProc()
{
	1) string NameOfTheButtonToClick = "Close" // or anything;

	KeepLooping
	{
		FindtheButtonInTheDialogBox (NameOfTheButtonToClick ); Is fOund
		if Found Exist Loop
	}
}

FindtheButtonInTheDialogBox(NameOfTheButtonToClick)
	{
		 Enums All The Child Windows Of the dialogBox
		 That Internet Explorer Dispalys
   	         FOr that it passes the EnumChildWindowsProc Address To EnumChildWindows Win32APi Function

	}

EnumChildWindowsProc( )
{

		 When it finds the window with the given TExt
 		 Found = true 
		 I make it click it In DIalog Box


}



Once the file has been downloaded from INternet Explorer The programm has to
Display the INformation that i have programmed it to fetch.it does it well

Problem is this
i order to put this FIlename in save dialog box i am using Sendkeys.
ANd you know Sendkeys needs the Place to be in focus That brings the limitation to 
it.that i cant do anything else when it has to happen 

using WM_char with SendMessage has the same problem of focus
Wm_SETTEXT does not work on it while WM_GETTEXT works well
I was thinking if WM_SETTEXT has been disabled or what
in order to do that i wanted to get the wndproc address
and use my wndproc to proccess this dialog box messages

but Getwindowlong is not working and neither setwindowlong

[DllImport("User32", CharSet = CharSet.Auto,SetLastError = true)]
                unsafe public static extern System.IntPtr  GetWindowLong (
                                        System.IntPtr hWnd,
                                        System.Int32 nIndex  
                
                ) ;

i have even tried 
[DllImport("User32", CharSet = CharSet.Ansi, SetLastError = true)]
                unsafe public static extern System.IntPtr GetWindowLongA(
                                        System.IntPtr hWnd,
                                        System.Int32 nIndex

                );




System.IntPtr WinProc1 = 
			GetWindowLongA( HwndDlg , 
			GETWINDOWLONG.GWL_WNDPROC
                        ) ;

What is wrong


Thankyou RIGHT_THEN [Edited by - RIGHT_THEN on March 2, 2008 10:50:48 AM]

Share this post


Link to post
Share on other sites
Hey, place your code between code tags, it's unreadable like this!

I can assure you that SetWindowLong works. Are you running the code on a 32bit or 64bit platform? What I use is:


void DoSomething()
{
// This calls a C# function that determines whether we need SetWindowLong (32bit platforms)
// or SetWindowLongPtr (64bit). This happens because SetWindowLongPtr is a macro on 32bit
// platforms, and is *not* available as a function.
Functions.SetWindowLong(Handle, GetWindowLongOffsets.STYLE, style);
}

static class Functions
{
#region GetWindowLongOffsets enum

internal enum GetWindowLongOffsets : int
{
WNDPROC = (-4),
HINSTANCE = (-6),
HWNDPARENT = (-8),
STYLE = (-16),
EXSTYLE = (-20),
USERDATA = (-21),
ID = (-12),
}

#endregion

using LONG = System.Int32;
using LONG_PTR = System.IntPtr;
using HWND = System.IntPtr;

internal static IntPtr SetWindowLong(IntPtr handle, GetWindowLongOffsets index, IntPtr newValue)
{
if (IntPtr.Size == 4)
return (IntPtr)SetWindowLong(handle, index, (LONG)newValue);

return SetWindowLongPtr(handle, index, newValue);
}

[SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
static extern LONG SetWindowLong(
HWND hWnd,
GetWindowLongOffsets nIndex,
LONG dwNewLong
);

[SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
static extern LONG_PTR SetWindowLongPtr(
HWND hWnd,
GetWindowLongOffsets nIndex,
LONG_PTR dwNewLong
);
}


Share this post


Link to post
Share on other sites
Sir Mr. Fiddler

Thankyou So much for the reply
I came to this Forum surfing net in which
one of the Quetioner gets his answer and
says i posted the same question on some forum
and did not get the reply and here i got with in seconds
was he right or was he right

i have the same situation and i to got reply in seconds

Now
I am using win32 and not win64
i am on windows xp sp2 platform


For me GetwindowLong and SetwindowLong
is not working only for Wndproc
It does get the HINSTANCE thou and few other options
that are relevent

But when it comes to WNDPROC it is returning false or 0
only

Does my explanation in previous post needs eleboration
for you to get the bug


Thankyou
RIGHT_THEN

Share this post


Link to post
Share on other sites
I am not using webbrowser Control Because i didnt know about
That it could do what i have stated above.
Long back when i tried my hand On webbrowser control with vb6
it was a headache.

Do you Mean to say That Webrowser control can take control of the
DialogBoxes and i would have easy access to the dialog box buttons
without resorting to winapi.
because i am not creating these dialog boxes
the sites Make them appear in my window when i click some
of their option.

But the Crux Of all is i am not as smart as most of you gentlemen
Here are with emmence solutions and stratigies for everything

i am just a hobbyist into programming doing home stuff for myself


Thankyou
RIGHT_THEN



Share this post


Link to post
Share on other sites
Most of us are hobbyist programmers working for fun :)

Personally, I've found the .Net WebBrowser control very easy to use - but I haven't tried its more exotic functionality.

Give it a try, it may save you quite a lot of work.

Share this post


Link to post
Share on other sites

This topic is 3575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this