feisty meow concerns codebase 2.140
find_window.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : find_window *
4* Author : Chris Koeritz *
5* *
6* Purpose: *
7* *
8* Locates a window by the title. If it's found, the window handle is *
9* displayed. *
10* *
11*******************************************************************************
12* Copyright (c) 2000-$now By Author. This program is free software; you can *
13* redistribute it and/or modify it under the terms of the GNU General Public *
14* License as published by the Free Software Foundation; either version 2 of *
15* the License or (at your option) any later version. This is online at: *
16* http://www.fsf.org/copyleft/gpl.html *
17* Please send any updates to: fred@gruntose.com *
18\*****************************************************************************/
19
21#include <basis/astring.h>
23#include <basis/guards.h>
24#include <filesystem/filename.h>
27
28using namespace application;
29using namespace basis;
30using namespace filesystem;
31using namespace loggers;
32using namespace structures;
33//using namespace timely;
34
35#undef LOG
36#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
37
38#ifdef __WIN32__
39
40window_handle matching_window = NULL_POINTER;
41astring window_name_sought;
42
43BOOL CALLBACK zingers_enum_proc(window_handle hwnd, LPARAM lParam)
44{
45 const int MAX_TITLE = 1024;
46 flexichar win_name[MAX_TITLE + 8]; // add a little for good luck.
47 int chars = GetWindowText(hwnd, win_name, MAX_TITLE - 1);
48 if (chars > 0) {
49 // see if the current window matches what we're looking for.
50 if (astring(from_unicode_temp(win_name)).ifind(window_name_sought) >= 0) {
51 matching_window = hwnd;
52 return false; // don't keep going.
53 }
54 }
55 return true; // haven't found it yet.
56}
57
58int main(int argc, char *argv[])
59{
61 command_line cmds(argc, argv);
62 if ( (cmds.entries() < 1)
63 || (cmds.get(0).type() != command_parameter::VALUE) ) {
64 out.log(cmds.program_name().basename().raw() + " usage:\n"
65 "this takes a single parameter, which is the name of a window\n"
66 "that is expected to be present in the current winstation. if the\n"
67 "window is found, its window handle is displayed.");
68 return 1;
69 }
70 astring title = cmds.get(0).text();
71 matching_window = NULL_POINTER; // reset our match first.
72 window_name_sought = title;
73 // enumerate the windows looking for a match.
74 EnumWindows(zingers_enum_proc, 0);
75 if (!matching_window) {
76 out.log("no matching window could be found. ignoring request.");
77 return 1;
78 }
79//out.log("found matching window handle...");
80
81 if (matching_window)
82 out.log(a_sprintf("window handle is 0x%lx (or %ld) for ", matching_window,
83 matching_window) + title + ".");
84 else
85 out.log(astring("no window found for ") + title + ".");
86 return 0;
87}
88
89#else
90// non-windows implementation is a no-op.
91int main(int argc, char *argv[])
92{
93 return 0;
94}
95#endif
96
97#ifdef __BUILD_STATIC_APPLICATION__
98 // static dependencies found by buildor_gen_deps.sh:
99 #include <algorithms/sorts.cpp>
102 #include <basis/astring.cpp>
104 #include <basis/environment.cpp>
105 #include <basis/guards.cpp>
106 #include <basis/mutex.cpp>
107 #include <basis/utf_conversion.cpp>
115 #include <filesystem/directory.cpp>
116 #include <filesystem/filename.cpp>
119 #include <structures/checksums.cpp>
125 #include <textual/parser_bits.cpp>
126 #include <timely/earth_time.cpp>
127 #include <timely/time_stamp.cpp>
128#endif // __BUILD_STATIC_APPLICATION__
129
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
virtual char get(int index) const
a constant peek at the string's internals at the specified index.
Definition astring.cpp:138
virtual basis::outcome log(const basis::base_string &info, int filter)
sends the string "info" to the standard output device.
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
int main(int argc, char *argv[])
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
char flexichar
Definition definitions.h:58
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
Support for unicode builds.
Aids in achievement of platform independence.
void * window_handle