반응형
[WindowsProgramming]메뉴
CMenu menuMain;
 menuMain.CreateMenu();
 CMenu menuPopup3;
 menuPopup3.CreatePopupMenu();
 menuPopup3.AppendMenu(MF_STRING, 301, "&1");
 menuPopup3.AppendMenu(MF_STRING, 302, "&2");
 menuPopup3.AppendMenu(MF_STRING, 303, "&3");
 CMenu menuPopup2;
 menuPopup2.CreatePopupMenu();
 menuPopup2.AppendMenu(MF_STRING|MF_CHECKED, 201, "빨강(&R)");
 menuPopup2.AppendMenu(MF_POPUP, (UINT_PTR)menuPopup3.Detach(), "초록(&G)");
 menuPopup2.AppendMenu(MF_STRING, 203, "파랑(&B)");
 menuMain.AppendMenu(MF_POPUP, (UINT_PTR)menuPopup2.Detach(), "색상(&C)");
 SetMenu(&menuMain);
 menuMain.Detach();
 
 return 0;

[WindowsProgramming]배경색 Brush
CPaintDC dc(this); // device context for painting
   
   CRect rect;
   GetClientRect(&rect);
   dc.SelectStockObject(NULL_PEN);
   CBrush brush(m_color);
   dc.SelectObject(&brush);
   dc.Rectangle(&rect);

[WindowsProgramming]메뉴 선택 업데이트
void CChildView::OnColor1()
{
   // TODO: Add your command handler code here
   m_color=RGB(255,0,0);
   Invalidate();
   
}

void CChildView::OnColor2()
{
   m_color=RGB(0,255,0);
   Invalidate();
   // TODO: Add your command handler code here
   
}

void CChildView::OnColor3()
{
   m_color=RGB(0,0,255);
   Invalidate();
   // TODO: Add your command handler code here
   
}

void CChildView::OnUpdateColor1(CCmdUI* pCmdUI)
{
   pCmdUI->SetCheck(m_color==RGB(255,0,0));
   // TODO: Add your command update UI handler code here
   
}

void CChildView::OnUpdateColor2(CCmdUI* pCmdUI)
{
   // TODO: Add your command update UI handler code here
   pCmdUI->SetCheck(m_color==RGB(0,255,0));
   
}

void CChildView::OnUpdateColor3(CCmdUI* pCmdUI)
{
   // TODO: Add your command update UI handler code here
   pCmdUI->SetCheck(m_color==RGB(0,0,255));
   
}


[WindowsProgramming] (FILE 입출력) 소문자 test1.txt를 대문자 test2.txt 로 바꿔주는것
void CFirstView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
   // TODO: Add your message handler code here and/or call default
   CStdioFile file1;
   CFileException e;
   if(!file1.Open("test1.txt",CFile::modeRead, &e)){
       e.ReportError();
       return;
   }
   CStdioFile file2;
   if(!file2.Open("test2,txt", CFile::modeWrite|CFile::modeCreate, &e)){
       e.ReportError();
       return;
   }
   CString str;
   while(file1.ReadString(str)){
       str.MakeUpper();
       file2.WriteString(str+"
");
   }
}


[WindowsProgramming]dir 명령 처럼 TRACE로 출력
void CFirstView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
   // TODO: Add your message handler code here and/or call default
   CStdioFile file1;
   CFileException e;
   if(!file1.Open("test1.txt",CFile::modeRead, &e)){
       e.ReportError();
       return;
   }
   CStdioFile file2;
   if(!file2.Open("test2,txt", CFile::modeWrite|CFile::modeCreate, &e)){
       e.ReportError();
       return;
   }
   CString str;
   while(file1.ReadString(str)){
       str.MakeUpper();
       file2.WriteString(str+"
");
   }
}

[WindowsProgramming]타이머 활용
void CMy2ndView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
   // TODO: Add your message handler code here and/or call default

   switch(nChar){
   case VK_LEFT:
       m_aPos-=1;
       break;
   case VK_RIGHT:
       m_bPos+=60;
       break;
   case VK_UP:
       m_cPos+=60;
       break;
   case VK_DOWN:
       m_dPos-=60;
       break;
   case VK_END:
       SetTimer(0,20,NULL);
       break;
   }
   Invalidate();
   
   CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMy2ndView::OnTimer(UINT nIDEvent)
{
   // TODO: Add your message handler code here and/or call default
   switch (nIDEvent){
   case 0:
       m_aPos-=1;
       Invalidate();
       break;
   }
   
   CView::OnTimer(nIDEvent);
}
반응형

'WindowsPrograming' 카테고리의 다른 글

ApiStart.txt  (0) 2007.04.21
WM_KEYDOWN 메시지  (0) 2007.04.09
[MFC]키보드로부터 입력  (1) 2007.04.09
Posted by Real_G