|
|
Thursday, February 17th, 2005
When you have a list box that gets items added to it on a continuing basis over the course of a program, it is nice for the list box to scroll downwards as items are added, so the most recent one is always visible. Except when the user is involved in reading some older items -- then this behavior is very annoying. Here is a solution, as implemented in an MFC application -- pretty easy to translate to C/C++* -- other languages, you're on your own: int GetVisibleCount(CListBox &lb)
{
CRect rct;
lb.GetWindowRect(&rct);
int iHgt = lb.GetItemHeight(0);
return (rct.bottom - rct.top) / iHgt;
}
// handler for a custom "Add Item" message
LRESULT CMyDlg::OnAddItem(WPARAM wp, LPARAM lp)
{
const char *msg = (const char *) lp;
int iTop = m_lbRealtimeStatus.GetTopIndex();
m_lbStatus.AddString(msg);
// "static" because I am never resizing the
// lb -- if you are you will need to calc
// this every time.
static visibleCount = GetVisibleCount(m_lbStatus);
if (iTop == m_lbStatus.GetCount() - 1 - visibleCount)
m_lbStatus.SetTopIndex(iTop + 1);
return 0L;
}
So what I am doing is, every time I add an item, I check what the current topmost visible index of the list box is -- if it is not equal to the number of items in the list box less the number of visible items, then I do not scroll. (Note that this calculation doesn't work when there are fewer items in the list box than the max number that will fit on the screen; but that does not matter because there is no need to scroll anyways in that situation.) * That is to say, C or C++ where you are not using MFC classes.
posted afternoon of February 17th, 2005: Respond ➳ More posts about Programming Projects
| |
Thursday, June 17th, 2004
Brad DeLong pointed me to a very nice site: Joel on Software is the musings of Joel Spolsky, founder of Fog Creek Software and a very insightful guy.
posted afternoon of June 17th, 2004: Respond ➳ More posts about Projects
| |
Monday, December 15th, 2003
It occurs to me that it might be nice to have links (to outside web sites) that knew when a reader clicked on them, in order to update statistics -- my idea is to sort my blogroll by how frequently each of the links is used. Here is an idea for how to do it: Currently the link is <a href="http://someurl">Link Text</a> -- but if the link were <a href="http://www.readin.com/blog/blog.asp?redirect='someurl'">Link Text</a>, then I could update my statistics and redirect. This might confuse some browsers' site history, causing the back button not to work properly; I'm pretty sure Explorer and Mozilla know what to do when confronted with such a situation but am not sure about earlier versions of Netscape. And I would want to have some Java code for mouseover, so that the browser's status bar would just display someurl when you hovered over the link. Update: Weird, now (Tuesday) I see someone has browsed to my blog following a link of the type I am describing: my referrals log shows a visit from http://www.popdex.com/redir/?u=http://wampum.wabanaki.net/archives/000634.html. (The "u" redirect URL is the address of the Koufax Awards thread on Wampum.) Apparently someone followed a self-conscious link to the Koufax Awards, then followed the link on that page to my blog. And for some reason their browser remembered the self-conscious link as the referrer instead of the redirect.
posted afternoon of December 15th, 2003: Respond
| |
Tuesday, April 29th, 2003
With regards to my previous post, I want to flesh out the idea of limiting information content in order to increase bandwidth. Actually -- well I guess its accurate to say "I want to flesh out" this concept -- but not sure it is currently within my ability to do so. This must be an existing meme though -- if you have any recommendations for reading on this subject, please contact me.
posted afternoon of April 29th, 2003: Respond
| |
So why did I create this journal? The reasons are severalfold. I've been pretty fascinated by the blogging phenomenon since last summer, when I discovered a couple of the sites I've been reading regularly since -- Calpundit, Talking Points Memo, and Body and Soul are perhaps the "big three" for me -- and have been wondering if I could sustain such a steady level of posting and keep it interesting, and how it would sound if I did. I started my first "web log" before I knew that term, back in 1999 with the READIN book diary; but page generation was manual, not automated, and maintaining the site was a hassle, and I never really got far with it. Although, take a look at the page for Faulkner's The Hamlet to get an idea of where I wanted to go with it. Once I found out about ASP it seemed like the perfect fit -- I just had to learn how to code automatically generated journal pages and good things would come of it. Two things I wanted to learn to do formatting-wise; expressing dates and times in human terms, and displaying links in a hierarchical format. All the m/d/yyyy dates and hh:mm:ss times you see on web pages don't do it for me. They are over-determined and difficult to read. I wanted to express recent dates as "Yesterday", "Last Sunday", and posting times as just "morning", "evening", etc. I think I have come up with a pretty coherent way of doing this! And the hierarchical links, well, take a look at the left hand side of this page, I think they are good. Update: Thinking about the two formatting goals above, I realize they are both concerned with limiting the amount of information presented in order to maximize the amound of information communicated. Funny... And the archiving system I have vaguely in mind could be thought of along the same lines too.
posted morning of April 29th, 2003: Respond ➳ More posts about The site
| |
|
Drop me a line! or, sign my Guestbook. • Check out Ellen's writing at Patch.com.
| |