|
So I'm making an application that alters another Windows program. I want to do it buy synthesizing mouseclicks. I have that aspect working, what I need to do now is determine the location. I'm using GetWindowLocation, However the values it returns are kind of absurd. SO I'll post my code(stolen mostly from another post) and if anyone can figure out where I went wrong...
<br />
[DllImport("user32.dll")]<br />
private static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement placement);<br />
public struct WindowPlacement{<br />
public uint length;<br />
public uint flags;<br />
public uint showCmd;<br />
public POINT ptMinPosition;<br />
public POINT ptMaxPosition;<br />
public RECT rcNormalPosition;<br />
}<br />
public struct POINT{<br />
public long x;<br />
public long y;<br />
}<br />
public struct RECT{<br />
public long left;<br />
public long top;<br />
public long right;<br />
public long buttom;<br />
}
That's my structure definitions.
I call it like this
<br />
WindowPlacement Place;<br />
GetWindowPlacement(Handle, ref Place);<br />
Ok so there it is, the values return seem pretty absurd. Negative numbers 15 digits long and such, nothing I can make a mousepointer move to without errors. Anyhelp would be great.
jake
|
|
|
|
|
In C++, a long and an int are both the same size. Change the longs to ints in POINT and RECT, and the rcNormalPosition will become valid and accurate, I've just tested it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hi
how i can make a stand alone c# windows application?
thanks
|
|
|
|
|
select the project type Windows Application in Visual Studio?
The only thing you need is the .NET framework
|
|
|
|
|
Hey guys;
I want to know how can I syntax colorize a textbox. Like puting a little squiggly MSword underline under a text or letter.
Any ideas please write.
Thanks
|
|
|
|
|
Two words - owner draw. You have to handle drawing something like that yourself, the textbox does not support it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Please search a bit yourself before posting. Searching for 'syntax textbox' here on CodeProject gives you an article which is no two days old.
|
|
|
|
|
I think in a textbox you cant do that.
A RichTextBox much better basic for it.
I think you can start if you read the RichTextBoxExtended in docs.
But I remember somwhere I find a code shomething like yorur wish, if I find it, post it to you.
|
|
|
|
|
Does anyone have any references on how to find out the mail settings on a PC using C# ? The program I'm working on needs to send emails and I'm hoping that I can get the mail server details and reply address from outlook withouth the user having to enter them.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christain,
Can we look up the info in the windows registry? For example, in the key:
HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\
or somewhere in the user profiles
|
|
|
|
|
Outlook is not set up on this PC, so I can't check, but I'll look into that tomorrow. A registry solution would suit me, I'm worried about trying to connect to different versions of outlook.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I need an application that keeps record of process starts and closes in several computers, more exactly, a windows service. This is for monitoring computer use at my university and make statistics on who uses more what programme and whatnot.
I'm not sure how to do it, but I'm guessing it's with WMI, maybe an event triggered? I don't know for sure.
I only need to know when a process was started/killed/closed and what process it was, I can do the other features (not listed here) myself.
If someone can just give me a hint or anything it'd be great
Thank you very much
|
|
|
|
|
|
Still can't find anything related to the user-triggered start of a process, sure that says how my service can start a process, but not how to actually know when the user has opened, say, Visual Studio.
|
|
|
|
|
I don't know if you can write a system wide hook on every time a process is started. If I was going to do that, I'd do it in C++. However, failing that, there is a Processes property which returns all the processes on the PC - GetProcesses. I'd have hoped the link I gave you ( which is about creating diagnostic programs like what you're writing ) would offer a better method, but failing that, you can always poll running processes regularly, and work out which processes get started and stopped.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
In VS 6.0 there was a control for IP addresses. Is there not one in C#? Also how do I move the text of a group box over to the right with out it effecting anything inside of it. I'm not grouping anything together just using it to tell the end user what this section of controls are.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
There isn't one built into the framework in .NET 1.x. However, it's quite easy to implement, several people already have done this, for example, this CP article[^].
Also, there is a masked text box built into .NET 2.0 that allows you to do things like IP addresses, phone numbers, zip codes, etc.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
Hi all,
I create a Web Service project called 'eSelectService' and another Class Library project called 'MonerisVO', and a Windows Form project called 'maps' as well.
The reason why I need the Class Library project is because I don't want to have more than 30 parameters when I try to invoke the Web Method. I used the class in Class Library as a value object to contain all the information I need.
Here is the problem:
When I debug the Web Service project, I add the Class Library project's output (Trans.dll) as a reference. Everything works fine.
But when I want to invoke the Web Service via my Windows Form project the compiler says "cannot convert the MonerisVO.ValueObject from eSelectService.ValueObject." So I remove the Trans.dll from the Windows Form project's references. But the new problem is I cannot see the methods in Trans.dll, even the overloaded constructor.
My guess is maybe I get some configuration options wrong.
Is there anybody has the same problem like me? Or is there any good ideas?
Please help me out.
Thanks a lot.
Grace
|
|
|
|
|
Hi all,
Here is the source code:
//Web Services
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using MonerisVO;
namespace eSelectService
{
public class GateWay : System.Web.Services.WebService
{
public GateWay()
{
InitializeComponent();
}
[WebMethod]
public string test(string host, Trans tr)
{
//Can invoke the method here in the Web Services.
return "host=" + host
+ ", order_id=" + tr.OrderID
+ ", amount=" + tr.TotalAmount;
}
}
}
//Web Forms
using eSelectService;
...
private void btStart_Click(object sender, System.EventArgs e)
{
eSelectService.GateWay gt = new eSelectService.GateWay();
eSelectService.Trans = new eSelectService.Trans();
trans.Init("order_id_test", "4.01");
MessageBox.Show(" result=" + gt.process);
}
//Class Library: Trans.class
...
public class Trans
{
private string order_id;
private string amt;
public TransactionVO(){}
public string OrderID
{
get
{
return order_id;
}
set
{
order_id = OrderID;
}
}
public string TotalAmount
{
get
{
return amt;
}
set
{
amt = OrderID;
}
}
public Init(string id, string amt)
{
this.orderID = id;
this.TotalAmount = amt;
}
}
|
|
|
|
|
|
Hello
I am filling a dataset from a single SQL table, containing some fields of datetime type. I then proceed reading each row in the dataset and attempting to pass the values of each record in a class, populating its fields. When I try to pass the datetime field into a class field of System.DateTime type, I try to also convert it to ToShortTime() format. This fails to compile, telling me that the datarow element is of type "object" and does not contain a definition for ToShortTime(). When I break execution just before the exception (after changing my syntax to ToString() and the type of the class field to string which compiles OK), I use the Immediate window to view the type of my datarow element and is shown to be ValueType: {System.DateTime}.
I am confused....any help please?
Regards
Chris
|
|
|
|
|
Although the field might contain a DateTime the compiler doesn't know that this column is filled with DateTime instances. And even if he knew there could still be some rows where this field is empty. In that case the value would be DbNull.
This means you just have to cast the object value you get to tell the compiler explicitely what he not able to determine. You could do something like this:
if (dataRow[fieldIndex] == DbNull.Value) {
//field is empty - do wahtever you think has to be done
} else {
DateTime date = (DateTime)dataRow[fieldIndex];
string timeAsShortString = date.ToShortTime();
}
|
|
|
|
|
This worked. Thank you very much.
It appears that the compiler does not realize (or auto-cast) dataset column element types read directly from the table.
Once again thanks a lot.
Chris
|
|
|
|
|
I have to generate printable reports from an Access database (Crystal Reports is not an option). Using automation, I can show an Access report, but that leaves my Access database open -- not sure I should trust my user(s) that much.
I'm not stuck to the idea of using an Access report, I just want to be able to easily create 6-10 reports that can be printed (displayed before printing would be nice, but not required).
Any pointers would be helpful.
Thanks,
Glenn
--
glenn_lanier@netzero.net
|
|
|
|
|
Hope this helps. You may need to change it a bit to meet your needs such as the Access version, but here are 2 routines that 1 prints directly and the other does a preview.
The reports are created in access then these call upon those report names.
Also it's in vb.net !sorry! but I also read/write C# and thought that this might be helpful to you.
Private Sub Print_Report(ByVal _report As String)
'Prints the "Routing Report" in ticketaccess.mdb.
' Enable an error handler for this procedure:
On Error GoTo ErrorHandler
'Dim oAccess As Access.Application
'path to ticketaccess.mdb file
Dim cfg As ConfigInfo = GetConfig
Dim sDBPath As String = cfg.databasepath
Dim sReport As String = _report 'name of report to print"
' Start a new instance of Access for automation:
'oAccess = New Access.Application()
Dim oAccess = CreateObject("Access.application.8")
' Determine the path to ticketaccess.mdb:
'sDBPath = oAccess.SysCmd(Action:=Access.AcSysCmdAction.acSysCmdAccessDir)
'sDBPath = sDBPath & "ticketaccess.mdb"
' Open ticketaccess.mdb in shared mode:
oAccess.OpenCurrentDatabase(filepath:=sDBPath, Exclusive:=False)
' Select the report name in the database window and give focus
' to the database window:
oAccess.DoCmd.SelectObject(ObjectType:=Access.AcObjectType.acReport, _
ObjectName:=sReport, InDatabaseWindow:=True)
' Print the report:
oAccess.DoCmd.OpenReport(ReportName:=sReport, _
View:=Access.AcView.acViewNormal)
Cleanup:
' Quit Access and release object:
On Error Resume Next
oAccess.Quit(Option:=Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess = Nothing
Exit Sub
ErrorHandler:
MsgBox(Err.Number & ": " & Err.Description, _
MsgBoxStyle.MsgBoxSetForeground, "Error Handler")
' Try to quit Access due to an unexpected error:
Resume Cleanup
End Sub 'Uses report in access db
Private Sub Preview_Report(ByVal _report As String)
'Previews the "Summary of Sales by Year" report in ticketaccess.mdb.
' Enable an error handler for this procedure:
On Error GoTo ErrorHandler
'Dim oAccess As Access.Application
Dim oForm As Access.Form
'path to ticketaccess.mdb file
Dim cfg As ConfigInfo = GetConfig
Dim sDBPath As String = cfg.databasepath
Dim sReport As String = _report 'name of report to preview
' Start a new instance of Access for automation:
'oAccess = New Access.ApplicationClass()
Dim oAccess = CreateObject("Access.Application.8")
' Make sure Access is visible:
If Not oAccess.Visible Then oAccess.Visible = True
' Determine the path to ticketaccess.mdb:
'sDBPath = oAccess.SysCmd(Action:=Access.AcSysCmdAction.acSysCmdAccessDir)
'sDBPath = sDBPath & "ticketAccess.mdb"
' Open ticketaccess.mdb in shared mode:
oAccess.OpenCurrentDatabase(filepath:=sDBPath, Exclusive:=False)
' Close any forms that ticketaccess may have opened:
For Each oForm In oAccess.Forms
oAccess.DoCmd.Close(ObjectType:=Access.AcObjectType.acForm, _
ObjectName:=oForm.Name, _
Save:=Access.AcCloseSave.acSaveNo)
Next
If Not oForm Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oForm)
End If
oForm = Nothing
' Select the report name in the database window and give focus
' to the database window:
oAccess.DoCmd.SelectObject(ObjectType:=Access.AcObjectType.acReport, _
ObjectName:=sReport, InDatabaseWindow:=True)
' Maximize the Access window:
oAccess.RunCommand(Command:=Access.AcCommand.acCmdAppMaximize)
'oAccess.RunCommand(Command:=Access.AcCommand.acCmdAppMinimize)
' Preview the report:
oAccess.DoCmd.OpenReport(ReportName:=sReport, _
View:=Access.AcView.acViewPreview)
' Maximize the report window:
oAccess.DoCmd.Maximize()
' Hide Access menu bar:
oAccess.CommandBars("Menu Bar").Enabled = False
' Hide Report's Print Preview menu bar:
oAccess.CommandBars("Print Preview").Enabled = False
' Hide Report's right-click popup menu:
'oAccess.CommandBars("Print Preview Popup").Enabled = False
' Release Application object and allow Access to be closed by user:
If Not oAccess.UserControl Then oAccess.UserControl = True
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess = Nothing
Exit Sub
ErrorCleanup:
' Try to quit Access due to an unexpected error:
On Error Resume Next
System.Runtime.InteropServices.Marshal.ReleaseComObject(oForm)
oForm = Nothing
oAccess.Quit(Option:=Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess = Nothing
Exit Sub
ErrorHandler:
MsgBox(Err.Number & ": " & Err.Description & "- -" & sDBPath, _
MsgBoxStyle.MsgBoxSetForeground, "Error Handler")
Resume ErrorCleanup
End Sub ' Uses report in access db
|
|
|
|