Thursday, March 23, 2006

Scroll in .Net user control.

Scroll in a user control is a pretty tricky. I used to have to override the WndProc procedure and call OnVScroll and OnHScroll there. It is not bad. But the whole idea of .Net is RAD,if you have to put a lots of P/Invoke methods, that defeats the whole idea.

I spent some time to do it in managed way. A couple of steps I have to follow is :

1> I have to set the AutoScroll = true.
2> I have to set the AutoScollMinSize to the drawing bitmap size. That way, if the client rectangle is smaller than this one. The scroll bar will show up.
3> Another feature I requested is programmatically scroll, when the mouse is moving out the client area, it should scroll the control. For this, I have to manually set the AutoScrollPosition property.

Friday, March 10, 2006

8 hours to figure out a DCOM call.

I spent quite a lot of time in last two days try to figure out a DCOM calls from the Windows 2003 machine to the Windows 2000 machine.

I had written a component to generate the sketch image for the property card. The actual component is sitting on windows 2000 server, and the proxy is exported and installed on windows 2000 server (the web server) too.

WebServer running the COM+ proxy(windows 2000) - > Component Server (also Database Server) (windows 2003)

Since the webserver is not very stable, and we exported the websites to the new 2003 server.

Suddently, the asp page gave out the following error.

Server object error 'ASP 0178 : 80070005'
Server.CreateObject Access Error

It is not a rare error, and googling will find tons of posts on this issue. Most of posts are misleading until i found this

Basically, when the anonymous user (IUSR_WEBSERVERNAME) makes a request on 2000, the identity used is NTAUTHORITY\IUSR_WEBSERVERNAME . On the 2003 server, the indentity used is WEBSERVERNAME\IUSR_WEBSERVERNAME, which is rejected by the component server.

The link suggested a couple of workaround, but I don't want to change anything on the new webserver, so I just added IUSR_WEBSERVERNAME to the Component Server, and it worked very beatifully.


Tuesday, March 07, 2006

Sweep line algorithm to computing the intersecting points.

The naive approach to compute the intersection points between line segments is use two for loops
for(int i = 0; i< count ; i++)
for( int j=i+1, j< count; j++)
compute the intersection between line[i] and line[j]

This is O(n*n) , not very efficient.

A better approach is to use the sweep-line approach. The sweep line will sweep from downwards. It will do some update at some event points.

Three types of event points:

1> The first type: the upper point of a line segment, we need to add that line segment into the set, and compute the intersection between this line segment and its immediate left and right neighbor.

2> The second type: the intersection point. The two line segments exchange position there, so we need to compute the intersection between those two line segments and thier new neighbors.

3> The third type: the end point of a line segment, this line segment will be deleted from the set. Its lef and right neighbor become immediate neighbor, we need to compute the intersections between them.

Thursday, March 02, 2006

CSS styles.

Three types of CSS styles:

1> Classes:
1-a> .ClassName
Classes with . at the beginning are applied to different html controls.
1-b> ElmentName.ClassName
Classes prefixed with the element name are applied only to the certain element.

2> Elements:
Elements are applied to certain elements, the following elements are applied to h1, h2.. h6 elements.

h1, h2, h3, h4, h5, h6
margin: 2px 0 2px 0;

.ClassName Element

.PageNumbers span
padding-left: 3px;

#ElementId Element

#poster h2
font-size: 13px;
font-weight: bold;
color: #50700E;

Those should be applied to certain element under the specific class name and the element Ids.

3> Element IDs:
Element IDs starts with the special symbol "#", and it only applies to element with those IDs applied. Those are normally used to position the different web parts.