|
Hi
How do I determine if my application is currently active? I.e. I want to see if my app. is the one in focus or if the user has shifted to another app. by clicking it's box in the taskbar, etc.
Thanks for your help,
Mads
|
|
|
|
|
You can overriden Leave event for when it lost focus. Also for regulary check it ,you can check Focused property of form in a timer.
Mazy
No sig. available now.
|
|
|
|
|
Thanks for your reply.
Unfortunately, Leave doesn't seem to have the requested effect. The Leave event is not raised when the active application is changed, I think we will try to do a work around using MDI.
|
|
|
|
|
I need to get a Java application to communicate with a C# apps. What're the possible ways of doing that? References/Url would be nice. Just want to add that I'm new to Java, and been coding Windows code for the most part of my life. So, please keep in simple and treat me tender.
Thanks in advance.
Norman Fung
|
|
|
|
|
Depends what you want to communicate but XML would be a good way if you want to do it file/db based. Another would be some sort of Socket based communication not sure how it would go between C# and Java.
Just a little idea
HTH
Luke
|
|
|
|
|
IPC, Java and C#: Is it possible to do this via shared memory...?
Thanks.
Norman Fung
|
|
|
|
|
If you want to actually host .NET controls in a Java application see my article, Embedding .NET Controls in Java[^]. There are also commercial libraries available such as JAWIN and Ja.NET that generate the necessary classes at runtime.
As far as interoperability between Java and .NET at the communications layer, there has been a whole slew of articles on MSDN[^], such as Application Interoperability: Microsoft .NET and J2EE[^].
As for one of your other questions, I suppose you could use IPC but you're going to spend a lot of time just P/Invoking the necessary functions, creating any structs, etc. The articles I mentioned should provide alternatives that can possibly decrease development time and - in some cases - use standard protocols to communicate between the two.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hey that's very useful tips. I'll look at it.
Norman Fung
|
|
|
|
|
How can I create a borderless menu or a transparent menu when creating a owner drawn menu? I have seen this in the Winamp 3x.
UB
You may stop this individual, but you can't stop us all... after all, we're all alike. +++Mentor+++
|
|
|
|
|
To make a menu transparent, you can use Menu.Handle to get an HWND for the popup window that represents that menu and use the native function SetLayeredWindowAttributes (you'll have to P/Invoke it). To draw the menu without a border, you'll have to handle the MenuItem.DrawItem event and do all the drawing yourself.
You can find several examples here on CodeProject using a search like menu draw[^] or similar. Dr. Gui on MSDN[^] also had a good example some time back at http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui11062001.asp[^]. The example's in VB.NET but it's mostly method calls (remember, the base class library - or any assembly for that matter - is available to all languages that target the CLR, or ".NET languages", in the same way; though, the syntax for making those calls may be different).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the advice. I found several articles on CodeProject. To make it borderless they have used subclassing. It's a war out there. Some of them have used hooks, and some of them are against using hooks
By the way I went to geekcode.com, and now I know what's that first three letters mean
Thanks again.
UB
You may stop this individual, but you can't stop us all... after all, we're all alike. +++Mentor+++
|
|
|
|
|
Can anyone help as I am having a little trouble..
I have a panel with AutoScroll = True. I have added a panel to this control which is bigger than the parent, so scroll bars appear. Then I add another panel calculating the position using
<br />
panelPos = PanelList.Count * APanel.Height;<br />
APanel.Location = new System.Drawing.Point(30, 38 + panelPos);<br />
When the scroll box is not scrolled adding panels puts each one directly below the next as I want. But if the parent is scrolled down then the position is wrong (the new panel is added too low down) by an offset.
I thought the answer would be in the AutoScrollPosition property but I haven't been succesful in making it work.
Any ideas?
TIA
Luke
|
|
|
|
|
If you look at the documentation for the AutoScrollPosition property, it states that negative values are returned for the X and Y properties of the Point returned from the property if a user has scrolled away from the starting position (0,0). Make sure you negate these values before factoring them into your new position for child panels.
See DirectX 9.0 - Get Ambient with DirectSound[^] which should contain a sample like this (judging by the way the program works).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Dear, Sir
I will develop an application that automatic check what update on database on the Web Server.
Please give me an idea and overview about it. To get what update via Internet I should use what classs.
I ever create database application, but I never create application that connect to the internet.
And I think I should use thread in this application. Is.... correct?
Thank You.
Sorry for bad English.
;);P ((
|
|
|
|
|
You need to read about ADO.NET. Disconnected data sources is the main area.
HTH
Luke
PS: Never appologise for your english (most of us "english" do not speak it very well and the majority cannot even speak another language including me
|
|
|
|
|
As Jinwah was getting at, see the System.Data.DataSet class documentation in the .NET Framework SDK, as well as System.Data.Common.DbDataAdapter - specifically, one of its derived classes depending on what database you're accessing (like System.Data.SqlClient.SqlDataAdapter for a SQL Server database).
You give the DbDataAdapter the appropriate SELECT, INSERT, UPDATE, and DELETE commands (it has properties for each), which you can either use the DataAdapter designer in VS.NET or a CommandBuilder to generate, or type them yourself but generating an example to get an idea might be a good idea.
Then, whenever you update, remove, or insert information in the DataSet , you call DbDataAdapter.Update(DataSet) which will use the change type information for each DataRow and will call the appropriate DbCommand on the DbDataAdapter . There are several examples of this on the CodeProject web site, as well as examples in the .NET Framework SDK.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have the following code:
<br />
<br />
try<br />
{<br />
string ConnString;<br />
ConnString="Provider=SQLOLEDB;";<br />
ConnString+="data source=127.0.0.1;";<br />
ConnString+="initial catalog=AutoConvert;";<br />
ConnString+="password=password;";<br />
ConnString+="persist security info=False;";<br />
ConnString+="user id=sa;";<br />
OleDbConnection dbConn = new OleDbConnection(ConnString);<br />
dbConn.Open();<br />
<br />
FileStream fs = File.Open("c:\\temp\\output.dat",FileMode.Open);<br />
BinaryReader BR = new BinaryReader(fs);<br />
byte [] BLOB=BR.ReadBytes(Convert.ToInt32(fs.Length));<br />
DataBase.InsertBLOB(dbConn,"Documents","BatchName","1234567",true,"Document",BLOB);<br />
dbConn.Close();<br />
<br />
}<br />
catch(Exception Err)<br />
{<br />
Console.WriteLine(Err.Message);<br />
}<br />
<br />
<br />
<br />
<br />
static public void InsertBLOB(OleDbConnection db,string Table,string LookUpField,string LookUpData,bool IsLookUpString,string BLOBField,byte [] BLOB)<br />
{<br />
try<br />
{<br />
string Command;<br />
if(IsLookUpString)<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}='{3}')",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
else<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}={3})",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
OleDbCommand addEmp = new OleDbCommand(Command, db); <br />
addEmp.Parameters.Add("@"+BLOBField,BLOB);<br />
addEmp.ExecuteNonQuery();<br />
}<br />
catch(Exception Err)<br />
{<br />
throw new Exception(Err.Message);<br />
}<br />
}<br />
addEmp.ExecuteNonQuery throws an exception witht he message:
"You must define @Document"
I copied the code almost directly from MSDN, but I can't get it to work...Any ideas ?
Oh and in my AutoConvert Catalog I have the table Documents with an image field of length 16 called Document.
|
|
|
|
|
First of all, if you're connecting to a SQL Server, you should be using the class in System.Data.SqlClient . These classes - including the SqlParameter (as opposed to OleDbParameter ) are optimized for SQL Server.
Finally, you must define the type of your SqlParameter like so:
SqlParameter parm = addEmp.Parameters.Add("@" + BLOBField, SqlDbType.Image;
parm.Value = BLOB; See http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwritingblobvaluestodatabase.asp[^] for an example.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help as always Heath, I thought SqlConnection and OleDbConnection class were interchangable...
|
|
|
|
|
You can use the System.Data.OleDb classes to access SQL Server, but they are not optimized for any one database - they just use the OLE DB driver using only the common abstract implementations. As far as mixing these two collections of classes together, that's not really supported because most methods in the derived classes take specific types indicitive of their namespace (like a SqlCommand can take a SqlConnection , not a generic DbConnection ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've been a VC++ programmer for about 4 years now and I'm learning C#, you been a great help thus far Heath...thanks
|
|
|
|
|
A solution that I'm developing has a server and multiple clients. The clients access Client-Activated object on the remoting server. What would be the best way of keeping track of the connections?
I have a SQL server on the same machine and I'm thinking about doing it like this: on init - add an entry in the connection table. when the object is disposed it will remove itself from the table. However, there are a few problems.
+ if the client crashes -> when the lease runs out the connection will be unregistered. right?
+ What about if the server crashes - I'll just clean up the connection table on startup.
Does anyone have any suggestions?
|
|
|
|
|
Your SQL-Server solution works, but there is an easier way to tracking your clients (I think):
Create an ArrayList and add each ClientObject by creation.
Use delegates to remove ClientObjects, when there lease is running out.
If the server crashes, the ArrayList will be removed automatically
|
|
|
|
|
Actually, this is not so good but your solution to use a lease is what I was going to recommend anyway. I originally recommend using a database as we do for our app (which is driven by a SQL Server anyway) because if your remoting object goes down for some reason, your list is lost. The database (in our case, which is replicated and stored on a RAID array) will persist this information so that when the remoting object comes back up, it can grab the information and return to its original state.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
As I hinted at before, implement ILease and return that in an override for GetLifetimeService on your remoting object. If a sponser cannot be contacted or has not renewed the time on the lease, you remove the row from the RDBMS for that sponsor (a client). In an internal remoting application, your lease can ping the sponsers to determine if they still exist. If you expose your remoting object on IIS (which automatically gets exposed as a Web Service, thus using HTTP which is one-way), you'll just have to wait until the sponsor does not renew their lease and remove the row.
If the remoting object (the server) crashes, this really isn't a problem. As long as the database is still up and running, the remoting object will grab the existing information (this is the reason I mentioned you should persist connection information in a database or something) and restore its state. Clients can't really connect why the remoting object is down, so you don't have to worry about new information. Now if the server(s) that has/have both your remoting object and the database go down, the scenario isn't much different from before. Just use transacted statements to increment and decrements your client connections table and they will be logged so that they can be completed in such a case.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|