2010年6月28日 星期一

MFC: OnPaint

void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
//dc.TextOut(0,0, (LPCTSTR)L"生醫影像實驗室討論區");
dc.TextOut(0,0, CString("生醫影像實驗室討論區"));

//dc.TextOutA(0,0, "test string");
// Do not call CWnd::OnPaint() for painting messages
}

MFC: show current cusor poistion

void CChildView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此加入您的訊息處理常式程式碼和 (或) 呼叫預設值

//CWnd::OnMouseMove(nFlags, point);
CClientDC dc(this); // device context for painting
COLORREF fgcol = dc.GetTextColor();
static CPoint opoint(0,0);
CString a;

dc.SetTextColor(dc.GetBkColor());
a.Format("(%3d, %3d)", opoint.x, opoint.y);
dc.TextOutA(opoint.x-15, opoint.y-15, a);
dc.SetTextColor(fgcol);
a.Format("(%3d, %3d)", point.x, point.y);
dc.TextOutA(point.x-15,point.y-15, a);
opoint = point;

}

2010年6月19日 星期六

function pinter in c (or c++)

/*
funpt.c: a demo of function pointer

to compile:
gcc -o funpt funpt.c -lm

Ching-Han Hsu, Ph.D. (c) 2010
*/

#include
#include
#include

double fun1(double (*fp)(double), double x)
{
printf("in fun1\n");
return fp(x);
}

double sqcos(double x)
{
printf("squared cos\n");
return (cos(x) * cos(x));
}

int main (int argc, char** argv)
{

printf("cos 2.0 = %.3f\n", cos(2.0));
printf("cos 2.0 = %.3f\n", fun1(cos, 2.0));
printf("squared cos 2.0 = %.3f\n", fun1(sqcos, 2.0));

return 0;
}

2010年6月15日 星期二

qsort: a demo to sort float array

#include
#include
#include

int comp(const void *, const void *);

/* for sorting a float array */
int comp(const void *p, const void *q)
{
return ((*(float *)p - *(float *)q) > 0.0 ? 1 : -1);
}

int main(int argc, char *argv[])
{
int i,j;
float *array_1,*array_2;

srand ( time(NULL) );
array_1 = (float*)calloc(sizeof(float),10);

printf("qsort start \n");

for(i=0;i<10;i++)
{
*(array_1 + i ) = (rand()%200)/7.0;
}


for(i=0;i<10;i++)
{
printf("array_1 %d = %f \n",i,*(array_1 + i));
}

printf("-------- \n");

qsort(array_1, 10, sizeof(float), comp);

for(i=0;i<10;i++)
{
printf("array_1 %d = %f \n",i,*(array_1 + i));
}

printf("\n");

return 0;
}

2010年6月14日 星期一

install java runtime on ubuntu 10.04

1. Install the following packages:
sun-java6-jre
sun-java6-fonts
sun-java6-bin

2. Install imagej

3. Install jabref

The above two packages are subject to some font problems of chinese characters.

ps. Do not install this one ia32-sun-java6-bin or other java distribution. To my own case, these packages just mess up with chinese font.