Programming magic, glory, and juices.

SetForegroundWindow, Bringing Window To Top

October 2nd, 2009


When using SetForegroundWindow/SetActiveWindow sometimes it does not bring the window into the foreground window. There is a great article on Dr. Dobb’s Journal that explains why this happens and how you can bring your window into the foreground.

HWND ForegroundWindow;
HWND BringToForegroundWindow;
DWORD ForegroundWindowThread;
DWORD BringToForegroundThread;

// Set BringToForegroundWindow

ForegroundWindow = GetForegroundWindow();
ForegroundWindowThread = GetWindowThreadProcessId(ForegroundWindow, NULL);
BringToForegroundThread = GetWindowThreadProcessId(BringToForegroundWindow, NULL);

AttachThreadInput(ForegroundWindowThread, BringToForegroundThread, TRUE);
SetForegroundWindow(BringToForegroundWindow);
AttachThreadInput(ForegroundWindowThread, BringToForegroundThread, FALSE);
SetActiveWindow(BringToForegroundWindow);

Nvidia Drivers Break Remote Desktop AGAIN!

January 20th, 2009


These are supposed to be WHQL’ed drivers!! You think they would check to make sure that remote desktop works after installing them. It happed in version 175.16 and now again in 180.48. Nvidia is putting a bad taste in my mouth. They have been known for long time for their great drivers (at least compared to ATI) and now I am not so sure anymore. You break my remote desktop once, shame on you, you break it twice, shame on me.

Tips For Setting Up A Torrent Box

January 7th, 2009


Keeping these things in mind here are some tips for setting up and configuring a torrent box.

The torrent box should..

  • Downloads torrents automatically
  • Run in the background and not hog your network resources
  • Consume as little power as possible (power = money)

We’ll also assume that we don’t want to ever delete what we download. If need be we can just archive old torrents to separate drives.

Hardware

  • Buy a case that is expandable. You want a case where you can expand it if you run out of disk space on your hard drives. For example Lian-Li sells a PC-A17 which can be expanded to hold up to 9 hard drives. That would allow you to hold at least 9 TB of data.
  • If you do plan on using more than 5 hard drives in your case I would recommend a Corsair power supply with modular cabling. In the case that you need extra SATA power connectors, Corsair will send them to you free of charge, you just have to email them.
  • Buy a motherboard with on board video (your not going to be gaming on this machine). During the initial setup of the torrent box you’ll probably need to connect a monitor to the computer. However, once it is setup you can store it somewhere else in your house and just connect to it via remote desktop. A dedicated video card will just end up consuming more power and if you are going to be using remote desktop, then it isn’t even needed. In the case that you do run into a problem then just connect a monitor to the onboard video and fix it.
  • Don’t buy an internal cd-rom drive, what’s the point? Buy an external USB cd-rom drive and sell all your internal cd-rom drives on eBay. An internal cd-rom drive will most likely never be used for your torrent box except when installing Windows. If you just have one external USB cd-rom drive you can share it between multiple computers.
  • Put tape over your case lights. It is annoying to watch them blink when the lights are turned off and it can distract you when watching movies if you put your torrent box in your living room.

Configuration

  • Use AutoLogon.exe from SysInternals. So that your computer automatically logs in. If something happens and your computer unexpectedly reboots or crashes, it will automatically log you back in so it can continue downloading torrents.
  • Have uTorrent start up when the system logs in. Put uTorrent in under Startup under the Programs menu in Windows.
  • Turn off Automatic Updates. Yes, turn it completely off. Having Automatic Updates turned on restarts your computer every so often and disrupts the downloading process. When your computer restarts from Automatic Updates it is just another opportunity for your machine to not properly boot back up.
  • If you have multiple hard drives make sure you manually specify in the BIOS the boot priority, don’t leave it up to fate to decide which hard drive has the boot priority.
  • Get rid of your antivirus program. You’ll have so much hard drive activity on your computer that a weak antivirus program is only going to hurt things. Plus, if you only download from approved sources of plunder, then there is no need for antivirus.
  • Turn off all Services in Administrative Tools that are not needed.
  • Setup uTorrent to download all torrents to your primary hard drive. When something gets old then archive it to another drive.

Bandwidth

  • Know what your up/dl capacity is. Don’t buy 20Mbps connection from Cox cause you’ll only get 20Mbps down 1% of the time. If you leave things going on in the background, it will all download given enough time.
  • Rate limit your upload speed. Put it at like 20-40 KBps upload speed. You don’t want your torrenting to intrude on your browsing, you want everything running in the background. As for downloading speed, you can just set it to Unlimited.
  • Don’t worry about your ratio (especially if you are one of those people who reset their IP daily). These things have a way of working themselves out. You’ll be on so many trackers that ratio means nothing.

RSS

Add RSS feeds to uTorrent, so you don’t have to manually select the torrents you want downloaded. If you have a problem downloading everything just set filters to download only certain shows from the RSS feeds. Here are some example feeds.

http://tvrss.net/feed/eztv/?nostats&num=250

http://www.mininova.org/rss.php?user=aXXo&direct&nostats

http://www.mininova.org/rss.php?user=KLAXXON&direct&nostats

http://www.mininova.org/rss.php?user=kingben666&direct&nostats

The Mininova nostats parameter will remove the leecher and seed information from the item title, so that uTorrent won’t unexpectedly try to redownload the same shows thinking they are different because the stats have changed. Also notice the ‘num’ parameter. In the case that your torrent box does go down for a couple of days, setting the ‘num’ parameter to say 250, causes it to check several days worth of torrents.

Also I would recommend adding these to the RSS NOT list in uTorrent as well as anything else you can think of that is total crap.

*World.Series.Of.Poker*|*Poker*|*UFC*|*WWE*|*Chopper*|*ECW*|*Ink*|*UFC*|*Top*Model*|*Ultimate*Fighter*|
*Prix*|*Friday*Night*|*MMA*|*Tattoo*|*Ink*|*Bachelor*|*Stern*|*Mercer*|*Singing*Bee*|*Boxing*|*Survivor*|
*x*factor*|*Runway*|*Dancing*|*Girlfriends*|*Big*Brother*|*Bill*Maher*|*Daily*Show*|*Colbert*|

Watching

The best way to watch the videos that you download is by streaming it across the network. At one point I explored the different ways to stream video across a network and I found that using an XBOX 360 is the best way. So, buy an XBOX 360! Use it to stream your videos across the network. It is easy! Just share a folder on your torrent box through Windows Media Player Sharing, go into XBOX and you’ll see that folder and all the videos. XBox has support for most of the major codecs which makes using it really easy.

However, if you are too cheap to buy an XBOX 360, their exists a Philips DVD player that allows you to connect a USB device to, to watch videos on it. Just get a 8 GB USB flash stick and load the shows on it that you want to watch then stick the USB flash stick into the DVD player and you should be able to view all the videos on it.

Error Handling and Exceptions

January 5th, 2009


I’ve been attempting to port an application to C# using SharpZipLib, which I might end up reconsidering.

One thing I find kind of difficult to deal with is the fact that SharpZipLib throws exceptions when an error occurs. For example, if you have a zip file and it has multiple compressed files within it, if there is an error extracting one of those files, it throws an exception, which makes it hard to continue attempting to extract the next compressed file in the archive.

Which brings me to the question, why use an exception over returning an error code in C#?

It is annoying that functions throw exceptions. As a programmer, when I call a function, I don’t expect it to throw an exception. I expect a function to return true if it succeeded and false if it failed. I mean should I have to put a try-catch loop around every function that I call in C#? It is kind of ridiculous.

I mean who are exceptions meant for but for programmers? Isn’t the information that is thrown in an exception better for a debug log?

Thoughts on Christmas

December 23rd, 2008


I am a Christian and I hate Christmas!! Thank God I am not the only one that hates it. Growing up we celebrated Christmas. However over the years I’ve come to loath it.

It is a tradition that is in no way biblical. Jesus wasn’t even born on Christmas day. I think if you are going to celebrate the birth of Christ, you should celebrate it accurately. And yes, it is possible to know when Jesus was born. A quick Google search will tell you that he was born on the Feast of the Tabernacles. If I were to celebrate any holiday during the winter it would have to be Hanukkah, because it at least has some biblical significance.

We used to do Christmas gifts, however I’ve decided to never do them again, if that is at all possible, with the commercialization of Christmas, it makes it hard. Furthermore I’ll make sure that everybody that I spend time with during Christmas knows that I don’t do gifts and I don’t celebrate Christmas. I’ll gladly receive a gift out of respect however I won’t give one. It’s not that I am poor, it is that I won’t celebrate Christmas anymore.

Christmas trees, I hate them and will never have one in my own house, fake or real. I honestly don’t have time to put up a Christmas tree and there is a verse in the bible that talks against ornating trees in Jeremiah 10:2-4.

As for all that Santa talk, I will teach my children the truth – that Santa is a fraud. Then I’ll tell them that if they so happen to receive a gift, that it is not from Santa — it is from me. Why should Santa get all the credit for me spending my hard earned money on gifts for my children? If my children so happen to go to school and inform other people’s children that Santa is a fraud, then good for them.

Holidays for me are just times that I get to spend with my family. I don’t need a tree, a gift, or a jolly ol’ saint nick to make me want to spend time with them.

PowerShell – Touching Files

December 21st, 2008


Had to use PowerShell to touch a bunch of files, because a certain piece of software, would only read them in the order in which they were last modified. I renamed all the files so that they were alphabetically in the order I wanted the program to process them. Then I ran this script which assigned last modified times to each of the files so that the program would read the files in alphabetical order.

$i = 0; foreach ($file in get-childitem | sort Name)
{ $file.LastWriteTime = [datetime]::Now.AddMinute($i); $i += 1; }

Windows Media Player Monitoring Folders or NOT!

August 16th, 2008


Sharing media across a network should be easy, I mean it is 2008 for God sakes! One problem I ran across recently with Windows Media Player is that it simply does pick up all the file changes in the folders that it is monitoring. Specifically, Windows Media Player won’t add new media from the folders it is monitoring when the media file becomes available by renaming. It works perfectly fine when you copy or move the file into the folder that is being monitored. But when that file already exists with an unknown extension and is then renamed with a media extension the change isn’t detected by Windows Media Player and so the file isn’t added to your media library and isn’t available for viewing across the network.

I encountered the problem when I had uTorrent downloading files into a folder that was being monitored by Windows Media Player. In uTorrent I had the files created with the “.!ut” extension. Then when the download was completed uTorrent would simply rename the file from “.!ut” to “.wmv” or whatever the original extension was. So when the file is first created by Windows Media Player it looks at it and sees that it is a “.!ut” extension and doesn’t know what to do with it. Then when the file is renamed Windows Media Player simply doesn’t monitor the change. And so the only way to get Windows Media Player to add the file into the media library is to go into the user interface and force it to manually update and if that doesn’t work then to restart the Windows Media Player Network Sharing service.

However I’ve come up with a solution and that is to use uTorrent to save the new downloads in a separate folder and then move them over into the folder that Windows Media Player is monitoring once the download is complete. So in uTorrent if you goto Preferences->Directories and check “Put new downloads in” you could set it to “c:\incomplete\” and then set “Move completed downloads to” say “c:\downloads\”. You might also want to turn off the option in Preferences->General for “Append .!ut to incomplete files” cause I never tested it with it on since there is no need to have it on since all incomplete files are in a totally separate folder.

At the time it was really annoying to have to manually force Windows Media Player to update the media library. I checked Google several times with no answers. I came to the end of my ropes, but when I finally figured out why the heck Windows Media Player wasn’t doing its job it was like a light blub turned on inside my head. Was all of this by design? Who knows. Who cares. It works now and that is all that matters.