|
You might consider posting this on the Lounge; you are, after all, talking about a revised code provided for an article here on CP. There are lots of posts on the Lounge where members talk about their achievements, challenges, current work; quite often these posts do not refer to specific CodeProject resources, or discussions.
However, it appears that the only update (I can see) of the article is that you simply added a message in the comments section announcing it, and linking to the project on GitHub. Unfortunately, it is also correct that some people seem to have have a certain latitude for Lounge post content that others do not (welcome to "human nature"); reaction to your post ? ... who knows ?
It appears to me your code is now in C#, rather than VB.NET; I suggest you edit the article, and at least mention that.
Since, I assume, your new code reflects some new/different ideas, or techniques, compared to a year, or more, ago, one can hope you might revise the article.
You also might notify CP staff of the revision; frequently the e-mail updates from CP members subscribe to include mentions/links to revised articles. I suggest you wait to do that until after you have revised the article text. I am not sure of the exact mechanism for this; perhaps revised articles are selected for mention automatically.
All of this is, of course, imho.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 14-Jun-16 23:40pm.
|
|
|
|
|
I want to create three cars from different directions meeting at the junction
|
|
|
|
|
And how is this relating to C#?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
1) Buy three cars.
2) Get three drivers, and give them each two mobiles.
3) Get them to call each other so they can all hear each other and coordinate activities.
4) Get them to drive at an appropriate speed into the same junction at the same time. I'd recommend videoing the results for YouTube.
(4) May be the hardest part, unless you find really stupid people who don't realize they may well be injured or killed. Alcohol may help here, but would impair coordination as well as being illegal.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I read it a little different, he wanted to build three cars, and then the builders would meet in a junction from different directions. 
|
|
|
|
|
Oh, right! That's easy: open a pub on the junction!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I'm still waiting for the Hammerhead Eagle i-Thrust Coupé GTR.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
And what, exactly, is your question? Please remember that we don't know what you've done or what part you are stuck on without you telling us.
This space for rent
|
|
|
|
|
1. Go to the toy store and buy 3 matchbox cars.
2. Position three lengths of wood in a star like pattern and elevate them 45 degrees on the furthest away from the center.
3. Position the cars at the top of each plank and release them all at the same time.
4. Have a camera handy so you can take a picture when they all crash together.
5. Import that picture to your solution and write the following.
Bitmap CarsCrashingTogether = new Buitmap("CarCrash.jpg");
6. Tada, you now have a Visual Studio application that contains a car crash.
Hope this helps
Matthew Hazlett
Fighting the good fight for web usability.
|
|
|
|
|
Hello,
I am trying to get the list of open windows using C#, here is my code..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace howto_list_desktop_windows
{
static class DesktopWindowsStuff
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetWindowText",
ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpWindowText, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows",
ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool EnumDesktopWindows(IntPtr hDesktop,
EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
private delegate bool EnumDelegate(IntPtr hWnd, int lParam);
private static List<IntPtr> WindowHandles;
private static List<string> WindowTitles;
public static void GetDesktopWindowHandlesAndTitles(
out List<IntPtr> handles, out List<string> titles)
{
WindowHandles = new List<IntPtr>();
WindowTitles = new List<string>();
if (!EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero))
{
handles = null;
titles = null;
}
else
{
handles = WindowHandles;
titles = WindowTitles;
}
}
private static bool FilterCallback(IntPtr hWnd, int lParam)
{
StringBuilder sb_title = new StringBuilder(1024);
int length = GetWindowText(hWnd, sb_title, sb_title.Capacity);
string title = sb_title.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(title) == false)
{
if (IsIconic(hWnd) == false)
{
{
WindowHandles.Add(hWnd);
WindowTitles.Add(title);
}
}
}
return true;
}
}
}
But this gives some window names which are not open. For example its giving "Windows ShellExperienceHost", which running in task manager. and photos which is under suspended state in task manager.
My intention is simple to list open windows (excluding minimized windows).
How to get rid off these kind of errors ?
Please help me.
|
|
|
|
|
|
can you please edit my code..Sorry I am new to .net and I am not getting how to use EnumWindows
|
|
|
|
|
There are plenty of examples here[^].
This space for rent
|
|
|
|
|
Have you found solution for this issue ? I am facing similar issue.
|
|
|
|
|
I have created a Retry function (using Rx with Rx-main and Rx-xaml packages from NuGet) that uses a timer to Retry the function if an error appears, but if it is not successful within a given timeframe, the presses is aborted.
I use the functiuon like shown below:
textBox.Text = "";
Thread.CurrentThread.Name = "UI Thread";
IScheduler thread1 = new NewThreadScheduler(x => new Thread(x) { Name = "Thread1" });
TimeSpan RetryMaxTime = new TimeSpan(0, 0, 0,0,5);
Observable.Create<int>(o =>
{
Console.WriteLine("Created on " + Thread.CurrentThread.Name);
o.OnNext(1);
o.OnError(new Exception("Something random just happened"));
o.OnCompleted();
return Disposable.Create(() => { });
})
.SubscribeOn(thread1)
.Retry(RetryMaxTime)
.ObserveOnDispatcher()
.Subscribe(
x =>
{
textBox.Text += x.ToString() + Environment.NewLine;
}
, ex => textBox.Text += ex.Message
, () => { textBox.Text += "Completed on " + Thread.CurrentThread.Name; }
);
}
Basically, I used the WeakSubscription code to create the function:
public static class MyExtensions
{
public static IObservable<TItem> Retry<TItem>(this IObservable<TItem> collection,TimeSpan ExceptionTimeout)
{
return Observable.Create<TItem>(obs =>
{
var weakSubscription = new WeakSubscription<TItem>(collection, obs, ExceptionTimeout);
return () =>
{
weakSubscription.Dispose();
};
});
}
public class WeakSubscription<T> : IDisposable, IObserver<T>
{
private readonly WeakReference reference;
private readonly IDisposable subscription;
private Exception LastError;
private bool EndRetry = false;
private bool disposed;
private System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public WeakSubscription(IObservable<T> observable, IObserver<T> observer, TimeSpan ExceptionTimeout)
{
this.reference = new WeakReference(observer);
var interval = Observable.Interval(ExceptionTimeout);
interval.SubscribeOn(Scheduler.CurrentThread).Subscribe(x =>
EndRetry = true);
this.subscription = observable.Retry()
.Catch<T>(e=>e)
.Subscribe(this);
}
IObservable<T> ExceptionHappened(Exception ex)
{
return null;
}
void IObserver<T>.OnCompleted()
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnCompleted();
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnError(Exception error)
{
var observer = (IObserver<T>)this.reference.Target;
LastError = error;
if (observer != null)
observer.OnError(error);
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnNext(T value)
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnNext(value);
if (this.EndRetry)
this.Dispose();
}
public void Dispose()
{
if (!this.disposed)
{
this.disposed = true;
this.subscription.Dispose();
}
}
}
}
As you can see, if the operation is unsuccessful after the tries, I'd like to get the Exception that was thrown inside the Retry function. My question is simply, how can I get the error thrown, or is there a better way of doing this altogether?
|
|
|
|
|
Suppose I have TABLE with the following fields:
Quantity [number]
Price [Number]
Returns [bool]
If Returns = true, then - ([quantity][Price])// negative returns
If Returns = false, then ([quantity][Price]) // positive returns
Question using SQL Server 2005:
Inquiry following his error was in command IIF:
[CODE]
SELECT quantity, Price, Returns, IIF ([Returns] = 0, ([quantity][Price]), (-1)([quantity]*[Price])) As Total
FROM TABLE;
[/CODE]
SQL Syntax Errors Encountered:
The following errors were encountered while parsing the contents of the SQL pane:
Error in list of function arguments: '=' not recognized. Unable to parse query text.
|
|
|
|
|
Wrong forum - this is for C# queries, not SQL. In future use this: Database Discussion Boards - CodeProject[^] or this: http://www.codeproject.com/Questions/ask.aspx[^]
But...try this:
SELECT quantity, Price, [Returns], (quantity * Price) * CASE WHEN [Returns] = 0 THEN 1 ELSE -1 END As Total FROM MyTable; Or if Returns is a BIT column:
SELECT quantity, Price, [Returns], (quantity * Price) * (1 - [Returns] * 2) As Total FROM MyTable;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Your good example, especially your 2nd query, I do not think writing like this that runs smoothly: (quantity * Price) * (1 - [Returns] * 2) As Total
Your very good example, Thank you very much.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Below code need to implement to measure the angle in a image. but after stretching the image found the mouse click position and line starting position is not correct.
Line starts some points after the mouse click point. if the image is not stretched no issues
private void pictureBox1_VisibleChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
if (me.Button == System.Windows.Forms.MouseButtons.Right)
{
switch (clickProgress)
{
case 1:
pts[2] = pts[0];
pts[1] = pts[0];
clickProgress--;
break;
case 2:
pts[2] = pts[0];
clickProgress--;
break;
case 3:
clickProgress--;
break;
}
}
if (me.Button == System.Windows.Forms.MouseButtons.Left)
{
if (clickProgress < 3)
{
pts[clickProgress] = me.Location;
if (clickProgress == 0)
{
pts[1] = pts[0];
pts[2] = pts[0];
}
clickProgress++;
}
}
updateBitmap();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (clickProgress > 0 && clickProgress < 3)
pts[clickProgress] = e.Location;
updateBitmap();
}
private void updateBitmap()
{
if (pictureBox1.Image == null)
{
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = bmp;
}
using (Graphics g = Graphics.FromImage(pictureBox1.Image))
{
g.Clear(Color.Black);
if (pic != null)
{
int width = pictureBox1.Width;
int height = pictureBox1.Height;
float scaleW = pictureBox1.Width * 1.0f / width;
float scaleH = pictureBox1.Height * 1.0f / height;
float scale = scaleW;
if (scale > scaleH)
scale = scaleH;
int nw = (int)(scale * width);
int nh = (int)(scale * height);
if (picScaled == null)
{
RectangleF sourceRect = new RectangleF(0, 0, width, height);
RectangleF destinationRect = new RectangleF(0, 0, nw, nh);
picScaled = new Bitmap(nw, nh);
Graphics gi = Graphics.FromImage(picScaled);
gi.DrawImage(
pic,
destinationRect,
sourceRect,
GraphicsUnit.Pixel);
gi.Dispose();
}
{
RectangleF sourceRect = new RectangleF(0, 0, nw, nh);
RectangleF destinationRect = new RectangleF(
pictureBox1.Width / 2 - nw / 2,
pictureBox1.Height / 2 - nh / 2,
nw,
nh);
g.DrawImage(
picScaled,
destinationRect,
sourceRect,
GraphicsUnit.Pixel);
}
}
Pen greenPen = new Pen(Brushes.Green);
greenPen.Width = 3.0F;
Pen redPen = new Pen(Brushes.Red);
redPen.Width = 3.0F;
if (clickProgress > 0)
g.DrawLine(greenPen, pts[0], pts[1]);
if (clickProgress > 1)
g.DrawLine(redPen, pts[0], pts[2]);
redPen.Dispose();
greenPen.Dispose();
}
pictureBox1.Invalidate();
if (clickProgress > 1)
{
Point p0 = new Point(pts[1].X - pts[0].X, pts[1].Y - pts[0].Y);
Point p1 = new Point(pts[2].X - pts[0].X, pts[2].Y - pts[0].Y);
double l0 = (p0.X * p0.X + p0.Y * p0.Y);
double l1 = (p1.X * p1.X + p1.Y * p1.Y);
double d = ((double)p0.X * p1.X + (double)p0.Y * p1.Y) / Math.Sqrt(l0 * l1);
if (d > +1) d = +1;
if (d < -1) d = -1;
if (l0 > 0 && l1 > 0)
label1.Text = (Math.Acos(d) * 180 / Math.PI).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture);
}
else
{
label1.Text = "";
}
}
|
|
|
|
|
Um. What do you suppose PictureBoxSizeMode.StretchImage does?
It takes the image in the Picturebox and "distorts" it to fit the size and shape of the container. That doesn't affect mouse locations within the image, it just affects the image as displayed.
So if you click the mouse on two points in the distorted PictureBox that correspond to the start and end points of a line (on the distorted image) and draw a line (on the underlying image graphics context) using the mouse coordinates it will be drawn as is - the coordinates you draw from and to will not be "mapped" into the distorted image but drawn exactly as you requested on the undistorted image. As a result, they aren't in "the right place" - which is why when you remove StretchImage from the PictureBox it works fine: the coordinates don't change at all, but now they match with the image.
Two options:
1) Don't use StretchImage
2) Convert the mouse location points so they aren't relative to the distorted image. That means looking at the box dimensions, the image dimensions and working out teh X and Y scalign factors you need to apply to "undistort" the click location.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 11-Jun-16 6:58am.
|
|
|
|
|
Hello,
I have a requirement of getting an event when all the Windows are in minimized state. How can I know when all other applications (except mine) are in minimized state using c#?
Please help me.
|
|
|
|
|
As far as I know there is no event that signals this - you can look at each window fairly easily though and enumerate those that are visible: List the currently running desktop windows in C# - C# HelperC# Helper[^] - a couple of small changes there would give you a list of "open" windows. But you'd have to check it periodically yourself.
The other option is a lot more complex, and a lot more fraught with crash-and-burn potential: CBT Hooking. This entails adding a global hook to the system and watching for minimize, restore, and maximize events making their way through. You can do this in C# - though it's not simple - but it's not a trivial task (and I'd back up my PC before I started trying as you can seriously destabilize your system if you get it wrong). Google for "CBT Hooking C#" and you'll find info, if you are brave enough!
[edit]Typo[/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 11-Jun-16 3:27am.
|
|
|
|
|
I am new to c#. The example given by you gives some Titles which are running in system tray and some other titles also, I want window titles which are open but not in minimized state... can you help me where I need to edit the code ?
|
|
|
|
|