|
OriginalGriff wrote: We all have. But if we muck up our PC that's one thing. Someone else's? Not the same at all.
And the lower the skill level, the more chance of error - you know that. Dude, it is a nonsense-application. Every student starts somewhere. I have run many pieces of homework on this machine, but never did anything happen that caused damage.
Yes, I know the dangers of coding all to well, in my first year I created a bug that caused a machine to dump 3 cubic meters of quick-drying cement on the floor. The people that had to shovel it away were not amused.
A gag-application is usually not run on an important server, and even if he makes a mistake, I doubt it would be as destructive as a virus.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: I have run many pieces of homework on this machine, but never did anything happen that caused damage. I was working on a project at my last employment some years ago and managed to disable one of my drives completely, with a fairly unsophisticated MFC app. Had it been the C drive I would have been most displeased.
|
|
|
|
|
That's why we don't work on production environments.
Doesn't mean that people should stop writing code "because" they may make a mistake
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I never suggested they should.
|
|
|
|
|
So he really does hates fast typists!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You could try putting this at the top of your file:
#pragma warning disable 1060
Or you can add this attribute to the method prototype:
SuppressUnmanagedCodeSecurityAttribute
Or, you could simply obey the warning and create an appropriate class and put the interop methods in it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 12-Mar-18 13:33pm.
|
|
|
|
|
|
I prefer to put all of my interop stuff into their own class. I think this warning started showing up in VS2017 (I've never seen it in VS2013).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm starting to plan out a project and I need some help with ideas.
Situation: my company uses a software managed by a third party company. I do not know exactly how this works but the link to this program looks like "113.444.767.123/bin/some file". This is started though iexplorer then switches over from the iexplorer process to a different process (I have the name).
We recently had then create a test company for training purposes. I can make two separate desktop icons easy enough. But once the program is running, if both the training and real companies are running at the same time, it is hard to determine the difference.
I want to change the taskbat icon, and pop a message balloon when the user switches between the two.
First problem, windows will use the desktop icon before the app icon, so I'm going to create a bootloader app that is launched from the desktop, it will open my real app and kill itself. Now I will have access to change the taskbar icon through code.
Second problem, I can't just call the process the company program and follow the returned processId because the original iexplorer ID calls the other program, thus changing ID's.
My thoughts: when I start the process from my program I start a loop the constantly calls getProcesses and loops through each one until the actual program process name is found. Once found I'll have the ID off the correct process and can match up icons based on that.
Third problem monitoring what process is active to change the icons.
My thoughts were to use TPL tasks, start a new async task that runs a loop to get the ForgroundWindowGetID and compare it to the list of IDs for the program I'm tracking. This is were in a little murky, can I send the ID back to my main program to handle the icons and balloons while still keeping the async task running, or do I need to stop the async task when the ID changes, then restart the task?
|
|
|
|
|
Use virtual machines; or get another physical machine.
None of this makes sense because what you're "planning" now is a throw-away.
I can create simulators; but the "real" thing is often cheaper (and VM's are "real" enough).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Couldn't you start your app with a parameter indicating whether it's the real company or the training company, and if it's the training company, change the icon of the main form in the app?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Not really, my app actually starts a 3rd party software. Once the 3rd party is running I want my app to be able to "watch" the 3rd party for which one was in focus. I was "hoping" and event would be thrown in Windows when a widow went in focus, but it doesn't look so.
What I've done so far (have not had time to do much) was to create two projects in one solution, the first one being a simple command line app that just calls the GUI. Now, since windows is not using the desktop shortcut icon, I can change the app icon and it is reflected on the team bar.
My plan for following windows is, on the open button event, the app calls the 3rd party program (actually a link to a server), starts a timer, on the tick event, loads all the precesses into a list and loops through list search for the process name to show up, once it finds it, adds the ID to a list and stops the timer, starts an async task that gets the ID number of the active window, if the active window is in the process list, displays the correct icon.
|
|
|
|
|
Prod vs test user decisons based on the color of a task bar icon.
Sounds like Hawaii all over again.
(Some people are color blind).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: (Some people are color blind). Actually, quite a few, including me.
Roughly 1 in 10 males are red/green colorblind (US statistic).
Females are rarely colorblind.
(A sex-linked trait, recessive on X chromosome.)
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
To me, "some" means one, all, or anything in between
In this case, you plan for any number.
(I think when I did have a "test" environment, I would change the entire background if there was any chance there would be any confusion).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
This is probably a very dumb question but i am just starting to learn programming and i´m stuck.
In the following code i have made two methods , one for button moving up and another one for button moving down. I know i should be able to put them into one method using parameters but i don´t understand that concept yet. Can anyone help me understand how to do that?
public partial class MainWindow : Window
{
Verdieping etage;
public MainWindow()
{
InitializeComponent();
Verdieping etage = (Verdieping)0;
lblHuidigeVerdieping.Content = etage.ToString();
}
enum Verdieping: sbyte
{
kelder =-1,
gelijksvloers,
een,
twee,
drie
}
void WijzigVerdiepingUp()
{
etage++;
lblHuidigeVerdieping.Content = etage.ToString();
}
void WijzigVerdiepDown()
{
etage--;
lblHuidigeVerdieping.Content = etage.ToString();
}
private void btnUp_Click(object sender, RoutedEventArgs e)
{
WijzigVerdiepingUp();
}
private void btnDown_Click(object sender, RoutedEventArgs e)
{
WijzigVerdiepDown();
}
}
|
|
|
|
|
Try:
const int Up = 1;
const int Down = -1;
void WijzigVerdieping(int direction = Up)
{
etage += direction;
lblHuidigeVerdieping.Content = etage.ToString();
}
private void btnUp_Click(object sender, RoutedEventArgs e)
{
WijzigVerdieping();
}
private void btnDown_Click(object sender, RoutedEventArgs e)
{
WijzigVerdiep(Down);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Even though we haven´t seen constants yet , and we have to make it work without them, i tried your code and it says
Operator '+=' cannot be applied to operands of type 'Mainwindow.Verdieping' and 'int'.
Thank you for your swift answer , i ll just wait till next class and ask the teacher if he can explain me the concept
|
|
|
|
|
You just need to change the parameter and constant types to sbyte :
const sbyte Up = 1;
const sbyte Down = -1;
void WijzigVerdieping(sbyte direction = Up)
{
etage += direction;
lblHuidigeVerdieping.Content = etage.ToString();
}
However, you need to bear in mind that .NET enum types aren't limited to the named values; they're only limited to the range of the underlying type. If you start with drie and add 1 , you'll get 4 .
That may or may not be a problem, depending on your requirements.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you, i had figured that out in the meantime as well
Though i still was looking for a way to make it work without using a constant, so i just tried without and it worked also.
I still don´t know when i have to declare a variable in the method and when not , i hope the understanding comes with doing more exercises.
Thank you both for your help
sbyte up = +1;
sbyte down = -1;
void WijzigVerdiep(sbyte direction )
{
etage += direction;
lblHuidigeVerdieping.Content = etage.ToString();
}
|
|
|
|
|
You're welcome!
But constants are a good idea here.
All they do is create a variable which can't be changed - the compiler will not let it appear on the left hand side of a "=" sign, or be passed as a method parameter that can be changed (you'll get to those later in the course).
They are also really easy to do: just put the keyword const at the start of the declaration (where you could put public or private ):
const sbyte up = +1;
const sbyte down = -1; And the compiler will not let any part of your code change the value.
That means you can't make a mistake, and change them accidentally - which could make your program to some strange things a lot later when it's difficult to spot.
You don't have to use them, but it's a good idea!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Add this method to your code, and then aim the click handler for both buttons at it.
private void btnUpDown_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnUp" : etage++; break;
case "btnDown" : etage--; break;
}
lblHuidigeVerdieping.Content = etage.ToString();
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 9-Mar-18 13:26pm.
|
|
|
|
|
Similarly, without numeric constants:
void WijzigVerdieping(bool omhoog) {
if (omhoog) etage++; else etage--;
lblHuidigeVerdieping.Content = etage.ToString();
}
private void btnUp_Click(object sender, RoutedEventArgs e) {
WijzigVerdieping(true);
}
private void btnDown_Click(object sender, RoutedEventArgs e) {
WijzigVerdieping(false);
}
which is using the predefined boolean constants true and false .
PS: you need some limit checks, otherwise pressing btnDown a lot might teleport you to Australia...
|
|
|
|
|
I assume there is a reason you defined the Enum used here; however, it makes no sense to use an Enum as a counter when you allow its value to go outside of the range for which you have defined Enum members.
Assumming you wish the Enum to define the range of "legal" counter values:
namespace Whatever
{
public enum Verdieping
{
kelder = -1,
gelijksvloers,
een,
twee,
drie
}
public partial class MainWindow : Window
{
private int tally;
public MainWindow()
{
InitializeComponent();
lblHuidigeVerdieping.Text = Verdieping.gelijksvloers.ToString()};
tally = 0;
}
private void TallyButtons_Click(object sender, RoutedEventArgs e)
{
if (sender.Equals(btnDown))
{
if (tally == (int)Verdieping.gelijksvloers)
{
return;
}
tally--;
}
else
{
if (tally == (int) Verdieping.drie)
{
return;
}
tally++;
}
lblHuidigeVerdieping.Text = tally.ToString();
}
}
}
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Hi everybody,
I would like to set a background image to a Groupbox and have it displayed at run time.
Below are the lines inserted in the xaml file at the appropriate locations:
<Window.Resources>
<VisualBrush x:Key="myNewBrush">
<VisualBrush.Visual>
<Grid>
<Rectangle Fill="Transparent"/>
<Image Source = "/Resources/Images/BartMap.png"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Windows.Resources>
<GroupBox Grid.Row="1" Grid.Column="0" Background="Transparent">
<GroupBox.Header>
<Label FontWeight="Bold">Track plan </Label>
</GroupBox.Header>
<Grid Background="{StaticResource myNewBrush}">
</Grid>
</GroupBox>
My problem: The image background is not displayed at runtime.
Could anyone help me with this issue?
Best regards,
Hervend
Hervend
|
|
|
|
|