'MFC'에 해당되는 글 6건

  1. 2011/09/06 [MFC] 파일 읽기
  2. 2009/01/16 Vista vs XP Registry 관련 함수
  3. 2008/09/09 MFC에서 윈도우 환경에 맞는 Control 만들기
  4. 2008/09/02 다이얼로그 타이틀바 없이 이동시키기
  5. 2008/03/31 [MFC] 다이얼로그를 전체화면으로 작성
  6. 2007/10/25 [MFC] Shared DLL을 사용한 2005 버전 프로그램 배포 시 주의
2011/09/06 10:54

[MFC] 파일 읽기

MFC에서 파일 읽고 쓰기

파일 읽고 내용을 리턴한다.
없으면 생성한다.

 
LPCTSTR testDlg::GetFileRead()
{


    CFile theFile;
    char* szFileName = "myfile.txt";
    BOOL bOpenOK;
    char szBuffer[256] = {0, };
    UINT nActual = 0;
    CString mFile;
    CFileStatus status;

    if(CFile::GetStatus(szFileName, status)) {
        bOpenOK = theFile.Open(szFileName, CFile::modeRead);
        theFile.Read(szBuffer, sizeof(szBuffer));
        theFile.Seek(0, CFile::begin);
        nActual = theFile.Read(szBuffer, sizeof(szBuffer));
        mFile.Format("%s", szBuffer);
    }
    else {
        bOpenOK = theFile.Open(szFileName, CFile::modeCreate | CFile::modeWrite);
    }
    return mFile;
}
msdn에서 참조했으며
기타관련 함수 사용법은 msdn에서 찾길 바랍니다.


Trackback 0 Comment 0
2009/01/16 10:24

Vista vs XP Registry 관련 함수

1. 레지스트리에서 값 읽어오기

 - 비스타에서 작업할 때
stdafx.h 파일에 
#define _WIN32_WINNT 0x0600
#include <Winreg.h> (include Windows.h)


LONG WINAPI RegGetValue(
  __in              HKEY hkey,
  __in_opt       LPCTSTR lpSubKey,
  __in_opt       LPCTSTR lpValue,
  __in_opt       DWORD dwFlags,
  __out_opt     LPDWORD pdwType,
  __out_opt     PVOID pvData,
  __inout_opt  LPDWORD pcbData
);
ex)
CString SubKey = "";
LPCTSTR lpKey = "SoftwareName";
LPCTSTR lpSubKey = "Data";
LPCTSTR pValue = "test";
DWORD cbData, cbType;
BYTE lpkData[256];

SubKey.Format("%s%s%s%s", "Software\\", lpKey, "\\", lpSubKey);
// -> HKEY_CURRENT_USER\Software\SoftwareName\Data

RegGetValue(
    HKEY_CURRENT_USER, 
    SubKey, 
    pValue, 
    RRF_RT_ANY, 
    &cbType, 
    lpkData, 
    &cbData);
// -> HKEY_CURRENT_USER\Software\SoftwareName\Data 에서 pValue의 값이 test인 키의 값을 뽀려온다. 이 값은 lpkData에 들어온다.

AfxMessageBox(lpkData);

 - XP에서 작업할 때
stdafx.h 파일에
#define _WIN32_WINNT 0x0501
#include <shlwapi.h>


LSTATUS SHGetValue(
    HKEY          hkey,
    LPCTSTR     pszSubKey,
    LPCTSTR     pszValue,
    LPDWORD   pdwType,
    LPVOID       pvData,
    LPDWORD   pcbData
);
ex) 
SHGetValue(
    HKEY_CURRENT_USER, 
    SubKey, 
    pValue, 
    &cbType, 
    lpkData, 
    &cbData);

///////////////////////////////////////////////////////////////////////////////////////////////

이런거 하나도 쓰기 귀찮구먼..
오늘은 여기까지.. 내일은 다른거..ㅋㅋ


Trackback 0 Comment 0
2008/09/09 23:38

MFC에서 윈도우 환경에 맞는 Control 만들기

stdafx.h 맨 아래 보면 다음과 같이 수정해준다.

#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #endif

Trackback 0 Comment 0
2008/09/02 22:30

다이얼로그 타이틀바 없이 이동시키기

방법 1. 윈도우 메시지중 WM_NCHITTEST를 추가하여 다음을 코딩한다.

LRESULT CTestDlg::OnNcHitTest(CPoint point)
{
    CRect rect;

    GetClientRect(&rect);
    ClientToScreen(&rect);

    if(rect.PtInRect(point))
    {    
        return HTCAPTION;
    }

    return CDialog::OnNcHitTest(point);
}


방법 2. 왼쪽 버튼 다운 함수에서의 처리 방법

void CTestDlg::OnLButtonDown(UINT nFlag, CPoint point)
{
      CDialog::OnLButtonDown(nFlag, point)  
     // 사용자가 캡션을 클릭한 것처럼 인식되게 끔 대화상자를 속인다.
     PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
  }


Trackback 0 Comment 0
2008/03/31 14:58

[MFC] 다이얼로그를 전체화면으로 작성

//OnInitDialog() 부분에 추가하면 된다.

LONG style = ::GetWindowLong( m_hWnd, GWL_STYLE );

style &= ~WS_CAPTION;
style &= ~WS_SYSMENU;

::SetWindowLong( m_hWnd, GWL_STYLE, style );
int screenx = GetSystemMetrics( SM_CXSCREEN );
int screeny = GetSystemMetrics( SM_CYSCREEN );

// resize:
SetWindowPos( NULL, -4, -4, screenx+8, screeny+4, SWP_NOZORDER );

Trackback 0 Comment 0
2007/10/25 16:22

[MFC] Shared DLL을 사용한 2005 버전 프로그램 배포 시 주의

Static Library 사용 시엔 문제가 없지만 Share DLL을 사용 시

릴리즈 버전은 ..\Microsoft Visual Studio 8\VC\redist\x86 에서,
디버그 버전은 ..\Microsoft Visual Studio 8\VC\redist\Debug_NonRedist 에서

CRT, MFC, ATL에 맞는 dll과 함께 Microsoft.VC80.*.manifest 도 포함해서 실행파일과 같은 폴더에 넣어주어야 한다.

아니면 ..\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86 또는
VC++ 2005 재배포 가능 패키지를 설치하여야 한다.
www.microsoft.com/downloads/details.aspx?FamilyID=32bc1bee-a3f9-4c13-9c99-220b62a191ee&DisplayLang=ko


Trackback 0 Comment 0