by Jim
Nov 16, 2006 9:00 AM
It's been driving me nuts that I couldn't rearrange the favorites in IE7 by dragging them around in the Favorites Center. I had to open the Organize Favorites dialog. I finally found the answer by posting to a thread on the Microsoft discussion groups.
Turns out Roxio was breaking my favorites. I had to disable their DriveLetterAccess addon, and everything works. I didn't even know I had that; it installed with "Creator Plus," aparently, which came with the machine. I opened Creator for the first time just now, out of curiosity.
It crashed.
by Jim
Nov 08, 2006 11:07 PM
Pretend for a second that ReadToEnd() isn't a bad way to parse an HTML file from code. I'm doing a little screen-scraping here, and thinking I had a problem with my regular expression. It took me a while to realize that I didn't have the whole file.
The page is only 4K, and IE and Firefox download the page just fine, showing the full source. Recalling my experiences with downloading shortcut icons, it occured to me that the Content-Length header could be incorrectly reporting the length. Sure enough, that was it.
WebClient and HttpWebRequest (which probably use the same underlying code) both return a stream that is limited to the length in the Content-Length header, regardless of the actual length of the page. I don't think there's a way to get the whole page with these classes. If I want to screen-scrape this, I'll probably need to use lower-level code that can ignore the headers. Bummer.
// Get the html
try
{
strm = Client.OpenRead(page);
// won't read the whole file if length is short in the header
Debug.WriteLine(string.Format("Content-Length: {0}",
Client.ResponseHeaders["Content-Length"]));
// Doesn't matter if we wrap the stream with reader or call ReadByte()
// on the raw stream.
sr = new StreamReader(strm);
html = sr.ReadToEnd();
Debug.WriteLine(html);
sr.Close();
/*
// This doesn't work either
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(page);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
strm = resp.GetResponseStream();
sr = new StreamReader(strm);
html = sr.ReadToEnd();
Debug.WriteLine(html.Length);
sr.Close();
resp.Close();
*/
}
But IE and Firefox work fine! They are programmed to recover from just about any screw up that the server might make. While trying to download website icons, I found that they would recognize an icon if the headers reported an incorrect content type, among other things.
If you point IE at a URL, and a stream comes back, IE will figure out what's going on.
by Jim
Nov 04, 2006 11:17 PM
Getting the location of the system tray from vb.net or C# isn't terribly hard. But it isn't documented either, so figuring it out takes a little research. The trick here is knowing the names of the taskbar and system tray windows. This can be discovered using the Spy++ tool. For those of you who don't remember the days before .NET, Spy++ is in your Visual Studio tools folder in the start menu. It was once very handy, but I don't remember the last time I used it.
Private Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Ansi Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
Private Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Private Function GetSystemTrayLocation() As Rectangle
'Get the location of the system tray
Dim rect As New RECT
Dim retval As Rectangle = Nothing
Dim hTaskbarHandle As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
If hTaskbarHandle <> 0 Then
Dim hSystemTray As IntPtr = FindWindowEx(hTaskbarHandle, IntPtr.Zero, _
"TrayNotifyWnd", Nothing)
If hSystemTray <> 0 Then
GetWindowRect(hSystemTray, rect)
retval = Rectangle.FromLTRB( _
rect.left, rect.top, rect.right, rect.bottom)
End If
End If
Return retval
End Function