-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2016版DS4、CUH-ZCT2J(CUH-ZCT2U)対応
- Loading branch information
Showing
18 changed files
with
848 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
#include "stdafx.h" | ||
#include "Findwindow.h" | ||
|
||
Findwindow::Findwindow() | ||
{ | ||
} | ||
|
||
|
||
Findwindow::~Findwindow() | ||
{ | ||
} | ||
std::wstring replace(const std::wstring& str, const std::wstring& from, const std::wstring& to) { | ||
std::wstring buf = str; | ||
std::wstring::size_type pos=0; | ||
while ((pos = buf.find(from,pos)) != std::wstring::npos) { | ||
buf.replace(pos, from.length(), to); | ||
pos += to.length(); | ||
} | ||
return std::move(buf); | ||
} | ||
std::wstring Findwindow::Val() | ||
{ | ||
std::wstring buf; | ||
WCHAR findIdx[20]; | ||
for (int i = 0; i < m_class.size(); i++) { | ||
wsprintf(findIdx, L"%d", m_idx[i]); | ||
buf += L"\""; | ||
buf += replace(m_class[i], L"\"", L"\"\""); | ||
buf += L"\",\""; | ||
buf += replace(m_title[i], L"\"", L"\"\""); | ||
buf += L"\",\""; | ||
buf += findIdx; | ||
buf += L"\";"; | ||
} | ||
|
||
|
||
return std::move(buf); | ||
} | ||
|
||
BOOL Findwindow::Val(std::wstring val) | ||
{ | ||
std::wstring findClass; | ||
std::wstring findTitle; | ||
std::wstring findIdx; | ||
int begin = 0; | ||
bool flag = false; | ||
std::wstring *buf = nullptr; | ||
for (int pos= 0; pos < val.length(); pos++) { | ||
if (val[pos] == L'"') { | ||
if (begin % 2 == 0) { | ||
switch (++begin) | ||
{ | ||
case 1: | ||
buf = &findClass; | ||
break; | ||
case 3: | ||
buf = &findTitle; | ||
break; | ||
case 5: | ||
buf = &findIdx; | ||
break; | ||
default: | ||
return FALSE; | ||
} | ||
continue; | ||
} | ||
if (!flag) { | ||
flag = true; | ||
continue; | ||
} | ||
flag = false; | ||
} | ||
else if (flag) { | ||
flag = false; | ||
buf = nullptr; | ||
switch (++begin) | ||
{ | ||
case 2: | ||
break; | ||
case 4: | ||
break; | ||
case 6: | ||
break; | ||
default: | ||
return FALSE; | ||
} | ||
if (val[pos] == L';') { | ||
begin = 0; | ||
m_class.push_back(findClass); | ||
m_title.push_back(findTitle); | ||
m_idx.push_back(_wtoi(findIdx.c_str())); | ||
findClass.clear(); | ||
findTitle.clear(); | ||
findIdx.clear(); | ||
} | ||
} | ||
if (buf != nullptr) { | ||
buf->push_back( val[pos] ); | ||
} | ||
} | ||
return TRUE; | ||
} | ||
|
||
std::wstring Findwindow::GetText(HWND hwnd) | ||
{ | ||
std::wstring text; | ||
int length = GetWindowTextLength(hwnd); | ||
if (length > 0) { | ||
WCHAR *buf = new WCHAR[length+1]; | ||
int ret = GetWindowText(hwnd, buf, length+1); | ||
|
||
if (ret == length) { | ||
text = buf; | ||
} | ||
delete[] buf; | ||
} | ||
return std::move(text); | ||
} | ||
|
||
std::wstring Findwindow::GetClass(HWND hwnd) | ||
{ | ||
WCHAR buf[257]; | ||
std::wstring str; | ||
if (GetClassName(hwnd, buf, 257) > 0) { | ||
str = buf; | ||
} | ||
return std::move(str); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
HWND Findwindow::Find() | ||
{ | ||
HWND hwnd = NULL; | ||
const WCHAR *fclass, *ftitle; | ||
for (int i = 0; i < m_class.size(); i++) { | ||
fclass = m_class[i].empty() ? NULL : m_class[i].c_str(); | ||
ftitle = m_title[i].empty() ? NULL : m_title[i].c_str(); | ||
if (fclass != NULL || ftitle != NULL) { | ||
int idx = m_idx[i]; | ||
HWND child=NULL; | ||
do { | ||
child = FindWindowEx(hwnd, child, fclass, ftitle); | ||
if (child == NULL) | ||
break; | ||
} while (--idx >= 0); | ||
hwnd = child; | ||
} | ||
else { | ||
hwnd = NULL; | ||
} | ||
if (hwnd == NULL) | ||
break; | ||
} | ||
return hwnd; | ||
} | ||
|
||
|
||
void Findwindow::Clear() | ||
{ | ||
m_class.clear(); | ||
m_title.clear(); | ||
m_idx.clear(); | ||
} | ||
|
||
void Findwindow::Pop() | ||
{ | ||
if (!m_class.empty()) { | ||
m_class.pop_back(); | ||
m_title.pop_back(); | ||
m_idx.pop_back(); | ||
} | ||
} | ||
|
||
//bool Findwindow::Set(int idx, WCHAR * findClass, WCHAR * findTitle,int findIdx) | ||
//{ | ||
// if (idx == -1) { | ||
// m_class.push_back(findClass); | ||
// m_title.push_back(findTitle); | ||
// m_idx.push_back(findIdx); | ||
// } | ||
// else if (m_class.size() > idx) { | ||
// m_class[idx] =findClass; | ||
// m_title[idx] =findTitle; | ||
// m_idx[idx] = findIdx; | ||
// }else | ||
// return false; | ||
// return true; | ||
//} | ||
|
||
int Findwindow::Size() | ||
{ | ||
return m_class.size(); | ||
} | ||
|
||
std::wstring Findwindow::Get(int idx, int col) | ||
{ | ||
std::wstring buf; | ||
if (m_class.size() > idx) { | ||
switch (col) | ||
{ | ||
case 0: | ||
buf = m_class[idx]; | ||
break; | ||
case 1: | ||
buf = m_title[idx]; | ||
break; | ||
case 2: { | ||
WCHAR str[10]; | ||
wsprintf(str, L"%d", m_idx[idx]); | ||
buf = str; | ||
break; | ||
} | ||
} | ||
} | ||
return std::move(buf); | ||
} | ||
|
||
void Findwindow::Set(int idx, int col, std::wstring buf) | ||
{ | ||
if (m_class.size() > idx) { | ||
switch (col) | ||
{ | ||
case 0: | ||
m_class[idx]=buf; | ||
break; | ||
case 1: | ||
m_title[idx]= buf; | ||
break; | ||
case 2: | ||
m_idx[idx] = _wtoi(buf.c_str()); | ||
break; | ||
} | ||
}else if (idx == -1) { | ||
switch (col) | ||
{ | ||
case 0: | ||
m_class.push_back(buf); | ||
break; | ||
case 1: | ||
m_title.push_back(buf); | ||
break; | ||
case 2: | ||
m_idx.push_back(_wtoi(buf.c_str())); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
class Findwindow | ||
{ | ||
std::vector<std::wstring> m_class; | ||
std::vector<std::wstring> m_title; | ||
std::vector<int> m_idx; | ||
bool m_enable; | ||
|
||
public: | ||
Findwindow(); | ||
~Findwindow(); | ||
std::wstring Val(); | ||
BOOL Val(std::wstring); | ||
static std::wstring GetText(HWND); | ||
static std::wstring GetClass(HWND); | ||
HWND Find(); | ||
|
||
void Clear(); | ||
void Pop(); | ||
int Size(); | ||
std::wstring Get(int idx, int col); | ||
void Set(int idx, int col, std::wstring); | ||
}; | ||
|
Oops, something went wrong.