Thursday, June 05, 2008

DivX register-app won't start under 64 bit OS

The DivX register app is hardcoded to use the System32 folder as path for Rundll32, which of course doesn't exist on a 64bit system. So when running Vista 64, you'll have to use a command similiar to this:

C:\Windows\Syswow64\rundll32.exe C:\Windows\System32\dtu100.dll,dtuSerialRunDll 7B63B2922B174135AFC0E1377DD81EC2

To start the DivX-regApp

// Lazze

Friday, April 18, 2008

Vista network slowdown when using media apps

Vista throttles networkspeed to keep multimedia viewing glitch free - but they have missed that we'rent using 286's no more...

To disable the "feature"

Regedit:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AudioSrv

Key "DependOnServices" - edit the list, remove "MMCSS"

Quit regedit, start MSCONFIG -> Services -> Disable "Multimedia Scheduler"

Reboot and Njoy networkspeed even when listening to a MP3

// Lazze

Tuesday, February 26, 2008

Resolved networking issues in Vista

Start, Run, CMD to open a command prompt(need to be admin):

Reset TCP/IP stack to installation defaults.

netsh int ip reset reset.log

Reset WINSOCK entries to installation defaults:

netsh winsock reset catalog

Reboot! Finished!

Monday, October 08, 2007

Virtual PC 2007 Console window won' t show

Happened me last nigh, my VPC:s ran just fine but I could only access the console through the traybar.

Evidently, the options.xml file has been damaged, or at least there are faulty values in it.

You have to view hidden systemfiles to find:

C:\Users\UserName\AppData\Roaming\Microsoft\Virtual PC\Options.Xml

find the console section and you will find that the layout parameters are way off, like max(int). Change the left/right etc to 10 or something similar and the window will pop back to the desktop. You must close all VPC:s and console to be able to save the options file.

All creds go to the following blogger,

SJ's Blog

// Lazze

Tuesday, September 25, 2007

Data controls ASP NET 2

When working with the data controls in ASP NET 2 - like GridView and DetailsView you are always best of if you use templated columns. The simplest way to acomplish this is to start of with DataBound fields then just right click them and choose "Convert to template field.

There are two major reasons for using templated fields:

1. You get predictable names, like CTL_MyView_TemplatefieldName - which is good if you need to access them via Javascript.

2. From code behind you can get your fields like this:

TextBox t = (TextBox) ((DetailsView)sender).FindControl("tbStatusDetailTemplate");

// Lazze

Sunday, September 09, 2007

Application Wide(Windows Forms) - capture Keys(like functions keys)

1) Define constants

const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;

2) Add interface, IMessageFilter

public partial class Form1 : Form, IMessageFilter

3) Make message interceptor

public bool PreFilterMessage(ref Message m)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if (m.Msg == WM_KEYDOWN && keyCode == Keys.F8) // We'll just handle F8 here
{

MessageBox.Show("Key: " keyCode.ToString());
return true;
}
return false;
}

4) Add message interceptor to forms message handling(in Forms constructor)

Application.AddMessageFilter(this);

Enjoy!

//Lazze

Wednesday, June 13, 2007

Loop through splitcontainer in Winforms

Control ctl = splitContainer1.GetNextControl(splitContainer1 , true);
while (ctl != null)
{
//Do something with ctl
ctl = splitContainer1.GetNextControl(ctl, true); }
}

Tuesday, June 12, 2007

ICO PNG

Want some flashy icons on your desk?

This nifty program converts PNG -> ICO or ICO -> PNG

100% free!

Get it here!

Sunday, June 03, 2007

WCF

This gave me some headace:

netsh http add urlacl url=http://+:8000/ServiceModelSamples/service/ user=lsiden

You have to run the above command(Vista) to grant HTTP on URL xxx for user XXX before you can start a WCF-server.

If you use DualHTTP you have to open the firewall for the incoming requests from the client.

Read more:

Here

and here

Sunday, May 13, 2007

Directory.GetDirectories without getting Unauthorized errors

foreach (string dir in Directory.GetDirectories(@"c:\"))
{
DirectoryInfo di = new DirectoryInfo(dir);
if ((di.Attributes & FileAttributes.System) == 0)
dirList.Add(dir);
}

DirectoryInfo.Attributes is a Flag enum list so you can't just check for equality. Using the above code makes it more or less safe :-)

Tuesday, May 16, 2006

Smart refence state class for web apps

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;

public partial class _Default : System.Web.UI.Page
{
MyState _state = null;

protected void Page_Load(object sender, EventArgs e)
{
this._state = MyState.Init(this.Session);
}
protected void Button1_Click(object sender, EventArgs e)
{
this._state.Antal += 1;
_tbAntal.Text = this._state.Antal.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
this._state.Antal += 3;
_tbAntal.Text = this._state.Antal.ToString();
}
}

class MyState
{
const string _name = "{1374BFDE-B051-4fa3-8A7A-E506233B2AB6}";

public int Antal = 0;

public static MyState Init( HttpSessionState state )
{
MyState s = null;
if(state[_name] == null)
{
s = new MyState();
state[_name] = s;
}
else
s = state[_name] as MyState;

return s;
}
}

Visual Studio 2005 Web Application Projects

Web Application Projects provide a companion web project model that can be used as an alternative to the built-in Web Site Project in Visual Studio 2005. This new model is ideal for web site developers who are converting a Visual Studio .Net 2003 web project to Visual Studio 2005. (Released May 8, 2006)


More info

Friday, May 12, 2006

Week of year

Updated post that works for Sweden:

private static int WeekNumber_Entire4DayWeekRule( DateTime date )
{
// Updated 2004.09.27. Cleaned the code and fixed a bug. Compared the algorithm with
// code published here . Tested code successfully against the other algorithm
// for all dates in all years between 1900 and 2100.
// Thanks to Marcus Dahlberg for pointing out the deficient logic.
// Calculates the ISO 8601 Week Number
// In this scenario the first day of the week is monday,
// and the week rule states that:
// [...] the first calendar week of a year is the one
// that includes the first Thursday of that year and
// [...] the last calendar week of a calendar year is
// the week immediately preceding the first
// calendar week of the next year.
// The first week of the year may thus start in the
// preceding year
const int JAN = 1;
const int DEC = 12;
const int LASTDAYOFDEC = 31;
const int FIRSTDAYOFJAN = 1;
const int THURSDAY = 4;
bool ThursdayFlag = false;

// Get the day number since the beginning of the year
int DayOfYear = date.DayOfYear;

// Get the numeric weekday of the first day of the
// year (using sunday as FirstDay)
int StartWeekDayOfYear = ( int ) ( new DateTime ( date.Year, JAN, FIRSTDAYOFJAN ) ).DayOfWeek;
int EndWeekDayOfYear = ( int ) ( new DateTime( date.Year, DEC, LASTDAYOFDEC ) ).DayOfWeek;

// Compensate for the fact that we are using monday
// as the first day of the week
if( StartWeekDayOfYear == 0 )
StartWeekDayOfYear = 7;
if( EndWeekDayOfYear == 0 )
EndWeekDayOfYear = 7;

// Calculate the number of days in the first and last week
int DaysInFirstWeek = 8 - ( StartWeekDayOfYear );
int DaysInLastWeek = 8 - ( EndWeekDayOfYear );

// If the year either starts or ends on a thursday it will have a 53rd week
if( StartWeekDayOfYear == THURSDAY || EndWeekDayOfYear == THURSDAY )
ThursdayFlag = true;

// We begin by calculating the number of FULL weeks between the start of the year and
// our date. The number is rounded up, so the smallest possible value is 0.
int FullWeeks = ( int ) Math.Ceiling( ( DayOfYear - ( DaysInFirstWeek ) ) / 7.0 );

int WeekNumber = FullWeeks;

// If the first week of the year has at least four days, then the actual week number for our date
// can be incremented by one.
if( DaysInFirstWeek >= THURSDAY )
WeekNumber = WeekNumber +1;

// If week number is larger than week 52 (and the year doesn't either start or end on a thursday)
// then the correct week number is 1.
if( WeekNumber > 52 && !ThursdayFlag )
WeekNumber = 1;

// If week number is still 0, it means that we are trying to evaluate the week number for a
// week that belongs in the previous year (since that week has 3 days or less in our date's year).
// We therefore make a recursive call using the last day of the previous year.
if( WeekNumber == 0 )
WeekNumber = WeekNumber_Entire4DayWeekRule( new DateTime( date.Year-1, DEC, LASTDAYOFDEC ) );

return WeekNumber;
}

Friday, March 24, 2006

Winform 2.0 annoyance on XP

Having problems seeing your design when running you windows forms app on XP? Looks good in VS design, but colorless and dull in runtime?

Then you need to make this fix to the main method:

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
// Calling DoEvents after the above method call seems to fix this issue
Application.DoEvents();
Application.Run(new Form1());
}

// Lazze

Saturday, February 25, 2006

First blog first time

Howdy,

As they say - It is a first time for everything!

I'll try to compose myself and publish some good stuff about .NET programming (C#) and maybe some general PC/Hardware stuff!

Good to be here!

//Lazze

Lazzes Smart Home - 2023

Here is an overview of the components in the Smart Home as of now. More stuff than I tought :-)