GSI

GDI+ 를 하다 보면 일반 string 을 그대로 사용하지 못한다. wchar로 바꿔서 해야 하는데 이때 이것을 사용하자.

  char* -> wchar를 바꾸는 방법
  std::string 이라면 str.c_str()을 넘겨주자.


  LPWSTR lpszW = new WCHAR[MAX_PATH];
  int nLen = MultiByteToWideChar(CP_ACP, 0, pstrSrc, -1, NULL, NULL);
  MultiByteToWideChar(CP_ACP, 0, pstrSrc, -1, lpszW, nLen);

Posted by gsi
:

CDialog를 서브클래싱 해서 다른 컨트롤에 적용할려고 할때 보통 Create를 오버라이드 해서 사용하게 되는데 이때 보면 Create의 원형은 아래와 같습니다.

BOOL CGDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
 return CDialog::Create(lpszTemplateName, pParentWnd);
}


하지만 여기서 보면 Dialog 니까. Dialog의 아이디를 넣으면 되겠지 하지만 이건 int 형을 LPCTSTR형으로 바꿀수 없다는 에러만 발생하게 됩니다. (솔직히 TemplateName라는게 어떤건지 잘 모르겠습니다.

하지만 우리가 알고 있는 Dialog의 아이디 값을 LPCTSTR형으로 바꾸어 주는 함수를 사용하면 됩니다.

보통 다른 컨트롤에서 생성하기 때문에 Create를 하나더 만듭니다.
왜냐하면 굳이 아이디 값을 노출하거나 더 적어줄 필요가 없으니 아래와 같이 함수를 만들면 될듯합니다.

BOOL CGDialog::Create(CWnd* pParentWnd)
{
 return Create(MAKEINTRESOURCE(IDD_GDIALOG), pParentWnd);
}


여기서 보는바와 같이 MAKEINTRESOURCE 라는 디파인 문을 사용하면 LPCTSTR형태로 변환해 주면 가능합니다.

위의 함수를 다른 컨트롤 쪽에서 아래와 같이 사용하면 해당 컨트롤에 추가해서 사용할 수 있습니다.

 m_Dialog.Create(this);
 m_Dialog.ShowWindow(SW_SHOW);
 m_Dialog.MoveWindow(CRect(200, 200, 400, 400));


[팁]
다이얼로그의 스타일이 3가지가 있는데요. Overlapped, PopUp, Child 형태가 있습니다.
Overlapped, PopUp 형태로 하게 되면 컨트롤에 추가 되지만 컨트롤 안에 종속되지는 않네요. 밖으로 이동이 가능하게 되는데요 꼭, 모달 다이얼로그와 비슷한 형태인듯 합니다.
그리고 Child 형태로 하게 되면 컨트롤 내부에서만 동작을 하게 되네요.

이때 타이틀바가 나오거나 안나오거나 상관 없이 동작하게 됩니다.

Posted by gsi
:

사용자 삽입 이미지

MFC 에서 싱글뷰로 해서 Doc 없애고, CChildView로만 생성했습니다.
내부에 Static, Button을 서브클래싱 해서 클래스를 각각 제작.

CChildView 내부에 멤버 변수로 선언
CGStatic m_Static;
CGButton m_Button;


OnCreate 함수를 오버라이드 하여 컨트롤을 생성합니다.
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CWnd::OnCreate(lpCreateStruct) == -1)
  return -1;

 m_Static.Create("test", WS_CHILDWINDOW|SS_NOTIFY, CRect(10, 10, 100, 100), this, 1000);
 m_Static.ShowWindow(SW_SHOW);

 m_Button.Create("", WS_CHILDWINDOW, CRect(100, 100, 200, 200), this, 1001);
 m_Button.ShowWindow(SW_SHOW);

 return 0;
}


CStatic 컨트롤의 마우스 이벤트를 먹게 할려면 SS_NOTIFY를 추가해야 합니다.

CStatic, CButton의 마우스 이벤트 코드는 동일하기 때문에 CButton 의 내용만 서술합니다.
이전 위치를 기억 하기 위해서 변수를 하나 생성
CPoint  oldPos;

생성자 쪽에서 초기화를 해줍니다.
oldPos = CPoint(0, 0);

나머지 OnLButtonDown, OnLButtonUp, OnMouseMove 이벤트를 추가하고
아래와 같이 작성해 줍니다.
void CGButton::OnLButtonDown(UINT nFlags, CPoint point)
{
 SetCapture();
 
 // 최초 위치를 oldpos에 입력하고 시작한다.
 CPoint curpos;
 GetCursorPos(&curpos);
 GetParent()->ScreenToClient(&curpos);
 oldPos = curpos;

 CButton::OnLButtonDown(nFlags, point);
}

void CGButton::OnLButtonUp(UINT nFlags, CPoint point)
{
 ReleaseCapture();
 CButton::OnLButtonUp(nFlags, point);
}

void CGButton::OnMouseMove(UINT nFlags, CPoint point)
{
 if(GetCapture() == this) {

  // 현재 컨트롤이 포함되어 있는 부모 컨트롤에서의 위치값을 가져온다.
  CRect thisRect;
  GetWindowRect(&thisRect);
  GetParent()->ScreenToClient(&thisRect);

  // 현재 마우스 위치값을 컨트롤의 위치 값으로 변환한다.
  CPoint curpos;
  GetCursorPos(&curpos);
  GetParent()->ScreenToClient(&curpos);

  // 변경된 위치값을 사용해서 이동범위를 구한다.
  CPoint newpos = curpos - oldPos;

  // 이동할 위치와 크기값을 보정한다.
  thisRect.left += newpos.x;
  thisRect.top += newpos.y;
  thisRect.right = thisRect.left+100;
  thisRect.bottom = thisRect.top+100;
 
  // 윈도우를 이동시킨다.
  MoveWindow(&thisRect);

  // 계속 움직임을 위해서 현재 값을 저장한다.
  oldPos = curpos;

  Invalidate();
 }

 CButton::OnMouseMove(nFlags, point);
}

Posted by gsi
:

버튼을 CView에 추가..

 m_Button.Create("", WS_CHILDWINDOW, CRect(50, 100, 150, 200), this, 1001);
 m_Button.ShowWindow(SW_SHOW);


그리고 버튼 내부에 클릭 이벤트를 통해서 해당 위치에 버튼을 MoveWindow 시켜보자.

void CGButton::OnLButtonUp(UINT nFlags, CPoint point)
{
 CPoint curpos;
// 커서의 스크린 위치를 가져온다.
 GetCursorPos(&curpos);
// 부모 객체에서의 스크린 좌표를 클라이언트 좌표로 바꾼다.
 GetParent()->ScreenToClient(&curpos);
// 좌표값을 사용해서 윈도우의 크기를 지정한다.
 CRect rt(curpos.x, curpos.y, curpos.x+100, curpos.y+100);
// 자신 객체를 이동시킨다.
 MoveWindow(&rt);

 CButton::OnLButtonUp(nFlags, point);
}


이 코드가 완성되었으니. 클릭후 드래그로 컨트롤을 View에서 이동가능할듯 하다. ^^
(아마도 다 아는거겠지만. 요즘 mfc에 대해서 조금씩 방법적인 면이 늘어 나는거 같다.)

Posted by gsi
:


The Sysinternals web site was created in 1996 by Mark Russinovich and Bryce Cogswell to host their advanced system utilities and technical information. Microsoft acquired Sysinternals in July, 2006. Whether you’re an IT Pro or a developer, you’ll find Sysinternals utilities to help you manage, troubleshoot and diagnose your Windows systems and applications. If you have a question about a tool or how to use them, please visit the Sysinternals Forum for answers and help from other users and our moderators.

Featured Resources



What's New (November 27th, 2007)

This Zoomit update enables you to center the mouse with the space bar when in drawing mode, adds an option to view time elapsed after the break timer expires, and reverses the keys used to draw lines and arrows.

PsExec’s new release fixes a bug in the -i option that prevented it from correctly displaying windows on the console desktop.

What's New (November 5th, 2007)

Introducing ADInsight, an LDAP (Light-weight Directory Access Protocol) real-time monitoring tool aimed at troubleshooting Active Directory client applications. Use its detailed tracing of Active Directory client-server communications to solve Windows authentication, Exchange, DNS, and other problems.

This version of PsExec, a command-line tool for executing programs locally and remotely, significantly improves handling of arguments passed to the specified application by not modifying spacing or quotation marks. It also fixes a number of minor bugs, including ones related to running programs in alternate terminal server sessions.

What's New (October 26th, 2007)

This update to Process Explorer, an advanced process information utility, has a number of miscellaneous improvements. For example, the thread support in the process properties dialog is enhanced with Wow64 thread stacks on 64-bit Windows and kernel stacks on Windows Vista and Server 2008. In addition, tooltips on the service hosting processes now show service names, the user SID is displayed on the security properties page, and column headers have tooltips when they’re too small to display their text.

What's New (October 15th, 2007)

See how Mark uses the Windows Debugger and Sysinternals Process Explorer to troubleshoot a Windows Vista Sidebar Clock gadget issue. This example will show how symbols can be leveraged for deep Windows troubleshooting.

This Handle update adds support for Vista object types and the –accepteula switch.

Next month Mark will be speaking at Microsoft's TechEd IT-Forum International on several Windows kernel, security, and troubleshooting topics.

What's New (October 3rd, 2007)

Check out Mark's new blog where he uses Process Monitor to uncover the root cause for a file copy error. Process Monitor is uniquely useful for exposing file, registry, and process activity within Windows.

What's New (September 28th, 2007)

Version 4.11 comes with a couple bug fixes and now supports images that span multiple monitors! See the site blog for more details on the bug fixes.

What's New Archive

Posted by gsi
: