|
If FindWindows returns 0 it couldn't find it....
/\ |_ E X E GG
|
|
|
|
|
This code is soo horibile, but it works. I'm not sure if you got it to work, but this does.... I keep spacing out when I was reading, oh well good practice for me...
public const int WM_SETTEXT = 0x000C;
[DllImport("user32.dll")]
static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
static extern int SendMessage(int hWnd, int Msg, int wParam, string lParam);
int ParenthWnd;
int hWnd;
private void button1_Click(object sender, System.EventArgs e)
{
string lpszParentClass = "Notepad";
string lpszParentWindow = "Untitled - Notepad";
string lpszClass = "Edit";
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
if (ParenthWnd==0)
Console.WriteLine("Notepad Not Running");
else
{
hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");
if (hWnd.Equals(IntPtr.Zero))
Console.WriteLine("What the F??? Notepad doesn't have an edit component ?");
else
{
MessageBox.Show("Notepad Window: " + ParenthWnd.ToString());
MessageBox.Show("Edit Control: " + hWnd.ToString());
string hi="hello";
SendMessage(hWnd, WM_SETTEXT, hi.Length, hi);
}
}
}
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote:
hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");
This is what I was trying to figure out and thanks. Just trying to learn this stuff. I know I crazy questions just I lack the experience that others on here have but one day I'll be able to to run with the big dogs. But by the then they will have newer toys haha. Will I ever win
Thanks again.
tony
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Here's a better explinaion of the method...
The FindWindowEx function retrieves the handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the given child window.
If the function succeeds, the return value is the handle to the window that has the specified class and window names.
PARAMETERS
· hwndParent
Identifies the parent window whose child windows are to be searched.
If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.
· hwndChildAfter
Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.
· lpszClass
Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero.
· lpszWindow
Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.
I don't know how much sense that makes to you but.... I dont' really know either.
/\ |_ E X E GG
|
|
|
|
|
You need to P/Invoke FindWindowEx in order to specify the parent from which searching begins.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah, thanks I figured it out after i posted. I go duh wait a minute he said FindWindowEx in his post as well so I did like a good little newbie and looked it up. Then eggie posted and my code is almost identical so I'm on the right track just headed the wrong way
Anway, as always thanks again. If you are a father enjoy fathers day. If your not hope you enjoy with your father.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
I think WM_GETTEXT only returns the length of the text. Uh, is this what you meant?
Nevermind, it's just really complicated...
/\ |_ E X E GG
|
|
|
|
|
Well, you are right it is complicated. However, i just take one step and time and when I figure it out and understand it I can look back laugh and go man i made this harder than it really was and wow this stuff is cool I don't know I just always wanted to know how programs controlled other programs because i remember long time back in 95 I would use I think it was macro recorder or something like that would generate task for me. Now with the help of you and others, I see where I can do this automation but in a better way. Like I use this program called Total Recorder don't know have heard of it but it lets you record streaming audio. Anway, there is a radio show that comes on called Art Bell (Coast to Coast) and most of the time I'm a sleep so I have to get up and turn the recorder on then go back to bed. Now all I will have to do is find the message handlers and pass them the wm_control command and few other things and it will do all this automatically for me by simply setting a timer in the program. And I can get one of those timers that turn the electricity on and off to my stereo. Ha sorry for the ramble just see this as fun.
Thanks again.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Hey, I have a working sample of reading some text using the SendMessage and WM_GETTEXT . Check it out...
Add this to your class...
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
[Out] StringBuilder lParam);
This was just on a a form with one button and a text box for the handle, here is the button click code. All it does is take the hex handler spy++ gives you and converts it to dec for the method. It removes the extea '0's at the beginning also.
private void button1_Click(object sender, System.EventArgs e)
{
char [] arr = {'0'};
string handle=this.textBox1.Text;
handle=this.textBox1.Text.TrimStart(arr);
IntPtr hWnd = new IntPtr(Convert.ToInt32(handle, 16));
MessageBox.Show(GetWindowText(hWnd));
}
Here is the method, pretty simple...
public static String GetWindowText(IntPtr hWnd)
{
IntPtr txtLength;
IntPtr retValue;
IntPtr zeroVal = new IntPtr(0);
retValue = SendMessage(hWnd,WM_GETTEXTLENGTH,zeroVal,zeroVal);
txtLength = retValue;
StringBuilder sb = new StringBuilder(txtLength.ToInt32() + 2);
retValue = SendMessage(hWnd, WM_GETTEXT, txtLength, sb);
return sb.ToString();
}
Just start spy++ and click file then find window, and then drag that little cross hair thingy over something... like ie's address bar. Then spy++ gives you the hex handle. Just paste that into the text box on the fort and the message box will show the text...
Do you know about pinvoke.net[^]? That site helped me alot alot.
/\ |_ E X E GG
|
|
|
|
|
I was looking at your code and not really understanding this part. Why are you using zeroVal when its a IntPtr instead of a StringBuilder? It gives an error in the compiler as well.
c:\test\notepad writer\Form1.cs(183): Argument '4': cannot convert from 'System.IntPtr' to 'System.Text.StringBuilder'
it is in reference to:
Thanks again.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
That will do it. Thanks to pinvoke.net.
public static String GetWindowText(IntPtr hWnd)
{
IntPtr txtLength;
IntPtr retValue;
IntPtr zeroVal = new IntPtr(0);
retValue = SendMessage(hWnd,WM_GETTEXTLENGTH,zeroVal,zeroVal);
txtLength = retValue;
StringBuilder sb = new StringBuilder(txtLength.ToInt32() + 2);
retValue = SendMessage(hWnd, WM_GETTEXT, txtLength, sb);
return sb.ToString();
}
/\ |_ E X E GG
|
|
|
|
|
How doo you do that? Have you add Serializable attribute to your class?
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
I have a component that contain a collection of a struct.
I drag and drop this component on a form. than i chang it collection, i want when i close form at design time, my collection content save automatically with form(into form's code or resource).
I use this attribute :"[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]".
but this attribute can save only simle data type such "int" or "string" or ...
and not work for collection of a struct or class. my collection code is here :
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Data ;
namespace DesignerSerializationVisibilityTest
{
// The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility
// attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized.
// The public, not hidden properties of the object that are set at design time will be persisted in the initialization code
// for the class object. Content persistence will not work for structs without a custom TypeConverter.
public class ContentSerializationExampleControl : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
int _x ;
public int X
{
get{return _x;}
set{_x=value;}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DimensionData Dimensions
{
get
{
return new DimensionData(this);
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FieldClollectionClass ss
{
get
{
FieldClollectionClass dd=new FieldClollectionClass() ;
FieldColumn fc=new FieldColumn() ;
fc.DisplayName="AAAAAAAAAAA" ;
fc.FieldName="BBBBBBBBBBBBBB" ;
dd.Add(fc) ;
return dd ;
}
}
#region FiledColumnClass
public class FieldColumn
{
private string m_fieldName ;
[ReadOnly(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string FieldName
{
set
{
m_fieldName=value ;
}
get
{
return m_fieldName ;
}
}
public void SetFieldName(string f)
{
m_fieldName=f ;
}
private string m_displayName ;
public string DisplayName
{
get
{
return m_displayName ;
}
set
{
m_displayName=value ;
}
}
private DataTable m_columnDataTable ;
public DataTable ColumnDataTable
{
get
{
return m_columnDataTable ;
}
set
{
m_columnDataTable=value ;
}
}
private bool m_isKey ;
public bool IsKey
{
get
{
return m_isKey ;
}
set
{
m_isKey=value ;
}
}
private string m_childTableValue ;
//[DefaultValue("code")]
public string ChildTableValue
{
get
{
return m_childTableValue ;
}
set
{
m_childTableValue=value ;
}
}
private string m_childTableName ;
//[DefaultValue("name")]
public string ChildTableName
{
get
{
return m_childTableName ;
}
set
{
m_childTableName=value ;
}
}
private int m_width ;
public int Width
{
get
{
return m_width ;
}
set
{
m_width=value ;
}
}
private bool m_visible ;
//[DefaultValue(true)]
public bool Visible
{
get
{
return m_visible ;
}
set
{
m_visible=value ;
}
}
}
#endregion
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class FieldClollectionClass : CollectionBase
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FieldColumn this[int index]
{
get
{
return( (FieldColumn) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( FieldColumn value )
{
return( List.Add( value ) );
}
public int IndexOf( FieldColumn value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, FieldColumn value )
{
List.Insert( index, value );
}
public void Remove( FieldColumn value )
{
List.Remove( value );
}
public bool Contains( FieldColumn value )
{
// If value is not of type FieldColumn, this will return false.
return( List.Contains( value ) );
}
}
public ContentSerializationExampleControl()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
}
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
// This attribute indicates that the public properties of this object should be listed in the property grid.
public class DimensionData
{
private Control owner;
// This class reads and writes the Location and Size properties from the Control which it is initialized to.
internal DimensionData(Control owner)
{
this.owner = owner;
}
public Point Location
{
get
{
return owner.Location;
}
set
{
owner.Location = value;
}
}
public Size FormSize
{
get
{
return owner.Size;
}
set
{
owner.Size = value;
}
}
}
}
|
|
|
|
|
Brand new to C# here, so thanks for bearing with me. What I want to do is probably really easy, but I sure 'nuff can't find the answer on my own.
I have an aspx page with some C# code-behind and a simple button control. I want the click event on that button to launch a new aspx page sized to about 600 x 600. Just a popup window. I've tried Response.Redirect and Server.Transfer, but neither one of them seems to do what I need. A different form in the same project uses a hyperlink formatted as follows: javascript:var w=window.open('pforms/forgotpassword.aspx','test', 'width=350,height=200,scrollbars=no,resizable=yes'). I want to do basically the same thing as that hyperlink, but in C# as a button click event. Can't use a hyperlink on my aspx page for several reasons, but mainly because the event is also running some C# code. Help? Thanks!
Joel
|
|
|
|
|
The most important thing to realize is that ASP.NET is all server-side code (with the help of a couple javascript files to help with form validation). Popping up a window is completely client-side. The server can't tell the client to open a window or direct the browser to a new window - all it can do is generate and send content.
So, the server click event needs to use Page.RegisterClientScriptBlock or Page.RegisterStartupScript to register a fragment of javascript that will do this.
It's not that hard to do at all, but if you want more help, ask in the ASP.NET forum where this question should've been posted originally.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Awesome, dude. Thanks!
Joel
|
|
|
|
|
I am trying to find a specific record in the results of an SQL statement. Bascially, in non-technical terms, a query or filter on the result of a query (let's not get hung up on semantics). The data on that record is then going to be passed on to another query, but unless it has a bearing on the solution or you are interested, I won't go on about the specifics.
Thanks much....
ab
|
|
|
|
|
aberger56 wrote:
I won't go on about the specifics
With that it's rather vague, so here is a question: Are you using a stored procedure? More details on your situation will help those in the forums help answer your question.
- Nick Parker My Blog | My Articles
|
|
|
|
|
OK, here goes...
We are tying to implement a table-driven locate system to our application. Some forms (calling forms) will have a locate button on them. If they have the button, there will be records on table app_locates for that form.
app_Locates has 4 fields:
al_FormName, which holds the name of the calling form
al_FieldName, which holds the internal name of the field on which the locate can be done
al_ExternalFieldName, which is what the user will see
al_FileName, the table on which the field lives.
When the locate button on the calling form is clicked, the name of the calling form is passed to the LDB, which queries app_locates for the records which have al_FormName = the calling form's name. So, if we are on the orders form, we may get 3 records returned from app_Locates.
On the LDB, we create a radio button for each of the records returned from the query, in this case 3 radio buttons. The text that goes along with the button is the al_ExternameFieldName, so that the user sees "Customer" and not "ord_Cust", "Order Num" and not ord_OrdNum. Also on the LDB is a text box, an OK button, and a Cancel button.
So, the user clicks the Customer radio button, enters Smith in the text box, and we query the appropriate table for the information. This is where the question comes in...
let's say app_locates has 5 records:
al_FormName al_FieldName al_ExternalFieldName al_filename
icode ic_Cust Customer iCode
ordmaint om_Cust Customer orders
ordmaint om_Date Order Date orders
ordmaint om_Zip Zip Code cust
shipping sm_Cust Customer shipping
Being as the Calling Form is ordmaint, the middle 3 records are returned. The form shows with 3 radio buttons, with the External Field Name shown as the associated text.
In theory, when the user picks a radio button and enters some text in the text box, we have the info we need to find the appropriate record on the al_filename so that we can put the correct info on the calling form. The query would be:
"select * from " + app_locates.al_filename + " where " + app_locates.al_FieldName + " = " + ldb.textbox.text
The problem is, how do I find the correct record out of the 3 returned from the first query (against app_locates) to populate the second query.
I hope this makes some degree of sense. The end result is that we can add a locate field to a form simply by adding a record to app_locates.
Thanks for the help....
aberger
|
|
|
|
|
Hi
Well like you know, the developers most bring to the reallity the dreams of the boss. Now I'm tryin' to get insane with MapXtreme 2004, this is easy to show a map and ... nothing more I can't do. I wanna display the data table into a datagrid, but I can't. Someone here had used this software?? I try with the developers guide, but It's hard for me, I get confused with the namespace MapInfo.Data .
So any help, thanks.
----
hxxbin
|
|
|
|
|
You best shot for support like that, is the company that developed the library. Considering there are thousands of libraries, controls, and whatnot out there, it's very unlikely anyone has used the product.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
In the code below I load an image into a PictureBox using the Image.FromFile method. When I am done with that image I would like to release it so that I can delete it from the hard drive. However, even after I set the PictureBox's Image property to another image I still can not delete it. Obviously my process still has a handle to the file but I can't find a way to release that handle. I tried looking through the methods and properties of pictureBox1.Image but I did not see anything that looked useful. Any ideas?
------------------
pictureBox1.Image= Image.FromFile(MyFile);
pictureBox1.Image = Image.FromFile(AnotherFile);
System.IO.File.Delete(MyFile); //This fails becuase MyFile is "in use by another process"
|
|
|
|
|
Got it. Thanks.
------------------
pictureBox1.Image= Image.FromFile(MyFile);
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(AnotherFile);
System.IO.File.Delete(MyFile);
|
|
|
|
|
i was just about to say, Dispose the Image. When you Dispose an object, it releases any unmanaged resources it has open, including file handles.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I would like to catch an exception and then exit the method. There is a lot of code after the catch test and I was wanting to exit at that point rather without running through the rest of the code. Is there an 'exit' for a method? I have looked but cannot find anything.
Thanks in advance.
Stephen
|
|
|
|
|