|
Firstly, do you need that Thread.Sleep?
For the Function Keys I have found it works with the Keycode value. I tried the following with my browser and it refreshed the page. You will need to change the Keycode from F5 to F2.
F2 = 0x71
F5 = 0x74
See here[^] for full list of codes
foreach(Process process in Process.GetProcessesByName(textBoxProcessName.Text))
{
IntPtr hWnd = process.MainWindowHandle;
PostMessage(hWnd, WM_KEYDOWN, 0x74, 0);
}
hope this helps
Illogical thoughts make me ill
modified on Thursday, February 17, 2011 12:41 PM
|
|
|
|
|
Also, are you sure "javaw" is the right window you want?
Illogical thoughts make me ill
|
|
|
|
|
Hi,
Yes the process in task manager is called javaw ... the code below is the only way I can seem to get it to work? For some reason it requires the Thread.Sleep(2000) or it happens to quickly.
I would rather not use SendKeys, as I would like to send the "F2" keystroke to the window when it is minimized, any ideas?
private void button1_Click(object sender, EventArgs e)
{
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
Process[] processes = null;
if (Process.GetProcessesByName("javaw") != null)
{
processes = Process.GetProcessesByName("javaw");
}
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
SetForegroundWindow(pFoundWindow.ToInt32());
Thread.Sleep(2000);
SendKeys.Send("{F2}");
PostMessage(pFoundWindow, WM_KEYDOWN, 0x71, 0);
}
}
|
|
|
|
|
In addition to the other advice you have been given, you should consider that F5 is pretty much the standard key to use for refresh.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
Yes it is normally f5, our developers must have overlooked that unfortunately
|
|
|
|
|
First of all I don't understand what a refresh is going to do on a window you are not seeing anyway.
And then I have some doubt a minimized window will be receiving anything.
As your target app seems to be an in-house development, this is what I would suggest:
- create an extra window, make it visible, not shown in taskbar, off-screen, and with a unique title;
- have it override its WndProc and check for a special message (a WM_USER kind of message, not a regular one);
The other app now should:
- locate the target app;
- find the off-screen window based on its title;
- send the Window message your target app will react on.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi all,
I have been looking at some example code around and wonder if anyone knows what the differences/uses/benefits are of the following two examples for creating an instance of a class (if there are any at all)
Example 1: The Norm (in my experience)
Class Code:
public Person(){
}
Usage Code:
Person person = new Person();
Example 2: Via a Static Method
Class Code:
public static Person CreatePerson(){
return new Person();
}
Usage Code:
Person person = Person.CreatePerson();
Thanks
Illogical thoughts make me ill
|
|
|
|
|
http://henko.net/imperfection/constructors-and-creation-methods/[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thanks, I guess I was lacking the term 'Creation Method' is my failed Google attempts.
I think the example use I has seen was perhaps a miss use of this technique, unless of course I missed the point.
My understanding is that the Creation Method would be used if there where multiple (almost template like) default variations of a class. Obviously this could still be achieved by a constructor but I suppose the Create Method way provides distinction as to what you are actually doing.
Perhaps I would be correct in stating the following?..
- If you only have one default set up for a class, use a constructor
- If you have multiple commonly used default set ups then consider a Creation Method style approach
...I guess the later should be used if you were considering using a 'switch' type parameter in a class constructor. i.e. Stick to only property setting parameters in constructors (of course, in .Net 4.0 we don't even need to provide overloads for this )
Illogical thoughts make me ill
|
|
|
|
|
musefan wrote: perhaps a miss use of this technique
Yes, probably.
The benefit of well-defined Design Patterns is that they allow developers to discuss situations clearly. The downside is when developers don't understand them, how to implement, and when to implement them.
|
|
|
|
|
|
Thanks, I read into that from the other Link.
It all makes more sense logically now, I think the problem that I didn't get was with the example I used, which was basically as I had seen in some same code when looking into something else. Misused I think
Illogical thoughts make me ill
|
|
|
|
|
Hi guys...
I have need some help cuz I'm totally lost of how I should figure this out...
My case is:
- Make a storage function, so text documents like PDF, docx, doc, can be stored in the Database (MSSQL08 express).
Functions:
- Show files in a ListView (check)
- Upload files selected from the client, and store them as varbinary(max) in the Database (check)
- Download the selected file on the ListView to the correct documenttype on the clients PC (uncheck)
My database table is quiet simple and look something like:
ID - int (Primary key)NOT NULL (is identity)
FileName - varchar(50)NOT NULL
FileContent - varbinary(MAX)NOT NULL
FileExt - varchar(8) NOT NULL
FileComment - varchar(MAX) NULL
So as you can see, I can with ease locate if the selected file got .doc og .pdf extension.
The storage of a file into the varbinary of byte[] works brilliant!
But I'm stucked at how do I download those selected files back to the client, so they look excatly the same as when the document got uploaded to the db?
I mainly have two types of documents stored:
- WORD files
- PDF files
Can anyone provide at codesnippet or anything, that shows how to make a varbinary file (with bytes) into a appropreated document on the client computer readable as WORD document and/or PDF?
|
|
|
|
|
Please refer to [this^] example for similar task.
What i can say is you can read bytes(varbinary) from SQL database and create a doc file, which you can open and preview to user. But, user cannot do on its own from database.
|
|
|
|
|
The view function is kinda cool, but my problem is, the code ain't ASP, but plain old winforms, and can't find a link between the asp view function and similar function for winforms?
|
|
|
|
|
How did you upload the files into your database in the first place? Assuming you used some form of reading the file from disk, then you need to reverse that process to write it back.
I must get a clever new signature for 2011.
|
|
|
|
|
I used FileStream like this:
public byte[] ReadFile(string filePath)
{
byte[] buffer;
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int length = (int)fileStream.Length;
buffer = new byte[length];
int count;
int sum = 0;
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count;
}
finally
{
fileStream.Close();
}
return buffer;
}
and stored the returned value byte[] as the varbinary into the Database... Try'd to figure the reverse way back, but didn't worked that well tbh, maybe because I didn't do it the write way, but when I stored it as .docx the file was 'damage' and when I store it as .txt there is just binary numbers.
|
|
|
|
|
Well you have not shown what you did to re-create the file so it is difficult to guess what may be the problem. However, if you merely reverse the process above: get the buffer from the database and write to the appropriate file, then it should be correct.
grmihel2 wrote: when I store it as .txt there is just binary numbers.
That is to be expected, .docx files are compressed XML.
I must get a clever new signature for 2011.
|
|
|
|
|
I try'd the following (had no clue where to start, so just gave it a try with BinaryWriter):
public void DownloadFile(string filSti, StoredFile fil)
{
byte[] file = WriteFile(filSti, fil);
BinaryWriter bw = new BinaryWriter(File.Open(@"d:\temp\doctest.docx", FileMode.OpenOrCreate));
bw.Write(file);
bw.Close();
}
Didn't worked that well... It created a .docx file of 32KB (the original was 14KB), and when I try to open it, Word says it cannot be open be cause it may be broken.. Any hint what to do? I have an idea then when I see the light of the end, it would be 'easy' to do the same operation for the PDF documents
|
|
|
|
|
grmihel2 wrote: had no clue where to start
The best thing I can suggest is to look at the classes and methods you are using to read the file, and find the opposite methods for writing. Are you sure that you are reading the file in binary and not using any form of character conversion and thus corrupting the file? Are you verifying every method call is successful and that the captured length of the file matches the original?
Also, what does this line do, I've not seen this call?
byte[] file = WriteFile(filSti, fil);
I must get a clever new signature for 2011.
|
|
|
|
|
Oh yes, sorry, the WriteFile function is following:
public byte[] WriteFile(string filePath, StoredFile file)
{
byte[] buffer = file.FilContent.ToArray();
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
int length = (int)fileStream.Length;
buffer = new byte[length];
int count;
int sum = 0;
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count;
}
finally
{
fileStream.Close();
}
return buffer;
}
|
|
|
|
|
Why are you reading a file in your WriteFile() method? You should be getting the file content from your database and writing it to a disk file. The above code seems somewhat confusing.
I must get a clever new signature for 2011.
|
|
|
|
|
True, I can see that the Write method didn't make sense
I'm not really used to do these RW files programming, so I'm sorry for newbieness, but you have to learn it some how
Anyways, I have attempted to rewrite another write method like this:
public void WriteFile(string filePath, StoredFile file)
{
byte[] data = file.FilContent.ToArray();
FileStream fileStream = new FileStream(@"d:\temp\doctest.docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
int length = (int)data.Length;
int buffer = 1000;
fileStream.SetLength(length);
fileStream.Seek(length - buffer, SeekOrigin.Begin);
fileStream.Write(data, 0, buffer);
fileStream.Flush();
}
finally
{
fileStream.Close();
}
}
The doctest.docx file is now 14KB as the original, so something seems right. But the file is still somehow corrupted, cuz I can't open the docx without an error message telling me the data in the Word document is wrong... Notice that the file.Filcontent is the varbinary value from the Database.
By the way, is it really so simple, that when I'm sure that its a .docx file I store in my DB as varbinary, I can just store it on local machine as a file with the same extension? No need of creating a Word application object and write it through that?
|
|
|
|
|
You seem to be getting confused with your file IO code:
int length = (int)data.Length;
int buffer = 1000;
fileStream.SetLength(length);
fileStream.Seek(length - buffer, SeekOrigin.Begin);
fileStream.Write(data, 0, data.Length);
fileStream.Flush();
I would suggest spending some time here[^] to get a better understanding of the FileStream class.
I must get a clever new signature for 2011.
|
|
|
|
|
Thanks a lot! That worked like a charm... I certainly need to study some more of the FileStreamers posibilities, thats a whole new world opening, but ain't that the beauty of coding, to explorer new posibilities?
Yet again, thnx for your expertise, it works brilliant now.
|
|
|
|
|