Hi all,
If I have a Windows 32 pointer to and object (Handle) and I know what that
object is (Button) can I some how cast that pointer to a type of
System.Windows. Forms.Button and then use its methods and properties?
I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.
Thanks,
ink 16 2007
ink wrote:
>
Hi all,
If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows. Forms.Button and then use its methods and properties?
I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.
Thanks,
ink
No, sorry, the best you can do in this context is to send messages to
the other control using Win32 api.
--
Lasse Vågsæther Karlsen
mailto:la***@vk arlsen.no
ink wrote:
>
Hi all,
If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows. Forms.Button and then use its methods and properties?
I am using C# compact framework 2.0
I have obtained the handle using the Windows 32 API and PInvoce.
I am using one dot.net application to control another application.
Thanks,
ink
No. You will have to use interop/pinvoke, that is you have to call
Windows API, also things like SendMessage.
ink wrote:
If I have a Windows 32 pointer to and object (Handle) and I know what
that object is (Button) can I some how cast that pointer to a type of
System.Windows. Forms.Button and then use its methods and properties?
Yes.
For example:
Button ButtonFromHandl e(IntPtr handle)
{
return Control.FromHan dle(handle) as Button;
}
This will return a Button instance reference if the handle is valid and
represents a Button control, or null if not.
Pete
Hi Peter
Thanks for the advice. I will defiantly give this a test.
thanks,
ink
"Peter Duniho" <Np*********@Nn OwSlPiAnMk.comw rote in message
news:13******** *****@corp.supe rnews.com...
ink wrote:
>If I have a Windows 32 pointer to and object (Handle) and I know what that object is (Button) can I some how cast that pointer to a type of System.Windows .Forms.Button and then use its methods and properties?
Yes.
For example:
Button ButtonFromHandl e(IntPtr handle)
{
return Control.FromHan dle(handle) as Button;
}
This will return a Button instance reference if the handle is valid and
represents a Button control, or null if not.
Pete
"ink" <in*@notmyemail .comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
I will defiantly give this a test.
That's the spirit! Don't let anyone get in your way... ;-)
--
Mark Rae
ASP.NET MVP http://www.markrae.net
Bollocks..
"Peter Duniho" <Np*********@Nn OwSlPiAnMk.comw rote in message
news:13******** *****@corp.supe rnews.com...
ink wrote:
>If I have a Windows 32 pointer to and object (Handle) and I know what that object is (Button) can I some how cast that pointer to a type of System.Windows .Forms.Button and then use its methods and properties?
Yes.
For example:
Button ButtonFromHandl e(IntPtr handle)
{
return Control.FromHan dle(handle) as Button;
}
This will return a Button instance reference if the handle is valid and
represents a Button control, or null if not.
Pete
Indeed. It's not supported in the CF, and if it were, it still won't turn a
handle from outside your managed app's scope of resources into a Control.
That said, you could still create your own wrapper that takesn in a Handle
and then exports things like Text by wrapping the necessary P/Invoke calls.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World www.OpenNETCF.com
"ink" <in*@notmyemail .comwrote in message
news:eT******** ******@TK2MSFTN GP04.phx.gbl...
>
Bollocks..
"Peter Duniho" <Np*********@Nn OwSlPiAnMk.comw rote in message
news:13******** *****@corp.supe rnews.com...
>ink wrote:
>>If I have a Windows 32 pointer to and object (Handle) and I know what that object is (Button) can I some how cast that pointer to a type of System.Window s.Forms.Button and then use its methods and properties?
Yes.
For example:
Button ButtonFromHandl e(IntPtr handle) { return Control.FromHan dle(handle) as Button; }
This will return a Button instance reference if the handle is valid and represents a Button control, or null if not.
Pete
ink wrote:
>
Bollocks..
I don't know what your problem is. You claimed to have a Button
instance in your original post. If you don't actually have a Button
instance, it's true that FromHandle won't get you an instance, but that
doesn't change the veracity of my answer. It just means you need to
learn to ask better questions (ie, don't make statements that aren't true).
As far as whether it's supported in Compact Framework, well...this isn't
a CF newsgroup. You will need to take responsibility for any specific
difference in your own environment from the more general environment
relevant to the forum in which you ask your question.
I'm sorry that in your specific case my answer wasn't applicable. But I
don't see any need for you to be so rude about it.
Pete
not to butt in a make things worse but,
'microsoft.publ ic.dotnet.frame work.compactfra mework' is actually a .NETCF
newsgroup...
"Peter Duniho" <Np*********@Nn OwSlPiAnMk.comw rote in message
news:13******** *****@corp.supe rnews.com...
ink wrote:
>> Bollocks..
I don't know what your problem is. You claimed to have a Button instance
in your original post. If you don't actually have a Button instance, it's
true that FromHandle won't get you an instance, but that doesn't change
the veracity of my answer. It just means you need to learn to ask better
questions (ie, don't make statements that aren't true).
As far as whether it's supported in Compact Framework, well...this isn't a
CF newsgroup. You will need to take responsibility for any specific
difference in your own environment from the more general environment
relevant to the forum in which you ask your question.
I'm sorry that in your specific case my answer wasn't applicable. But I
don't see any need for you to be so rude about it.
Pete
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jacob Jensen |
last post by:
This question has probably been asked a million time, but here it comes
again. I want to learn the difference between the three type cast operators:
static_cast, reinterpret_cast, dynamic_cast. A good way to do this is by
example. So I will give an example and please tell me what you think:
I have a base
class A
with a virtual destructor, and a
class B
that is it inherits publicly from A and defines som extra stuff.
|
by: Tamir Khason |
last post by:
Is it possible? or just my fantasy?
I did it before with cpp. Handle and change base classes such as dialogs,
windows etc.
Is it possible to do with C#? Someone knows good reference to such kind of
programming?
TNX
--
Tamir Khason
|
by: The Real Andy |
last post by:
Sorry if this question sounds stupid, its early days for me when it
comes to c# and com interop.
I have a method imported from Win Media PLayer SDK,
IWMPPluginUI:DisplayPropertyPage, like so:
void DisplayPropertyPage(IntPtr hwndParent)
I need to pass hwndParent to a dialog, but I cant for the life of me
figure out how to cast it to a windows.forms.form handle.
|
by: Razak |
last post by:
Hi,
I have a class which basically do Impersonation in my web application. From
MS KB sample:-
++++++++++++++++++++code starts
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
|
by: James Juno |
last post by:
Hello,
I want to do something like this:
class A
{
...
};
class B : public A
| |
by: Alexander Schmolck |
last post by:
what's the best approach to write C(++)-extension code that has to create a
python int from a C pointer and vice versa so that it works smoothly on 32 bit
and 64 platforms (on which sizeof(int) != sizeof(*void)) equally work (under
unix,mac&windows and with gcc, vc and borland)?
Currently the relevant code (in mlabraw.cpp available from
<http://mlabwrap.sf.net>) looks like somthing like this:
/* C++ -> py */
Engine *ep;
|
by: S. Lorétan |
last post by:
Hi guys,
Sorry for this stupid question, but I don't know why it isn't working.
Here is my (example) code:
namespace Test {
class A {
public string Label1;
}
|
by: Christopher Pisz |
last post by:
My problem is my derived class is getting called twice instead of the base
and then the derived. I thought this was the purpose for virtuals and
dynamic casting :/
I want my base class to have its method called and then the derived class
have its method called. What am I not understanding?
Int the following code, my Event Tester class is getting called twice for
keyboard events when I step through the debugger:...
|
by: alex.j.k2 |
last post by:
Hello all,
I have "PRECISION" defined in the preprocessor code
and it could be int, float or double, but I do not know in the
code what it is.
Now if I want to assign zero to a "PRECISION" variable,
which of the following lines are correct:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |