SurplusCode

C#, PHP, CSS, DHTML, AJAX

Windows Live Writer

Monday
May 5,2008

So it has been more than a while since I have posted anything here, but what can I say. Life gets busy and you forget about things that are low in priority. If it wasn’t for the fact that I have a lifetime account with TextDrive, this site would have been taken down months ago.

In any case, I’m back, at least for this one post. I just wanted to test out blogging with Windows Live Writer. I have used it to test on two other sites (Live Spaces and Wordpress.com), and I wanted to see how it worked with my own install of WordPress.

If things go well, I may start to blog more on SurplusCode on the different programming and technical related projects.

  • Comments Off
  • Thursday
    Nov 2,2006

    I’ve recently needed to find what control currently has focus in my WinForms application. Google gave me two answers. The first depends on unmanaged code, and the second is fully managed.

    Reference
    [csharp]
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern IntPtr GetFocus();

    private Control GetFocusedControl()
    {
    Control ctl = FromHandle(CreateProjectPanel.GetFocus());

    //MessageBox.Show(ctl.Name);

    return ctl;
    }
    [/csharp]

    I can’t remember where I found this second solution, but it is the one I use in my code. It uses the Control.Focused and Control.ContainsFocus properties to recursively find the focused control.
    [csharp]
    private System.Windows.Forms.Control GetFocusedControl(System.Windows.Forms.Control.ControlCollection Controls)
    {
    // store focused control…
    foreach (System.Windows.Forms.Control clsControl in Controls)
    {
    if (clsControl.Focused)
    {
    return clsControl;
    }
    if (clsControl.ContainsFocus)
    {
    if (clsControl.Controls.Count == 0)
    {
    return clsControl;
    }
    else
    {
    return GetFocusedControl(clsControl.Controls);
    }
    }
    }
    // no focus…
    return null;
    }

    // usage
    Control hasFocus = GetFocusedControl(this.FindForm().Controls);
    [/csharp]

  • Comments Off
  • Update: Web page thumbnail maker

    Monday
    Oct 16,2006

    Executable: Thumbnailer-0.2.zip
    Source: Thumbnailer_src-0.2.zip

    I have released a new version of my web page thumbnail creator. I modified the UI up a bit and included the thumbnail control within a web browser that I found on CodeProject. I thought this would be better than just typing the URL (or copy/paste) into a text field. Sometimes I found myself navigating around and then making a thumbnail.

    thumber_textdrive

    Also, I believe I have fixed the “white page” thumbnail issue. I am not quite sure what causes it, but it seems to happen on more “dynamic” sites, such as espn.go.com and nytimes.com. I think it has to do with IFrames and how it is used on that particular site. Either way, I have fixed it so that this problem doesn’t occur as often as it did. You can look at the source if you want more information. (requires Visual Studio 2005).

    Executable: Thumbnailer-0.2.zip
    Source: Thumbnailer_src-0.2.zip

    Samples

    ajaxian.com

    www.textdrive.com

    nytimes.com

    www.yahoo.com

    And for those of you who don’t want to download the .NET framework, I found Webshot, a free Windows app that does just about the same thing as my thumnail maker.

    Friday
    Sep 22,2006

    I don’t remember why, but for the longest time I have been searching for a tool or code that would allow me to create a screen shot and thumbnail of an entire web page. Lately, I have been using Cropper, as well as the old ”Print Screen” and cropping the image in Photoshop technique. This normally does the job. But what if the web page is rendered to be taller than the available screen height?

    I am sure there is a tool that does what I am looking for, but I haven’t found it yet…until today. Well, I almost found it. What I found instead was two articles on Code Project. And then after a couple hours in Visual Studio, presto-chango, I give you the Web Page Thumber.

    It’s actually just a prototype, built on top of dooskoobi’s “Webpage Thumbnailer“ source code. Credits also go to a reply comment by gimenezparera to Douglas M. Weems’ “Image Capture Whole Web Page using C#” article. This last one pointed me to the System.Windows.Forms.WebBrowser component, specifically using WebBrowser.Document.Body.ScrollRectangle.Height to find the rendered web page height.

    I have  provided an executable download of my hacked version of the Webpage Thumbnailer. You will need .NET 2.0 Framework or redistributable package  installed.

    Executable: Thumbnailer.zip

    The interface should be fairly straightforward, but here are a couple tips. ”Browser Width” is the width of the browser to render the web site at when the full size screen shot is taken. This is useful if you want to get a thumbnail/screen shot at different resolutions to see if the content shifts or not. To “Save a thumnail”, right-click on the image (or double-click on it). Currently, it only supports png as the output format.

    One big note, it does NOT work with all web sites. I don’t know why, but it just doesn’t. I will take a look at it when I have more time.

  • Comments Off
  • Saturday
    Sep 9,2006

    I installed a newer version of VistaDB 2.x than what is in SourceSafe and in my project’s reference, and when I tried to run the app in Visual Studio 2005, it was asking me for the newer version of VistaDB.Provider.dll (2.20.25.0). And since my project only had reference to 2.20.22.0, it was a no go.

    I spent an hour or two uninstalling the newer version, searching for and getting rid of all the new dlls, and verified all remaining VistaDB dlls on my hard drive to be the correct versions. It still didn’t work.

    I finally fixed the problem when I searched the registry for the offending newer version, and removed references to it. Specifically the unwanted registry keys are found below:

    HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Fusion \ PublisherPolicy \ Default \ policy.2.[11 or 20].vistadb.provider__7e75aae290f30672

    Simply remove any reference to your unwanted versions. I deleted my exact keys before I wrote it down, so I can’t tell you what they were. Also, I guess you can just search the registry for the “bad” version of the VistaDB.Provider.dll using just the version number. Again, in my case, it was 2.20.25.0

  • Comments Off
  • Friday
    Sep 8,2006

    I’ve downloaded this app from Code Project last night, and so I thought I would use it to make a post. Here’s a snippent of the what the app does.

    RSS Feeder.NET is a free open source desktop RSS feed aggregator which downloads feeds from web sources and stores them locally for offline viewing, searching and processing. It is also a rich blogging tool which you can use to blog a variety of blog engines including WordPress, B2Evolution, .Text, Community Server etc. You can be fully MS Outlook® dependent or can run fully standalone. You can also use both at the same time whichever you find comfortable to work with. It does not increase the Outlook load time, nor does it make the Outlook slow or prevent it from closing properly. It is a Smart Client that makes best use of both Local Resource and Distributed Web Information sources.

    I’m building a smart client of my own, and I hope this will be a decent example to follow. I am still going with the Compsite UI Application Block (CAB), so we’ll see if I can integrate what I learn from RSS Feeder.NET and what I have been doing with CAB for the last six months.

    Also, I will look to improve this app so that I can use it to post to SurplusMeat without having to use a web browser. A very good feature set has already been implemented, but I think I have a few more ideas on how to improve it (spell check, live preview, post to multiple blogs).

     

  • Comments Off
  • Tuesday
    Jun 27,2006

    I rolled my own dialog in WinForms 2.0 and wanted to use the images that is available when using the MessageBox by way of the MessageBoxIcon enum. To do what I wanted, I used the System.Drawing.SystemIcons class, which exposed static references to several system icons, of course. Here’s an example use of the Warning icon in a PictureBox:

    [csharp]
    System.Windows.Forms.PictureBox pb = new System.Windows.Forms.PictureBox();
    pb.Location = new System.Drawing.Point(14, 7);
    pb.Size = new System.Drawing.Size(48, 41);
    pb.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
    pb.BackgroundImage = System.Drawing.SystemIcons.Warning.ToBitmap();
    [/csharp]

    System.Drawing.SystemIcons also has Application, Asterisk, Error, Exclamation, Hand, Information, Question, Warning, and WinLogo.

    The System.Drawing namespace also has SystemBrushes, SystemColors, SystemFonts, and SystemPens.

  • Comments Off
  • Friday
    Jun 16,2006

    I just checked my web site reports on nextSTAT, and noticed that I already have one “real” visitor since I setup SurplusMeat earlier this week.

    First Visit to SurplusMeat.com

    The visitor did a search on technorati.com using the term “shawn burke”. And referring to the visitor details image, it appears that the visit originated from Microsoft Corp. Putting my detective hat on, I am most certain that the visitor was Mr. Burke himself or someone with very close ties to him. Interesting….

    Read the rest of this entry »

  • Comments Off
  • Thursday
    Jun 15,2006

    I was asked by our user interaction designer to make Enter key presses mimic a Tab key press by moving focus to the next control where TabStop=true. Sounds simple enough. But after several fruitless searches on Google, I thought I would have to resort to using unmanaged code. Luckly, I finally found a blog post with the answer that I was looking. Well, the post itself didn’t solve my problem, but the comments pointed me in the right direction.

    The initial suggestion to override the form’s OnKeyUp event doesn’t apply to my case because my text fields were in a panel. ProcessKeyTab is a protected method that can only be called when you extend a control that is derived from ContainerControl, such as Form or Panel. Since I didn’t extend the Panel I was using, I couldn’t call ProcessKeyTab.

    After reading the comments, I found that the answer lies in using the static SendKeys.Send method. In each TextBox that you want to treat Enter as Tab, simply handle the KeyPress event and call SendKeys.Send(”{TAB}”) if the key pressed is an Enter key.

    Read the rest of this entry »

  • Comments Off
  • Upgraded to WordPress 2.0.3

    Wednesday
    Jun 14,2006

    SurplusMeat is now running version 2.0.3 of WordPress. I haven’t noticed any bugs or problems yet. I’m still running version 2.0.2 on my local development box and on MetricsPad.

    Also, I switched my theme to Hemingway Reloaded by WordpressLab. I chose it for its simplicity and liquid layout. Aside from the mods I’ve already made, I plan to give it a little bit more color and usability. I’ve already started by giving some of the anchor tags (and their hover states) the traditional blue hyperlink color.

    <soapbox>
    No offense to the original designer or all the “designers” out there, but why do they insist on making links hard to spot quickly. The blue text with underline just screams click me. Well, it doesn’t have to be blue, but you get the point. And while I’m on my soap box, why do so many sites make their default font size so small. For example, I visit Shaun Inman’s blog on a regular basis, and with each visit, I have to press Control + (plus sign) a couple times in Firefox to get the text size big enough so that I can actually read it. I understand that my monitor is set at a high resolution (1600×1200 at least), but Shaun is a smart guy. He can figure out that I’m at a high rez and offer me a different style sheet that makes his great content more readible by default.
    </soapbox>