Category Archives: Techniques

Using 2 views for a single document

In order to use more than 1 views for a singel document, one should add another document template. If adding this snippet code to InitInstance() directly, one would encounter a dialog to select different documents although you only have one type of document. Commonly, there are 2 methods to avoid this dialog: first is to declaim different resource ID for the second document template, and blabla…; second is to add the second doucment template to other place other than the InitInstance(). See:
BOOL CPhotograph2App::OnDstTemplate()
{
 pDstTemplate = new CMultiDocTemplate(IDR_Photograph2TYPE,
  RUNTIME_CLASS(CPhotograph2Doc),
  RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  RUNTIME_CLASS(CDstView));
  
 if (!pDstTemplate)
    return FALSE;
 AddDocTemplate(pDstTemplate);          
  
 ASSERT_VALID(pDstTemplate); 
 return TRUE;
}
 
Then you can create the view when necessary. Remember to InitialUpdateFrame after CreateNewFrame.
// CMainFrame message handlers
BOOL CMainFrame::OnDstWindow()
{
   CMDIChildWnd* pActiveChild = MDIGetActive();
   CDocument* pDocument;
  
   if (pActiveChild == NULL ||
      (pDocument = pActiveChild->GetActiveDocument()) == NULL) {
      TRACE0("Warning: No active document for WindowNew command.\n");
      AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
      return FALSE;     // command failed
   }
  
 CPhotograph2App*  pApp = (CPhotograph2App*)AfxGetApp();  
 ASSERT_POINTER(pApp, CPhotograph2App);
   //CDocTemplate* pTemplate = pDocument->GetDocTemplate();
   CMultiDocTemplate* pDstTemplate = pApp->GetDstTemplate();     
 
 ASSERT_VALID(pDstTemplate); 
 CFrameWnd* pFrame = pDstTemplate->CreateNewFrame(pDocument, pActiveChild);
  
   if (pFrame == NULL)   {  
    TRACE0("Warning: failed to create new frame.\n");   
    return FALSE;     // command failed
   }
 
   pDstTemplate->InitialUpdateFrame(pFrame, pDocument);
}
 
 

Usage of CScrollView

Generally speaking, we only need to rewrite 2 functions:
1. OnInitialUpdate()
void CSrcView::OnInitialUpdate()
{
 CScrollView::OnInitialUpdate();
 
 CPhotograph2Doc* pDoc = GetDocument();
 CSize sizeTotal;
 // TODO: calculate the total size of this view
 sizeTotal.cx = pDoc->pSrcImg->Width();
 sizeTotal.cy = pDoc->pSrcImg->Height();
 SetScrollSizes(MM_TEXT, sizeTotal);
}
 
2. OnDraw()
// some drawing
 
SetScrollSizes(MM_TEXT, CSize(pDoc->pSrcImg->Width(), pDoc->pSrcImg->Height()));
   
 CChildFrame *pParentFrame = (CChildFrame *)this->GetParentFrame();
    pParentFrame->RecalcLayout();
//    ResizeParentToFit();  
 
Probably, you may want to override the function OnEraseBkgnd();
BOOL CSrcView::OnEraseBkgnd(CDC* pDC)
{
 //   Set   brush   to   desired   background   color            
 CBrush   backBrush(RGB(255,   255,   255));                
 //   Save   old   brush       
 CBrush*   pOldBrush   =   pDC->SelectObject(&backBrush);  
            
 CRect   rect;               
 pDC->GetClipBox(&rect);           //   Erase   the   area   needed                  
 pDC->PatBlt(rect.left,   rect.top,   rect.Width(),   rect.Height(),                     
  PATCOPY);               
 pDC->SelectObject(pOldBrush);  
             
 return   TRUE;  
 //return CScrollView::OnEraseBkgnd(pDC);
}
 
That’s all.

How to live a Happy and Rewarding Life(ZZ)

 
 
Watch Butterflies or Birds.
Be grateful for good health.
Don’t interrupt.
Take a nap on Sunday afternoon.
Never deprive someone of hope.
Be thankful for every meal.
Never be afraid to say, "I’m Sorry."
Improve your performance by improving your attitude.
Wave at children on the school bus.
Leave everything a little better than when you found it.
Leave the toilet seat in the down position.
Take time to smell the roses.
Don’t tailgate.
Keep it simple.
Enjoy good company.
Keep your promises.
Listen to your children.
Be kinder than necessary.
Wear outrageous underwear on a job interview, or to work!
Take good care of those you love.
Make it a habit to do nice things for people who never find out.
Judge your success by the degree that you enjoy peace and good health.
Be a good loser.
Be a better winner.
Be romantic.
Live so that when your children think of fairness, caring and integrity, they think of you.
Enjoy real maple syrup.
Never refuse homemade brownies.
Remember other people’s birthdays.
Sing in the shower.
Resist gossip.
Don’t nag.
Don’t expect that money will bring you happiness.
Say "THANK YOU" a lot.
Take care of your reputation; it is your most valuable asset.
Take your dog to obedience school.
Slow dance.
Don’t rain on other people’s parade.
Don’t postpone joy.
Whistle.
Call your mother.
Do more than what is expected of you.
Be someone’s hero.
Count your blessings…daily.
Enjoy a sunrise, sunset.  
Author Unknown

第一个Cg程序写好了

vertex shader和fragment shader其实基本上是用网上现成的代码,只是修改了fragment shader的部分代码。但debug这个程序时碰到好多问题,可能是因为用到了好多Cg Runtime的函数,最开始时没有显示输出,现在都应该调试好了。
 
简单总结一下:
  1. 下载的shader代码有些问题,后来通过添加error callback函数查到了错误;
  2. Cg toolkit document可能有些问题,arbvp1部分写了glstate.matrix.mvp,而实际用的时候应该是state.matrix.mvp。就这个问题让我荒废了10个小时以上,最后找到了其他人的代码才知道是这个错误了。这个document真是害死人了。(难道是我没有领会document的精神?)
  3. 单独运行编译好的prog3.exe(debug)时,出现莫名其妙的问题。在不同的机子上显示不同的颜色,发现原来是读数据出错了,但是在VS的IDE里debug运行却没有问题,不知道怎么回事?最后编译release version的代码,在各个机子上运行就正常了,无语。。。
  4. 编译时出现link error,选择multi-threaded就好了
  5. 在我的nvidia 7900GTX运行很慢,慢的难以理解;但在我的laptop的ati x1300上却运行的没一点问题,怀疑是驱动问题,明天到lab去升级一下驱动试试。。   

How to do research in the MIT AI lab —— Notebooks

这是几天前写,现在贴出来。原文请看

http://www.cs.indiana.edu/mit.research.how.to/mit.research.how.to.html

—-

吃饭前读了"How to do research in the MIT AI lab" 的“notebooks”这段,感觉有很多收获,据说最有价值的部分是在这篇文章的第2部分。下面是“Notebooks”的部分内容:

每个研究者都应该有个笔记本。上面记着一些想法,当前碰到的问题,及其可能的解决方法等。把那些可能的解决方法都想好并记下来,也可以记些以后要读的参考文献。可以随便记笔记,因为只有你自己才会看它。

每隔一段时间把记过的笔记再看一下。

笔记本上记的东西将来可能就是文章的原形。或者,你可以把记的东西用文章的结构组织起来,尽管你并不想发表它。当然,你也可能改变主意。

----

自己虽然读了研究生,但是始终没有做研究的感觉,可能一方面是环境问题,不过更主要的可能还是自己不太用心,也不用功。但是,却对笔记还有些体会。记得研究生发的那篇论文就是归功于笔记的。当时,自己确实是有什么想法就记下来,还有一些可能的解决方法。有时晚上坐在回徐汇的徐闵线上还掏出笔记本记下突然想到的一些想法,最后好好组织一下就形成了一片文章。自己虽然不太满意,但终究还是发表了。