|
Hi
am new to windows service.what ever samples i see ,it is described that by default the servicebase class will be available, after that the installer needs to be added .
It makes sense that the installers are needed to install the service to the OS as a service . But i don't find any code relations that the service class refers the installer classes .
Please xplain me
1. where is the link between the service class & the installer
2. how the installer identifies which service needs to be installed(service seems accepts any text string not hardly the service class)
Thanks & Regards
Raghuraman.C
|
|
|
|
|
Hello,
Can anyone tell me how I can locate a program that is minimized to the system tray. I know the Process Id of the application, but when I call Interaction.AppActivate using the process Id I get an ArgumentException exception. However, I don't know the title of the application to use the (Win32)FindWindow method.
Apparently programs that run in the system Tray can not be retrieved using this method. I am able to retrieve all other types of programs using this method.
Here is my code that locates the application and activates it to bring it to the front.
private void onLocateApplicationButtonClick(object sender, EventArgs e)<br />
{<br />
if ((null != sender)<br />
&& (sender is Control)<br />
&& (null != ((Control)sender).Tag)<br />
&& (((Control)sender).Tag is int))<br />
{<br />
int app_index = (int)((Control)sender).Tag;<br />
<br />
try<br />
{<br />
Interaction.AppActivate(m_processes_list[app_index].Id);<br />
}<br />
catch (ArgumentException aex)<br />
{<br />
Console.WriteLine("{0}", aex.Message);<br />
}<br />
}<br />
}
Any one have a suggestion?
Thanks,
DP
|
|
|
|
|
Maybe this will give you a head start, ignore the custom types referenced that aren't included in this code. If you have the process id, you should be able to identify it while looping through all processes. You'll probably need to use the CaptureWindowless() example.
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using BoneSoft.LinksLibrary;
namespace LinksLibrarian2 {
public class ProcessCapturer {
static ProcessCapturer() {}
public static ShortCuts CaptureWindows() {
ShortCuts scs = new ShortCuts();
scs.AddRange(CaptureFolders());
scs.AddRange(CaptureIEs());
Process[] localAll = Process.GetProcesses();
foreach (Process p in localAll) {
try {
if (p.MainWindowTitle.Equals(string.Empty)) { continue; }
ShortCut esc = null;
esc = new ExeShortCut(p.MainWindowTitle, p.MainModule.FileName);
if (esc == null) { continue; }
esc.Description = p.ProcessName;
scs.Add(esc);
} catch {}
}
return scs;
}
public static ShortCuts CaptureWindowless() {
ShortCuts scs = new ShortCuts();
Process[] localAll = Process.GetProcesses();
foreach (Process p in localAll) {
try {
if (!p.MainWindowTitle.Equals(string.Empty)) { continue; }
ShortCut esc = null;
esc = new ExeShortCut(p.ProcessName, p.MainModule.FileName);
if (esc == null) { continue; }
esc.Description = p.ProcessName;
scs.Add(esc);
} catch {}
}
return scs;
}
}
}
Visit BoneSoft.com
|
|
|
|
|
Thanks for your help.
I used your 'CaptureWindowless' example to verify that the Process Id I have is in the list of all Processes and it is. However, I am still unable to Activate that given process so that it brings my application to the front.
Using your code I added the following try-catch once I verify the Process is in the list. And I pass the process name to the (Win32) method, FindWindow, and it returns zero - could not find it.
try
{
Interaction.AppActivate(id);
}
catch (ArgumentException)
{
uint hwndInstance = FindWindow(null, p.ProcessName);
}
|
|
|
|
|
Hey Everyone,
This is my 2nd day using C# and so far it's been pretty cool. I'm trying to write an application that will return system information to me such as the processor type and RAM speed of a system. Any idea how I would go about that?
Thank you in advance.
-Karthik Gaekwad
|
|
|
|
|
|
That is perfect! Thanks a million.
-K
|
|
|
|
|
I have a typed dataset with an integer value called FiscalMonth. What I want to do is bind it to a combobox that is preseeded with a list of integers from 1-12.
Here's what I have so far:
<br />
for (int i = 1; i <= 12; i++)<br />
{<br />
uxcbFMonth.Items.Add(i);<br />
}<br />
<br />
mySource = new BindingSource();<br />
<br />
mySource.DataSource = myManagerClient.VersionTable.Select("VersionKey = " +VersionKey.ToString())[0];
That seems to work just fine, the combobox is populated, and in the text fields, the databinding (using Control.DataBindings.Add) works. The problem is it doesn't appear as if the combobox databinding works, because when I try to change it the control locks and remains selected until I manually close the application.
I assign the databindings like this:
uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth", true, DataSourceUpdateMode.OnValidation);
Am I binding to the wrong value? Any ideas?
|
|
|
|
|
I have a Word template with 13 docVariables. In C# word interop code stuffers I have to access them with Field[1].Select() and then populate the selection (Variables come up empty).
My problem: Is there a way to rather call Field["varname"] instead of recalling Field[1] over and over again. If not, is there a way to ensure that I have the correct field, instead of hoping I counted correctly?
|
|
|
|
|
You could use an enum. Or a Dictionary. Just thinking about simple solutions.
Logifusion[^]
|
|
|
|
|
Dictionary?
Everything works fine, the guy I'm doing it for just wants to be super sure that the correct fields get filled out... Seeing as its his, ahem, rear on the line, I can understand his concern.
|
|
|
|
|
Well, you can write an enum like this:
public enum MyDocFields {
FirstField = 0,
SecondField = 1,
...
}
Or you can use a Dictionary:
Dictionary<string, int> dictDocFields = new Dictionary<string, int>();
dictDocFields.Add("FirstField", 1);
...
Basically just use anything that eventually gets you back to an integer.
Logifusion[^]
|
|
|
|
|
Doesn't really solve my problem, but thanks a lot anyway...
My main problem is that I need to prove from the document that I am working with the correct field, assigning my own names to the field does not quite cut it...
Oh well, always was one for self inflicted torture
Thanks for your help
|
|
|
|
|
This code below is pretty long. Wonder if its possible to shorten the code?
the sender would be the combo box... I have 7 comboboxes on the window as part for Filtering the data from the raw data and the cbMath<x> comboboxes are independent.
Can anyone make any suggestion?
#region private void cbMath_IndexChanged(object sender, System.EventArgs e)
private void cbMath_IndexChanged(object sender, System.EventArgs e)
{
ComboBox cb = (ComboBox)sender;
switch (cb.Name.ToString())
{
case "cbMathA":
{
if (this.numericUpDownAL.Visible && this.cbMathA.Text == "Range")
{
this.numericUpDownAR.Visible = true;
}
else
{
this.numericUpDownAR.Visible = false;
}
if (this.dateTimePickerAL.Visible && this.cbMathA.Text == "Range")
{
this.dateTimePickerAR.Visible = true;
}
else
{
this.dateTimePickerAR.Visible = false;
}
break;
}
case "cbMathB":
{
if (this.numericUpDownBL.Visible && this.cbMathB.Text == "Range")
{
this.numericUpDownBR.Visible = true;
}
else
{
this.numericUpDownBR.Visible = false;
}
if (this.dateTimePickerBL.Visible && this.cbMathB.Text == "Range")
{
this.dateTimePickerBR.Visible = true;
}
else
{
this.dateTimePickerBR.Visible = false;
}
break;
}
case "cbMathC":
{
if (this.numericUpDownCL.Visible && this.cbMathC.Text == "Range")
{
this.numericUpDownCR.Visible = true;
}
else
{
this.numericUpDownCR.Visible = false;
}
if (this.dateTimePickerCL.Visible && this.cbMathC.Text == "Range")
{
this.dateTimePickerCR.Visible = true;
}
else
{
this.dateTimePickerCR.Visible = false;
}
break;
}
case "cbMathD":
{
if (this.numericUpDownDL.Visible && this.cbMathD.Text == "Range")
{
this.numericUpDownDR.Visible = true;
}
else
{
this.numericUpDownDR.Visible = false;
}
if (this.dateTimePickerDL.Visible && this.cbMathD.Text == "Range")
{
this.dateTimePickerDR.Visible = true;
}
else
{
this.dateTimePickerDR.Visible = false;
}
break;
}
case "cbMathE":
{
if (this.numericUpDownEL.Visible && this.cbMathE.Text == "Range")
{
this.numericUpDownER.Visible = true;
}
else
{
this.numericUpDownER.Visible = false;
}
if (this.dateTimePickerEL.Visible && this.cbMathE.Text == "Range")
{
this.dateTimePickerER.Visible = true;
}
else
{
this.dateTimePickerER.Visible = false;
}
break;
}
case "cbMathF":
{
if (this.numericUpDownFL.Visible && this.cbMathF.Text == "Range")
{
this.numericUpDownFR.Visible = true;
}
else
{
this.numericUpDownFR.Visible = false;
}
if (this.dateTimePickerFL.Visible && this.cbMathF.Text == "Range")
{
this.dateTimePickerFR.Visible = true;
}
else
{
this.dateTimePickerFR.Visible = false;
}
break;
}
case "cbMathG":
{
if (this.numericUpDownGL.Visible && this.cbMathG.Text == "Range")
{
this.numericUpDownGR.Visible = true;
}
else
{
this.numericUpDownGR.Visible = false;
}
if (this.dateTimePickerGL.Visible && this.cbMathG.Text == "Range")
{
this.dateTimePickerGR.Visible = true;
}
else
{
this.dateTimePickerGR.Visible = false;
}
break;
}
default: return;
}
}
|
|
|
|
|
I had to do something similar to this myself. I used reflection. Here's kinda what I would do:
char endChar = cb.Name[cb.Name.Length - 1];
FieldInfo fiNumL = this.GetType().GetField("numericUpDown" + endChar + "L");
FieldInfo fiNumR = this.GetType().GetField("numericUpDown" + endChar + "R");
FieldInfo fiMath = this.GetType().GetField("cbMath" + endChar);
Control cNumL = fiNumL.GetValue(this) as Control;
Control cNumR = fiNumR.GetValue(this) as Control;
Control cMath = fiMath.GetValue(this) as Control;
cNumR.Visible = (cNumL.Visible && cMath.Text == "Range");
It's not complete, but hopefully it makes sense. If you're not comfortable with reflection, just shorten your if statements:
this.numericUpDownGR.Visible = this.numericUpDownGL.Visible && this.cbMathG.Text == "Range";
Logifusion[^]
|
|
|
|
|
Hmmm I like the suggestion. I'll look into these possiblites. Thanks!
|
|
|
|
|
The 2nd suggestion made by LogiFusion makes more sense to me. Its much straightforward. It helped to shrink the switch statement from 151 lines to 46 lines.
Thanks a heap!
|
|
|
|
|
Nothing like a challange. 36 lines.
private void do(Contol upDown, Control upDown2, string math, Control picker, Control picker2) {
upDown2.Visible = (upDown.Visible && math == "Range");
picker2.Visible = (picker.Visible && math == "Range")
}
private void cbMath_IndexChanged(object sender, System.EventArgs e) {
switch (((ComboBox)sender).Name) {
case "cbMathA":
do(this.numericUpDownAL, this.numericUpDownAR, this.cbMathA.Text, this.dateTimePickerAL, this.dateTimePickerAR);
break;
case "cbMathB":
do(this.numericUpDownBL, this.numericUpDownBR, this.cbMathB.Text, this.dateTimePickerBL, this.dateTimePickerBR);
break;
case "cbMathC":
do(this.numericUpDownCL, this.numericUpDownCR, this.cbMathC.Text, this.dateTimePickerCL, this.dateTimePickerCR);
break;
case "cbMathD":
do(this.numericUpDownDL, this.numericUpDownDR, this.cbMathD.Text, this.dateTimePickerDL, this.dateTimePickerDR);
break;
case "cbMathE":
do(this.numericUpDownEL, this.numericUpDownER, this.cbMathE.Text, this.dateTimePickerEL, this.dateTimePickerER);
break;
case "cbMathF":
do (this.numericUpDownFL, this.numericUpDownFR, this.cbMathF.Text, this.dateTimePickerFL, this.dateTimePickerFR);
break;
case "cbMathG":
do (this.numericUpDownGL, this.numericUpDownGR, this.cbMathG.Text, this.dateTimePickerGL, this.dateTimePickerGR);
break;
}
}
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: Nothing like a challange.
Did I hear challenge?!?
cbMathA.Tag = new Infos(numericUpDownAL, numericUpDownAR, dateTimePickerAL, dateTimePickerAR);
cbMathB.Tag = new Infos(numericUpDownBL, numericUpDownBR, dateTimePickerBL, dateTimePickerBR);
cbMathC.Tag = new Infos(numericUpDownCL, numericUpDownCR, dateTimePickerCL, dateTimePickerCR);
cbMathD.Tag = new Infos(numericUpDownDL, numericUpDownDR, dateTimePickerDL, dateTimePickerDR);
cbMathE.Tag = new Infos(numericUpDownEL, numericUpDownER, dateTimePickerEL, dateTimePickerER);
cbMathF.Tag = new Infos(numericUpDownFL, numericUpDownFR, dateTimePickerFL, dateTimePickerFR);
cbMathG.Tag = new Infos(numericUpDownGL, numericUpDownGR, dateTimePickerGL, dateTimePickerGR);
cbMathH.Tag = new Infos(numericUpDownHL, numericUpDownHR, dateTimePickerHL, dateTimePickerHR);
public struct Infos {
public Control UpDown;
public Control UpDown2;
public Control Picker;
public Control Picker2;
public Infos(Control upDown, Control upDown2, Control picker, Control picker2)
{
UpDown = upDown;
UpDown2 = upDown2;
Picker = picker;
Picker2 = picker2;
}
}
private void cbMath_IndexChanged(object sender, System.EventArgs e) {
Infos info = (Infos)((ComboBox)sender).Tag;
info.UpDown2.Visible = (info.UpDown.Visible && ((ComboBox)sender).Text == "Range");
info.Picker2.Visible = (info.Picker.Visible && ((ComboBox)sender).Text == "Range");
}
Addition:
Just noticed that replacing the 4 Control fields with one array could safe another 6 lines but that would probably look a bit ugly.
-- modified at 15:32 Friday 16th June, 2006
|
|
|
|
|
Seems I enjoy seeing such challenge... But I'm deciding on the options as people input the ideas. I do have other areas in my code is somewhat similiar to this case and will see which will fit for few Methods I would use.
I will announce who's the "winner" for the "competition" sometime this weekend.
~RonBou (I've got 2 accounts with Codeproject.)
-- modified at 15:51 Friday 16th June, 2006
|
|
|
|
|
Robert Rohde wrote: Just noticed that replacing the 4 Control fields with one array could safe another 6 lines but that would probably look a bit ugly.
Or perhaps even replace the entire struct with an array?
cbMathA.Tag = new Control() {numericUpDownAL, numericUpDownAR, dateTimePickerAL, dateTimePickerAR};
cbMathB.Tag = new Control() {numericUpDownBL, numericUpDownBR, dateTimePickerBL, dateTimePickerBR};
cbMathC.Tag = new Control() {numericUpDownCL, numericUpDownCR, dateTimePickerCL, dateTimePickerCR};
cbMathD.Tag = new Control() {numericUpDownDL, numericUpDownDR, dateTimePickerDL, dateTimePickerDR};
cbMathE.Tag = new Control() {numericUpDownEL, numericUpDownER, dateTimePickerEL, dateTimePickerER};
cbMathF.Tag = new Control() {numericUpDownFL, numericUpDownFR, dateTimePickerFL, dateTimePickerFR};
cbMathG.Tag = new Control() {numericUpDownGL, numericUpDownGR, dateTimePickerGL, dateTimePickerGR};
cbMathH.Tag = new Control() {numericUpDownHL, numericUpDownHR, dateTimePickerHL, dateTimePickerHR};
private void cbMath_IndexChanged(object sender, System.EventArgs e) {
Control() info = (Control())((ComboBox)sender).Tag;
info(1).Visible = (info(0).Visible && ((ComboBox)sender).Text == "Range");
info(3).Visible = (info(2).Visible && ((ComboBox)sender).Text == "Range");
}
And, yes, readability and extremely short code doesn't play well together.
---
b { font-weight: normal; }
|
|
|
|
|
We could continue and probably end up in one single line... which noone could ever understand
|
|
|
|
|
hi every one
i'm working on a win application and i'm kinda stuck in security issue as i want to make my main form to get the local pc mac addres and check it with a prestored value so that it continues working or exit application.
here what i need "i need the code to get mac address and show it in a textBox in a form?" this maybe a stupied quest to some of u but i appriciate helping
Hesham Hafez
|
|
|
|
|
Does this[^] article help?
[edit]
Sorry, see this[^] article.
[/edit]
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
-- modified at 12:58 Friday 16th June, 2006
|
|
|
|
|
well thanks for helping but i don't know how to make use of a console application output to make it displayed in form applicaiton i know that sounds stupied but i'm not really good at c# so please advice
Hesham Hafez
|
|
|
|
|