-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJunUtil.cpp
More file actions
103 lines (79 loc) · 2.28 KB
/
Copy pathJunUtil.cpp
File metadata and controls
103 lines (79 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "stdafx.h"
#include "JunUtil.h"
//////////////////////////////////////////////////////////////////////////
// GlobalNum 초기화
int GlobalNum::nPaintStatus = 0;
//////////////////////////////////////////////////////////////////////////
// JunHee Util
// 문자열 컨트롤
std::string JunUtil::CStringToString(CString cstr)
{
char caResult[100];
#pragma warning(push)
#pragma warning(disable: 4996)
strcpy(caResult, CT2A(cstr));
if (caResult == NULL)
{
strcpy(caResult, "");
}
caResult[strlen(caResult) + 1] = '\0';
#pragma warning(pop)
return caResult;
}
CString JunUtil::StringToCString(std::string str)
{
CString strResult;
strResult = str.c_str();
strResult += '\0';
return strResult;
}
bool JunUtil::isNumber(std::string str)
{
if (str.size() == 0)
return false;
#pragma warning(push)
#pragma warning(disable: 4018)
for (int i = 0; i < str.size(); i++)
{
#pragma warning(pop)
if (( str[i] >= '0' && str[i] <= '9') == false)
{
return false;
}
}
return true;
}
// 원하는 작업 영역 캡쳐, 캡쳐 하고 싶은 영역의 Frame Param 전달
void JunUtil::SpecificAreaCapture(CWnd *pcwnd)
{
// 바탕 화면 윈도우 객체에 대한 포인터를 얻는다.
CWnd* pWndDesktop = pcwnd->GetDesktopWindow();
// 바탕 화면 윈도우 DC
CWindowDC ScrDC(pWndDesktop);
// 뷰 윈도우 DC
CClientDC dc(pcwnd);
// Rect를 사용해서 작업 영역에 대한 좌표를 얻고,
CRect Rect;
pcwnd->GetClientRect(&Rect);
// 그 위치를 현재 윈도우 절대 좌표로 변경해 주자.
pcwnd->GetWindowRect(&Rect);
// CImage를 하나 만들고
CImage Image;
// 스캔을 시작할 x, y 위치와
int sx = Rect.left;
int sy = Rect.top;
// 작업 영역에 대한 크기를 각각 임시로 저장해 두자.
int cx = Rect.Width();
int cy = Rect.Height();
// 작업 영역의 크기만큼, 현재 바탕화면의 속성과 동일한 image를 생성한다.
Image.Create(cx, cy, ScrDC.GetDeviceCaps(BITSPIXEL));
// 이미지 DC에 현재 작업 영역의 절대 좌표를 사용해 그 크기만큼 저장하게 한다.
CDC* pDC = CDC::FromHandle(Image.GetDC());
pDC->BitBlt(0, 0, cx, cy, &ScrDC, sx, sy, SRCCOPY);
Image.ReleaseDC();
// 저장된 이미지를 원하는 파일명, 포멧타입을 지정해서 저장한다.
Image.Save(TEXT("media\\capture\\image.png"), Gdiplus::ImageFormatJPEG);
// 그 파일을 실행해 준다.
// 응용 프로그램을 실행시킬 수 있음!
ShellExecute(NULL, TEXT("open"), TEXT("media\\capture\\image.png"), NULL, NULL, SW_SHOW);
}