- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFindWindow.cpp
More file actions
Latest commit
79 lines (68 loc) · 2.07 KB
/
Copy pathFindWindow.cpp
File metadata and controls
79 lines (68 loc) · 2.07 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
#include<windows.h>
#include<shlwapi.h>
#include<cstdio>
#include<tchar.h>
#include"arg.inl"
structFindWindowPlusData
{
LPCTSTR lpClassName;
LPCTSTR lpWindowName;
HWND hWnd;
};
BOOLCALLBACKFindWindowPlusEnumWindowsProc(_In_ HWND hWnd, _In_ LPARAM lParam)
{
FindWindowPlusData* data = (FindWindowPlusData*) lParam;
if (data->lpClassName != nullptr)
{
TCHAR strClassName[MAX_PATH];
if (!GetClassName(hWnd, strClassName, ARRAYSIZE(strClassName)))
returnTRUE;
if (!PathMatchSpec(strClassName, data->lpClassName))
returnTRUE;
//_tprintf(_T("Class: %s\n"), strClassName);
}
if (data->lpWindowName != nullptr)
{
TCHAR strWindowName[MAX_PATH];
if (!GetWindowText(hWnd, strWindowName, ARRAYSIZE(strWindowName)))
returnTRUE;
if (!PathMatchSpec(strWindowName, data->lpWindowName))
returnTRUE;
//_tprintf(_T("Title: %s\n"), strWindowName);
}
data->hWnd = hWnd;
_tprintf(_T("HWND: 0x%08X\n"), HandleToUlong(hWnd));
returnTRUE;
}
HWNDFindWindowPlus(LPCTSTR lpClassName, LPCTSTR lpWindowName)
{
FindWindowPlusData data = { lpClassName, lpWindowName };
EnumWindows(FindWindowPlusEnumWindowsProc, (LPARAM) &data);
return data.hWnd;
}
int_tmain(int argc, constTCHAR* const argv[])
{
arginit(argc, argv);
LPCTSTR lpClassName = argvalue(_T("/class"), nullptr, _T("<class>"), nullptr);
LPCTSTR lpWindowName = argvalue(_T("/title"), nullptr, _T("<title>"), nullptr);
if (!argcleanup())
returnEXIT_FAILURE;
if (argusage(lpClassName == nullptr && lpWindowName == nullptr))
returnEXIT_SUCCESS;
constHWND hWnd = FindWindowPlus(lpClassName, lpWindowName);
if (hWnd != NULL)
{
//_tprintf(_T("HWND: 0x%08X\n"), HandleToUlong(hWnd));
returnEXIT_SUCCESS;
}
elseif (GetLastError() == 0)
{
_tprintf(_T("Error: Not found\n"));
returnEXIT_FAILURE;
}
else
{
_tprintf(_T("Error: %d\n"), GetLastError());
returnEXIT_FAILURE;
}
}