473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

beginners question API


Hello everyone, Ive been trying to get this code to work for very long
now, but I havent been able to catch the problem. Im trying to use the
SendMessage method but when I execute the program nothing happens. Thats
the best response Ive gotten from it so far, other times it mdoesnt
compile. Its a short code, Im trying simply to get SendMessage to click
a button in another specified app when I click my button. Im using c#
express with framework 2.0, the example Ive found for this were all for
older framwork versions and didnt work. Can anyone show me where Im
wrong?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class Win32
{
[DllImport("user32", EntryPoint = "GetNextWindow")]
public static extern int
GetWindow(IntPtr hwnd, int wFlag);
public const int BM_CLICK = 0x00F5;
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClass, string lpWindow);

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int
lParam);
}
private void button1_Click(object sender, EventArgs e)
{
int hWnd;
hWnd = Win32API.FindWindow(Class1.Text, caption.Text);
Win32API.SetForegroundWindow(hWnd);
Win32.SendMessage(hWnd, Win32.BM_CLICK, 0, 0);
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Feb 11 '06 #1
3 1525
[DllImport("user32", EntryPoint = "GetNextWindow")]
public static extern int
GetWindow(IntPtr hwnd, int wFlag);
There's no function called GetNextWindow exported from user32.dll.
GetNextWindow is simply a macro calling GetWindow, so it will probably
work better if you just remove the EntryPoint.

hWnd = Win32API.FindWindow(Class1.Text, caption.Text);
Win32API.SetForegroundWindow(hWnd);
Win32.SendMessage(hWnd, Win32.BM_CLICK, 0, 0);


FindWindow only searches top level windows. Do you really have a
button floating around on the desktop without a parent?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 11 '06 #2
I understand your first point about the GetNextWindow, but about the
second part with FindWindow, that is the only way I knew how to do it.
What can I use instead? Thanks for your help by the way!

*** Sent via Developersdex http://www.developersdex.com ***
Feb 11 '06 #3
>I understand your first point about the GetNextWindow, but about the
second part with FindWindow, that is the only way I knew how to do it.
What can I use instead? Thanks for your help by the way!


If the button is a control in some other window, you first have to
find the top level window with FindWindow, then walk your way down the
control tree with functions like FindWindowEx, GetWindow or
GetDlgItem.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 12 '06 #4

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

Similar topics

7
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional...
4
by: blah | last post by:
I m actually a Novice in Python as well as Linux, When i look up things on the internet about Linux Flavours, They are written so complex that it is difficult for me to understand, i am asking if...
4
by: Eggnog | last post by:
Hi, Is there a newsgroups for beginners questions? Cheers, Nawg
6
by: William Foster | last post by:
Does anyone know of a good online tutorial for C# focused on beginners. I have been to many great sites like csharpfriends, csharp-corner etc looking for good tutorials and have had no luck. Any...
19
by: yltkhuu | last post by:
1. How does having a widely adopted C++ standard help game programmers? 2. What are the advantages ans disadvantages of employing the "using" directive? 3. Why might you define a new name for an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
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
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...
0
tracyyun
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...

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.