473,473 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using Windows API in VB.Net?

I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?

Nov 20 '05 #1
9 7037
You can definitely using the Win32 API in .NET, to perform many tasks you
have to. The framework is still work in process, and there are zillions of
Win32 API's that aren't supported yet.

Is it a no-no? No, not at all. In fact, much of the Framework is merely
API calls wrapped for managed code.

Not sure exactly what you mean by Treated by in the third one...but what are
you trying to do? Just sendmessagetoDescendants or something else?
"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?

Nov 20 '05 #2
VB6 had that Win API function prototype utility, does VS.Net have one? How
do I find the correct prototype to use for my Win32 API function?

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:#p**************@tk2msftngp13.phx.gbl...
You can definitely using the Win32 API in .NET, to perform many tasks you
have to. The framework is still work in process, and there are zillions of Win32 API's that aren't supported yet.

Is it a no-no? No, not at all. In fact, much of the Framework is merely
API calls wrapped for managed code.

Not sure exactly what you mean by Treated by in the third one...but what are you trying to do? Just sendmessagetoDescendants or something else?
"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?


Nov 20 '05 #3
Martin,
1) Can one use Win32 API functions in VB.Net Yes, However I would recommend you make sure you really need to & more
importantly want to. I've seen a number of people decide they need to use
API x, although API x is already part of the framework as feature y, they
use API x instead of feature y. In other words use the Framework if its part
of the Framework. Which means you need to learn the Framework ;-)
2) Is doing so a "no no" Normally I try to isolate any Win32 API functions to a single module/class,
think Encapsulation. And to a lesser extent Isolation.
3) are VB.Net windows, underneath the covers, Win32 windows? Yes,
and can be treated as such? Most of the time, Yes! In fact System.Windows.Forms.Control has a Handle
property which is the Win32 HWND.
I want to use the Win32 API function : SendMessageToDescendants
The problem is SendMessageToDescendants is NOT a Win32 API!!

It is a MFC/ATL API (C++ function), you cannot directly call MFC or ATL
functions. The SendMessageToDescendants function uses the GetTopWindow Win32
API followed by the GetNextWindow Win32 API.

Rather then mess with attempting to call a MFC functions, I would find the
Framework method of doing it. The Control.Controls collection represents all
of the controls on the Form or contained Control. While Form.OwnedForms
represents all the owned forms and Form.MdiChildren represent all the owned
MDI Children.

I would enumerate (For Each) one of these collections and 'send the message'
to each of these, using recursion if needed. Where 'send the message' is
probably a member of an interface that each child implements or a member of
a base class that each child inherits from. Which means I am actually
calling a routine on the object! On rare exceptional cases it would be the
SendMessage Win32 API. Note in order to receive a message sent with
SendMessage you normally override the Control.WndProc sub routine.

Remember .NET is all about OOP. ;-)

Hope this helps
Jay

"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl... I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?

Nov 20 '05 #4
Hi Martin, one of the main goals of Dotnet is to provide "platform
independence", but by using Windows API, you are directly impacting upon
your program's portability. It is NOT a good practice to use Windows APIs
unless it is ABSOLUTELY necessary !!

In your case, I would advise you to follow Jay's approach of using
For...Each but instead of using SendMessage see if you can make use of any
Property or Method of the control.

"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?

Nov 20 '05 #5
* "Martin Ortiz" <ma*********@optonline.com> scripsit:
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
Yes.
2) Is doing so a "no no"
No, you can use them, no problem.
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?


They are Win32 windows.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Hi all,

You are right - what have been said in the replies is absolutely valid only
until we are talking about the Windows platform. I realize there are no
official .Net releases for other platforms - and they might even never
appear (Mono and dotGNU are amateur projects in no way related to
Microsoft), but if the original poster believes his application has good
chances to be ported - I would at least encapsulate the platform-dependent
stuff as jay Harlow have suggested.

P.S. Putting all flavours of Unix/Linux/FreeBSD aside, one could probably
imagine old-fashion APIs going away in some future Windows release.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Nice Chap" <Ni******@PlasmaDyne.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Martin, one of the main goals of Dotnet is to provide "platform
independence", but by using Windows API, you are directly impacting upon
your program's portability. It is NOT a good practice to use Windows APIs
unless it is ABSOLUTELY necessary !!

In your case, I would advise you to follow Jay's approach of using
For...Each but instead of using SendMessage see if you can make use of any
Property or Method of the control.

"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?



Nov 20 '05 #7
Cor
Hi Martin,
VB6 had that Win API function prototype utility, does VS.Net have one? How
do I find the correct prototype to use for my Win32 API function?


You could not beter shown that Jay B is right in what he wrote than with
this answer.

While I look at the times, I understand that you had, when you wrote this,
not yet read that.

Cor
Nov 20 '05 #8
I come from a MFC background....and at time of post didn't check how the
SendMessageToDescendants was actually implemented....
I will use the approach you suggested instead, which sounds better, rather
than using a Win32 API function
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
Martin,
1) Can one use Win32 API functions in VB.Net Yes, However I would recommend you make sure you really need to & more
importantly want to. I've seen a number of people decide they need to use
API x, although API x is already part of the framework as feature y, they
use API x instead of feature y. In other words use the Framework if its

part of the Framework. Which means you need to learn the Framework ;-)
2) Is doing so a "no no" Normally I try to isolate any Win32 API functions to a single

module/class, think Encapsulation. And to a lesser extent Isolation.
3) are VB.Net windows, underneath the covers, Win32 windows? Yes,
and can be treated as such?

Most of the time, Yes! In fact System.Windows.Forms.Control has a Handle
property which is the Win32 HWND.
I want to use the Win32 API function : SendMessageToDescendants


The problem is SendMessageToDescendants is NOT a Win32 API!!

It is a MFC/ATL API (C++ function), you cannot directly call MFC or ATL
functions. The SendMessageToDescendants function uses the GetTopWindow

Win32 API followed by the GetNextWindow Win32 API.

Rather then mess with attempting to call a MFC functions, I would find the
Framework method of doing it. The Control.Controls collection represents all of the controls on the Form or contained Control. While Form.OwnedForms
represents all the owned forms and Form.MdiChildren represent all the owned MDI Children.

I would enumerate (For Each) one of these collections and 'send the message' to each of these, using recursion if needed. Where 'send the message' is
probably a member of an interface that each child implements or a member of a base class that each child inherits from. Which means I am actually
calling a routine on the object! On rare exceptional cases it would be the
SendMessage Win32 API. Note in order to receive a message sent with
SendMessage you normally override the Control.WndProc sub routine.

Remember .NET is all about OOP. ;-)

Hope this helps
Jay

"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?


Nov 20 '05 #9
Just a little background info on a general problem I'm trying to find a
solution for....(and why SendMessageToDescendants was being looked at)

(in VC 6 and VB6)
On a previous program, I had written an ATL control, this was used in VB
control in VB6, which in turn was part of a composite control, which in turn
was finally on a form.
The recommend to inform the parent of whatever activity was to bubble events
up....
i.e. my ATL control would generate an event, it's host would re-generate the
same event, on and upward.....sounds hunky dory right?
THEN when I had to issue "orders" from the top down, I would do the same in
reverse (but not using events of course), my main form would call a method
on a control, which would in turn call a method on its embedded control,
etc...till it got "bubbled down" to the appropriate call.

All in all, sounds good in theory, but in practice it becomes a maintenance
nightmare, especially when you're changing things around.

In VB.Net an elegant solution to the first issue (bubbling events up), is
easily solved by having on initial event bubbled upward (just once during
init phase), this initial event will contain what ever necessary info that
whom ever is listening can hook into with the AddHandler function, and it's
a loosely coupled arrangement, making maintenance nice and easy

So instead of
Control--- (bubbling event)--->HostControl---(bubbling
event)--->CompositeControl--->--- (bubbling event)--->Form

we get
Control---->Form

(making maintenance a breeze)

The next problem is doing this in reverse, using something similar to
SendMessageToDescendants (an MFC based function)

"Nice Chap" <Ni******@PlasmaDyne.com> wrote in message
news:#K**************@TK2MSFTNGP10.phx.gbl...
Hi Martin, one of the main goals of Dotnet is to provide "platform
independence", but by using Windows API, you are directly impacting upon
your program's portability. It is NOT a good practice to use Windows APIs
unless it is ABSOLUTELY necessary !!

In your case, I would advise you to follow Jay's approach of using
For...Each but instead of using SendMessage see if you can make use of any
Property or Method of the control.

"Martin Ortiz" <ma*********@optonline.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
I want to use the Win32 API function : SendMessageToDescendants

I want to use it in a VB.Net app, but I have a few questions.....

1) Can one use Win32 API functions in VB.Net
2) Is doing so a "no no"
3) are VB.Net windows, underneath the covers, Win32 windows? and can be
treated as such?


Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with...
5
by: Dave | last post by:
I tried posting this in the WinForm forum and got no hits so I am trying it here. After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
0
by: Marco Segurini | last post by:
Hi, I am trying to dynamically install/deinstall a message handler to a System.Windows.Forms.Form using NativeWindow. I do not use IMessageFilter derived class because it intercept only the...
2
by: Hrcko | last post by:
How to use this control? I have to grids on my form, one on the top and one on bottom. When I start application I want to be able to move bottom grip up, and top grid down, but it doesn't...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
3
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and...
0
by: Sister Ray | last post by:
I'm trying to create a simple form that sends an email using my company's exchange server. I'm using the System.Net.Mail Namespace of the .net framework 2.0. I've googled everywhere and i think my...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.