Initial commit.

This commit is contained in:
knatech 2014-01-26 01:54:31 +09:00
commit 351bed51f6
36 changed files with 7680 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.obj
*.lib
*.exe

11
.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>brain-essential</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

674
brainapi-0.13/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

114
brainapi-0.13/brainapi.cpp Normal file
View File

@ -0,0 +1,114 @@
#include "brainapi.h"
_Res_Open_win Res_Open_win = NULL;
_Res_Close_win Res_Close_win = NULL;
_Font_Open_win Font_Open_win = NULL;
_Font_Close_win Font_Close_win = NULL;
_SHDicToolsInit SHDicToolsInit = NULL;
_Win2DicKey_NewPF_win Win2DicKey_NewPF_win = NULL;
_TPanel_Initialize_win TPanel_Initialize_win = NULL;
_TPanel_Terminate_win TPanel_Terminate_win = NULL;
_SLCD_on_win SLCD_on_win = NULL;
_SLCD_off_win SLCD_off_win = NULL;
_SLCD_disp_rectangle_win SLCD_disp_rectangle_win = NULL;
_PadEditor_win PadEditor_win = NULL;
_PadEditorButton_Num PadEditorButton_Num = NULL;
_SHDicGetMessageID SHDicGetMessageID = NULL;
_PadPenProc PadPenProc = NULL;
_PadPenProc_after PadPenProc_after = NULL;
_TPanel_PowerHandler TPanel_PowerHandler = NULL;
_EdSetSubBacklightState EdSetSubBacklightState = NULL;
_SSHOT_WriteSubLcdBMP2File_win SSHOT_WriteSubLcdBMP2File_win = NULL;
_EdGetDisablePowerOff EdGetDisablePowerOff = NULL;
_EdSetDisablePowerOff EdSetDisablePowerOff = NULL;
_EdUpdateBacklightState EdUpdateBacklightState = NULL;
_EdKeepBacklightState EdKeepBacklightState = NULL;
_EdFreeBacklightState EdFreeBacklightState = NULL;
_EdSetBacklightBright EdSetBacklightBright = NULL;
_EdKeepBacklightBright EdKeepBacklightBright = NULL;
_EdMrSensorGetState EdMrSensorGetState = NULL;
_EdMrSensorDisable EdMrSensorDisable = NULL;
_EdMrSensorEnable EdMrSensorEnable = NULL;
_EdMmMapIoSpace EdMmMapIoSpace = NULL;
_EdMmUnmapIoSpace EdMmUnmapIoSpace = NULL;
static HMODULE g_hBrainLib = NULL;
int brainApisEnabled() {
return g_hBrainLib == NULL ? 0 : 1;
}
int loadBrainApis() {
g_hBrainLib = LoadLibrary(_T("SharpLib.dll"));
if (g_hBrainLib == NULL)
return 0;
Res_Open_win = (_Res_Open_win)
GetProcAddress(g_hBrainLib, _T("Res_Open_win"));
Res_Close_win = (_Res_Close_win)
GetProcAddress(g_hBrainLib, _T("Res_Close_win"));
Font_Open_win = (_Font_Open_win)
GetProcAddress(g_hBrainLib, _T("Font_Open_win"));
Font_Close_win = (_Font_Close_win)
GetProcAddress(g_hBrainLib, _T("Font_Close_win"));
SHDicToolsInit = (_SHDicToolsInit)
GetProcAddress(g_hBrainLib, _T("SHDicToolsInit"));
Win2DicKey_NewPF_win = (_Win2DicKey_NewPF_win)
GetProcAddress(g_hBrainLib, _T("Win2DicKey_NewPF_win"));
TPanel_Initialize_win = (_TPanel_Initialize_win)
GetProcAddress(g_hBrainLib, _T("TPanel_Initialize_win"));
TPanel_Terminate_win = (_TPanel_Terminate_win)
GetProcAddress(g_hBrainLib, _T("TPanel_Terminate_win"));
SLCD_on_win = (_SLCD_on_win)
GetProcAddress(g_hBrainLib, _T("SLCD_on_win"));
SLCD_off_win = (_SLCD_off_win)
GetProcAddress(g_hBrainLib, _T("SLCD_off_win"));
SLCD_disp_rectangle_win = (_SLCD_disp_rectangle_win)
GetProcAddress(g_hBrainLib, _T("SLCD_disp_rectangle_win"));
PadEditor_win = (_PadEditor_win)
GetProcAddress(g_hBrainLib, _T("PadEditor_win"));
PadEditorButton_Num = (_PadEditorButton_Num)
GetProcAddress(g_hBrainLib, _T("PadEditorButton_Num"));
SHDicGetMessageID = (_SHDicGetMessageID)
GetProcAddress(g_hBrainLib, _T("SHDicGetMessageID"));
PadPenProc = (_PadPenProc)
GetProcAddress(g_hBrainLib, _T("PadPenProc"));
PadPenProc_after = (_PadPenProc_after)
GetProcAddress(g_hBrainLib, _T("PadPenProc_after"));
TPanel_PowerHandler = (_TPanel_PowerHandler)
GetProcAddress(g_hBrainLib, _T("TPanel_PowerHandler"));
EdSetSubBacklightState = (_EdSetSubBacklightState)
GetProcAddress(g_hBrainLib, _T("EdSetSubBacklightState"));
SSHOT_WriteSubLcdBMP2File_win = (_SSHOT_WriteSubLcdBMP2File_win)
GetProcAddress(g_hBrainLib, _T("SSHOT_WriteSubLcdBMP2File_win"));
EdGetDisablePowerOff = (_EdGetDisablePowerOff)
GetProcAddress(g_hBrainLib, _T("EdGetDisablePowerOff"));
EdSetDisablePowerOff = (_EdSetDisablePowerOff)
GetProcAddress(g_hBrainLib, _T("EdSetDisablePowerOff"));
EdUpdateBacklightState = (_EdUpdateBacklightState)
GetProcAddress(g_hBrainLib, _T("EdUpdateBacklightState"));
EdKeepBacklightState = (_EdKeepBacklightState)
GetProcAddress(g_hBrainLib, _T("EdKeepBacklightState"));
EdFreeBacklightState = (_EdFreeBacklightState)
GetProcAddress(g_hBrainLib, _T("EdFreeBacklightState"));
EdSetBacklightBright = (_EdSetBacklightBright)
GetProcAddress(g_hBrainLib, _T("EdSetBacklightBright"));
EdKeepBacklightBright = (_EdKeepBacklightBright)
GetProcAddress(g_hBrainLib, _T("EdKeepBacklightBright"));
EdMrSensorGetState = (_EdMrSensorGetState)
GetProcAddress(g_hBrainLib, _T("EdMrSensorGetState"));
EdMrSensorDisable = (_EdMrSensorDisable)
GetProcAddress(g_hBrainLib, _T("EdMrSensorDisable"));
EdMrSensorEnable = (_EdMrSensorEnable)
GetProcAddress(g_hBrainLib, _T("EdMrSensorEnable"));
EdMmMapIoSpace = (_EdMmMapIoSpace)
GetProcAddress(g_hBrainLib, _T("EdMmMapIoSpace"));
EdMmUnmapIoSpace = (_EdMmUnmapIoSpace)
GetProcAddress(g_hBrainLib, _T("EdMmUnmapIoSpace"));
return 1;
}
void freeBrainApis() {
FreeLibrary(g_hBrainLib);
}

78
brainapi-0.13/brainapi.h Normal file
View File

@ -0,0 +1,78 @@
#ifndef BRAINAPI_H
#define BRAINAPI_H
#include "windows.h"
typedef int (WINAPI *_Res_Open_win)(const wchar_t *);
typedef int (WINAPI *_Res_Close_win)();
typedef int (WINAPI *_Font_Open_win)(const wchar_t *);
typedef int (WINAPI *_Font_Close_win)();
typedef int (WINAPI *_SHDicToolsInit)(HWND);
typedef int (WINAPI *_Win2DicKey_NewPF_win)(int, unsigned long);
typedef void (WINAPI *_TPanel_Initialize_win)(HWND);
typedef void (WINAPI *_TPanel_Terminate_win)();
typedef int (WINAPI *_SLCD_on_win)();
typedef int (WINAPI *_SLCD_off_win)();
typedef int (WINAPI *_SLCD_disp_rectangle_win)(int, int, int, int);
typedef int (WINAPI *_PadEditor_win)(HWND, int, int, const void *);
typedef int (WINAPI *_PadEditorButton_Num)(HWND);
typedef unsigned int (WINAPI *_SHDicGetMessageID)(int);
typedef int (WINAPI *_PadPenProc)(int, int);
typedef int (WINAPI *_PadPenProc_after)();
typedef int (WINAPI *_TPanel_PowerHandler)(int);
typedef int (WINAPI *_EdSetSubBacklightState)(int);
typedef int (WINAPI *_SSHOT_WriteSubLcdBMP2File_win)();
typedef int (WINAPI *_EdGetDisablePowerOff)();
typedef int (WINAPI *_EdSetDisablePowerOff)(int);
typedef int (WINAPI *_EdUpdateBacklightState)();
typedef HANDLE (WINAPI *_EdKeepBacklightState)(int, int);
typedef int (WINAPI *_EdFreeBacklightState)(HANDLE);
typedef void (WINAPI *_EdSetBacklightBright)(int);
typedef int (WINAPI *_EdKeepBacklightBright)(int, int);
typedef int (WINAPI *_EdMrSensorGetState)();
typedef int (WINAPI *_EdMrSensorDisable)();
typedef int (WINAPI *_EdMrSensorEnable)();
typedef void * (WINAPI *_EdMmMapIoSpace)(unsigned long, unsigned long, int);
typedef void (WINAPI *_EdMmUnmapIoSpace)(void *, unsigned long);
extern _Res_Open_win Res_Open_win;
extern _Res_Close_win Res_Close_win;
extern _Font_Open_win Font_Open_win;
extern _Font_Close_win Font_Close_win;
extern _SHDicToolsInit SHDicToolsInit;
extern _Win2DicKey_NewPF_win Win2DicKey_NewPF_win;
extern _TPanel_Initialize_win TPanel_Initialize_win;
extern _TPanel_Terminate_win TPanel_Terminate_win;
extern _SLCD_on_win SLCD_on_win;
extern _SLCD_off_win SLCD_off_win;
extern _SLCD_disp_rectangle_win SLCD_disp_rectangle_win;
extern _PadEditor_win PadEditor_win;
extern _PadEditorButton_Num PadEditorButton_Num;
extern _SHDicGetMessageID SHDicGetMessageID;
extern _PadPenProc PadPenProc;
extern _PadPenProc_after PadPenProc_after;
extern _TPanel_PowerHandler TPanel_PowerHandler;
extern _EdSetSubBacklightState EdSetSubBacklightState;
extern _SSHOT_WriteSubLcdBMP2File_win SSHOT_WriteSubLcdBMP2File_win;
extern _EdGetDisablePowerOff EdGetDisablePowerOff;
extern _EdSetDisablePowerOff EdSetDisablePowerOff;
extern _EdUpdateBacklightState EdUpdateBacklightState;
extern _EdKeepBacklightState EdKeepBacklightState;
extern _EdFreeBacklightState EdFreeBacklightState;
extern _EdSetBacklightBright EdSetBacklightBright;
extern _EdKeepBacklightBright EdKeepBacklightBright;
extern _EdMrSensorGetState EdMrSensorGetState;
extern _EdMrSensorDisable EdMrSensorDisable;
extern _EdMrSensorEnable EdMrSensorEnable;
extern _EdMmMapIoSpace EdMmMapIoSpace;
extern _EdMmUnmapIoSpace EdMmUnmapIoSpace;
extern "C" {
int brainApisEnabled();
int loadBrainApis();
void freeBrainApis();
}
#endif // BRAINAPI_H

17
brainapi-0.13/brainapi.mk Normal file
View File

@ -0,0 +1,17 @@
TARGET=brainapi-0.13.lib
CPP=clarm
CPPFLAGS=/nologo /W3 /O2 /EHsc /QRarch4T /QRinterwork-return \
/D "ARM" /D "_ARM_" /D "ARMV4I" /D UNDER_CE=400 \
/D "UNICODE" /D "_UNICODE"
OBJS=\
brainapi.obj \
all : $(TARGET)
$(TARGET) : $(OBJS)
lib /NOLOGO /OUT:$@ $(OBJS)
clean :
-del $(TARGET) $(OBJS)
brainapi.obj : brainapi.h

674
kncecomm-0.18/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -0,0 +1,290 @@
#include "kncecomm.h"
#include <string>
#include <algorithm>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_APPLICATION_LIST = 101,
IDC_PATH_EDIT = 102,
IDC_PATH_BROWSE = 103
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onApplicationList(HWND hDlg, int event);
static void onPathEdit(HWND hDlg, int event);
static void onPathBrowse(HWND hDlg, int event);
static void updateApplicationList(HWND hDlg);
static void addToBucket(vector<pair<tstring, tstring> > &captToPath,
const tstring &dir);
extern HINSTANCE g_hInstance;
struct KnceAppDlgData {
HFONT hFont;
KnceChooseApplicationParams *chooseApplicationParams;
vector<tstring> applicationPaths;
bool eventProcessing;
};
bool showChooseApplicationDialog(HWND hOwnerWindow,
KnceChooseApplicationParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_APPLICATION"),
hOwnerWindow, (DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_APPLICATION_LIST:
onApplicationList(hDlg, event);
break;
case IDC_PATH_EDIT:
onPathEdit(hDlg, event);
break;
case IDC_PATH_BROWSE:
onPathBrowse(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceAppDlgData *data = new KnceAppDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->hFont = knceCreateDefaultFont(true, 100, false, false);
knceSetDialogFont(hDlg, data->hFont);
data->chooseApplicationParams = (KnceChooseApplicationParams *)params;
data->eventProcessing = false;
updateApplicationList(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
GetWindowText(hPathEdit, data->chooseApplicationParams->fileName,
MAX_PATH);
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
int index = SendMessage(hAppList, LB_GETCURSEL, 0, 0);
if (index == -1) {
tstring title = data->chooseApplicationParams->fileName;
int sepPos = title.rfind(_T('\\'));
if (sepPos != tstring::npos)
title = title.substr(sepPos + 1);
int extPos = title.rfind(_T('.'));
if (extPos != tstring::npos)
title = title.substr(0, extPos);
_tcsncpy(data->chooseApplicationParams->title, title.c_str(), 256);
}
else {
TCHAR *appNameBuf = new TCHAR[
SendMessage(hAppList, LB_GETTEXTLEN, index, 0) + 1];
SendMessage(hAppList, LB_GETTEXT, index, (LPARAM)appNameBuf);
_tcsncpy(data->chooseApplicationParams->title, appNameBuf, 256);
delete [] appNameBuf;
}
DeleteObject(data->hFont);
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
DeleteObject(data->hFont);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onApplicationList(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_SELCHANGE || data->eventProcessing)
return;
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
int index = SendMessage(hAppList, LB_GETCURSEL, 0, 0);
if (index == -1)
return;
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
data->eventProcessing = true;
SetWindowText(hPathEdit, data->applicationPaths[index].c_str());
data->eventProcessing = false;
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
static void onPathEdit(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != EN_CHANGE || data->eventProcessing)
return;
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
data->eventProcessing = true;
SendMessage(hAppList, LB_SETCURSEL, -1, 0);
data->eventProcessing = false;
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
static void onPathBrowse(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
KnceChooseFileParams params = {0};
params.isSaveFile = false;
params.filters = _T("Programs (*.exe)|*.exe|All files (*.*)|*.*");
if (knceChooseFile(hDlg, &params)) {
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
SetWindowText(hPathEdit, params.fileName);
}
}
static void updateApplicationList(HWND hDlg) {
int i;
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
vector<pair<tstring, tstring> > captToPath;
tstring dir = _T("\\NAND3\\ƒAƒvƒŠ");
tstring findPath = dir + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
}
}
FindClose(hFind);
dir = _T("\\Storage Card\\ƒAƒvƒŠ");
findPath = dir + _T("\\*.*");
hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
}
}
FindClose(hFind);
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
SendMessage(hAppList, LB_RESETCONTENT, 0, 0);
data->applicationPaths.clear();
int numApps = captToPath.size();
for (i = 0; i < numApps; i++) {
SendMessage(hAppList, LB_ADDSTRING, 0,
(LPARAM)captToPath[i].first.c_str());
data->applicationPaths.push_back(captToPath[i].second);
}
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
}
static void addToBucket(vector<pair<tstring, tstring> > &captToPath,
const tstring &dir) {
tstring indexFileName = dir + _T("\\index.din");
tstring appFileName = dir + _T("\\AppMain.exe");
if (GetFileAttributes(indexFileName.c_str()) == -1 ||
GetFileAttributes(appFileName.c_str()) == -1) {
return;
}
tstring capt = dir.substr(dir.rfind('\\') + 1);
tstring captLower = capt;
transform(captLower.begin(), captLower.end(), captLower.begin(),
_totlower);
vector<pair<tstring, tstring> >::iterator iter = captToPath.begin();
for ( ; iter != captToPath.end(); iter++) {
tstring captTemp = iter->first;
transform(captTemp.begin(), captTemp.end(), captTemp.begin(),
_totlower);
if (captTemp.compare(captLower) > 0)
break;
}
captToPath.insert(iter, make_pair(capt, appFileName));
}

View File

@ -0,0 +1,146 @@
#include "kncecomm.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_KEY_LABEL = 103
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam,
LPARAM lParam);
static void onInitDialog(HWND hDlg, void *params);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onTimer(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceCapKeyDlgData {
HFONT hFont;
int *capturedKeyCode;
};
bool showCaptureKeyDialog(HWND hOwnerWindow, int *capturedKeyCode) {
int ret = DialogBoxParam(g_hInstance, _T("CAPTURE_KEY"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)capturedKeyCode);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
default:
return false;
}
return true;
}
case WM_TIMER:
onTimer(hDlg);
return true;
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceCapKeyDlgData *data = new KnceCapKeyDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->hFont = knceCreateDefaultFont(true, 100, false, false);
knceSetDialogFont(hDlg, data->hFont);
data->capturedKeyCode = (int *)params;
*data->capturedKeyCode = -1;
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
SetTimer(hDlg, 1, 100, NULL);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
KillTimer(hDlg, 1);
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
KillTimer(hDlg, 1);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onTimer(HWND hDlg) {
int i;
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
int keyCode = -1;
for (i = 0; i < 256; i++) {
if (GetAsyncKeyState(i) != 0) {
keyCode = i;
break;
}
}
if (keyCode == -1 || keyCode == 1 ||
keyCode == HARD_KEY_EXECUTE ||
keyCode == HARD_KEY_BACK ||
keyCode == HARD_KEY_LEFT || keyCode == HARD_KEY_UP ||
keyCode == HARD_KEY_RIGHT || keyCode == HARD_KEY_DOWN)
{
return;
}
*data->capturedKeyCode = keyCode;
TCHAR keyNameCStr[128];
knceRealKeyCodeToName(keyNameCStr, 128, keyCode);
HWND hKeyLabel = GetDlgItem(hDlg, IDC_KEY_LABEL);
SetWindowText(hKeyLabel, keyNameCStr);
HWND hOkButton = GetDlgItem(hDlg, IDOK);
if (!IsWindowEnabled(hOkButton)) {
EnableWindow(hOkButton, true);
SetFocus(hOkButton);
}
}

Binary file not shown.

Binary file not shown.

692
kncecomm-0.18/kncecomm.cpp Normal file
View File

@ -0,0 +1,692 @@
#include "kncecomm.h"
#include <algorithm>
#include <map>
using namespace std;
enum {
NWUS_KEYBD_REPEAT_CHANGED = 2
};
extern "C" void WINAPI NotifyWinUserSystem(UINT uEvent);
bool showChooseDirectoryDialog(HWND hOwnerWindow,
KnceChooseDirectoryParams *params);
bool showChooseFileDialog(HWND hOwnerWindow, KnceChooseFileParams *params);
bool showChooseFontDialog(HWND hOwnerWindow, KnceChooseFontParams *params);
bool showCaptureKeyDialog(HWND hOwnerWindow, int *capturedKeyCode);
bool showChooseApplicationDialog(HWND hOwnerWindow,
KnceChooseApplicationParams *params);
void registerWaitBoxClass();
void unregisterWaitBoxClass();
HWND createWaitBox(HWND hOwnerWindow, const tstring &msg);
void destroyWaitBox(HWND hWnd);
static int CALLBACK enumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData);
static int CALLBACK enumFixedFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
static int CALLBACK enumVariableFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
static int CALLBACK checkFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData);
static bool matchStringsIgnoreCase(const tstring &str1, const tstring &str2);
static std::tstring toLowerString(const std::tstring &str);
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim);
HINSTANCE g_hInstance = NULL;
static map<int, tstring> g_realKeyCodeToNameTable;
static map<tstring, int> g_realKeyNameToCodeTable;
static int g_savedKeyRepeatRefCount = 0;
static int g_savedKeyRepeatInitialDelay = 0;
static int g_savedKeyRepeatRate = 0;
static vector<tstring> g_localizedFixedFontNames;
static vector<tstring> g_localizedPropFontNames;
BOOL APIENTRY DllMain(HANDLE hInst, DWORD fdwReason, LPVOID pvReserved) {
int i;
if (fdwReason == DLL_PROCESS_ATTACH) {
g_hInstance = (HINSTANCE)hInst;
registerWaitBoxClass();
g_localizedFixedFontNames.push_back(_T("MS Gothic"));
g_localizedFixedFontNames.push_back(_T("VL Gothic"));
g_localizedFixedFontNames.push_back(_T("IPAGothic"));
g_localizedFixedFontNames.push_back(_T("Sazanami Gothic"));
g_localizedFixedFontNames.push_back(_T("Kochi Gothic"));
g_localizedFixedFontNames.push_back(_T("mikachan"));
g_localizedPropFontNames.push_back(_T("MS PGothic"));
g_localizedPropFontNames.push_back(_T("VL PGothic"));
g_localizedPropFontNames.push_back(_T("IPAPGothic"));
g_localizedPropFontNames.push_back(_T("Sazanami Gothic"));
g_localizedPropFontNames.push_back(_T("Kochi Gothic"));
g_localizedPropFontNames.push_back(_T("mikachan-P"));
g_localizedPropFontNames.push_back(_T("mikachan-PB"));
g_localizedPropFontNames.push_back(_T("mikachan-PS"));
static int realKeyCodes[] = {
0x11, 0x70,
0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x79, 0x24,
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55,
0x49, 0x4f, 0x50,
0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4a,
0x4b, 0x4c,
0x5a, 0x58, 0x43, 0x56, 0x42, 0x4e, 0x4d,
0xbd,
0x14, 0x23, 0x08,
0x21, 0x22, 0xdb, 0xdd,
0xbe, 0xbc,
0xdc, 0xba, 0xbf,
0x1b, 0x0d,
0x25, 0x26, 0x27, 0x28
};
static TCHAR *realKeyCStrs[] = {
_T("POWER"), _T("WHOLESEARCH"),
_T("CONTENTS1"), _T("CONTENTS2"), _T("CONTENTS3"), _T("CONTENTS4"),
_T("SWITCH"), _T("BOOKMARKS"), _T("LIBRARY"), _T("MENU"),
_T("Q"), _T("W"), _T("E"), _T("R"), _T("T"), _T("Y"), _T("U"),
_T("I"), _T("O"), _T("P"),
_T("A"), _T("S"), _T("D"), _T("F"), _T("G"), _T("H"), _T("J"),
_T("K"), _T("L"),
_T("Z"), _T("X"), _T("C"), _T("V"), _T("B"), _T("N"), _T("M"),
_T("HYPHEN"),
_T("FUNCTION"), _T("CLEAR"), _T("BACKSPACE"),
_T("PAGEUP"), _T("PAGEDOWN"), _T("VOLUMEUP"), _T("VOLUMEDOWN"),
_T("LARGER"), _T("SMALLER"),
_T("VOICE"), _T("DESCRIPTION"), _T("SJUMP"),
_T("BACK"),_T("EXECUTE"),
_T("LEFT"), _T("UP"), _T("RIGHT"), _T("DOWN")
};
int numRealKeys = sizeof(realKeyCodes) / sizeof(int);
for (i = 0; i < numRealKeys; i++) {
g_realKeyCodeToNameTable[realKeyCodes[i]] = realKeyCStrs[i];
g_realKeyNameToCodeTable[realKeyCStrs[i]] = realKeyCodes[i];
}
}
else if (fdwReason == DLL_PROCESS_DETACH)
unregisterWaitBoxClass();
return true;
}
KNCECOMM_API int knceChooseDirectory(HWND hOwnerWindow,
KnceChooseDirectoryParams *params) {
return showChooseDirectoryDialog(hOwnerWindow, params);
}
KNCECOMM_API int knceChooseFile(HWND hOwnerWindow,
KnceChooseFileParams *params) {
return showChooseFileDialog(hOwnerWindow, params);
}
KNCECOMM_API int knceChooseFont(HWND hOwnerWindow,
KnceChooseFontParams *params) {
return showChooseFontDialog(hOwnerWindow, params);
}
KNCECOMM_API int knceCaptureKey(HWND hOwnerWindow,
int *capturedKeyCode) {
return showCaptureKeyDialog(hOwnerWindow, capturedKeyCode);
}
KNCECOMM_API int knceChooseApplication(HWND hOwnerWindow,
KnceChooseApplicationParams *params) {
return showChooseApplicationDialog(hOwnerWindow, params);
}
KNCECOMM_API HWND knceCreateWaitBox(HWND hOwnerWindow,
const TCHAR *msg) {
if (msg == NULL)
return createWaitBox(hOwnerWindow, _T(""));
else
return createWaitBox(hOwnerWindow, msg);
}
KNCECOMM_API void knceDestroyWaitBox(HWND hWnd) {
destroyWaitBox(hWnd);
}
KNCECOMM_API void knceGetCurrentDirectory(TCHAR *path, int pathSize) {
TCHAR modulePath[MAX_PATH];
GetModuleFileName(NULL, modulePath, MAX_PATH);
TCHAR *p = _tcschr(modulePath, _T('\0'));
for ( ; p >= modulePath; p--) {
if (*p == _T('\\')) {
*p = _T('\0');
break;
}
}
_tcsncpy(path, modulePath, pathSize);
}
KNCECOMM_API int knceCompareFileTime(int *failed, const TCHAR *fileName1,
const TCHAR *fileName2) {
failed = 0;
WIN32_FIND_DATA fd1;
HANDLE hFind = FindFirstFile(fileName1, &fd1);
if (hFind == INVALID_HANDLE_VALUE) {
*failed = 1;
return 0;
}
FindClose(hFind);
WIN32_FIND_DATA fd2;
hFind = FindFirstFile(fileName2, &fd2);
if (hFind == INVALID_HANDLE_VALUE) {
*failed = 1;
return 0;
}
int result = CompareFileTime(&fd1.ftLastWriteTime, &fd2.ftLastWriteTime);
FindClose(hFind);
return result;
}
KNCECOMM_API int knceRegisterHotKey(HWND hWnd, unsigned int mods,
unsigned int keyCode)
{
TCHAR hotKeyNameCStr[64];
_sntprintf(hotKeyNameCStr, 64, _T("KNCECOMM_HOTKEY_%d_%d"), keyCode, mods);
int hotKeyId = GlobalAddAtom(hotKeyNameCStr);
if (!RegisterHotKey(hWnd, hotKeyId, mods, keyCode)) {
GlobalDeleteAtom(hotKeyId);
return 0;
}
return hotKeyId;
}
KNCECOMM_API int knceUnregisterHotKey(HWND hWnd, int id) {
if (id == 0)
return 1;
int ret = UnregisterHotKey(hWnd, id) != 0;
GlobalDeleteAtom(id);
return ret;
}
KNCECOMM_API int knceRealKeyCodeToName(TCHAR *name, int nameSize, int code) {
if (code < 0 || code > 255)
return 0;
map<int, tstring>::const_iterator iter =
g_realKeyCodeToNameTable.find(code);
if (iter == g_realKeyCodeToNameTable.end())
_sntprintf(name, nameSize, _T("UNKNOWN%d"), code);
else
_tcsncpy(name, iter->second.c_str(), nameSize);
return 1;
}
KNCECOMM_API int knceRealKeyNameToCode(const TCHAR *name) {
map<tstring, int>::const_iterator iter =
g_realKeyNameToCodeTable.find(name);
if (iter == g_realKeyNameToCodeTable.end()) {
int code = 0;
if (_stscanf(name, _T("UNKNOWN%d"), &code) == 1) {
if (code < 0 || code > 255)
return -1;
else
return code;
}
else
return -1;
}
else
return iter->second;
}
KNCECOMM_API void knceChangeKeyRepeatSpeed(int initDelay, int repeatRate) {
if (g_savedKeyRepeatRefCount++ > 0)
return;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\keybd"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
DWORD val = 0;
DWORD size = sizeof(DWORD);
RegQueryValueEx(hKey, _T("InitialDelay"), NULL, 0,
(BYTE *)&val, &size);
g_savedKeyRepeatInitialDelay = val;
RegQueryValueEx(hKey, _T("RepeatRate"), NULL, 0, (BYTE *)&val, &size);
g_savedKeyRepeatRate = val;
val = (DWORD)initDelay;
RegSetValueEx(hKey, _T("InitialDelay"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
val = (unsigned long)repeatRate;
RegSetValueEx(hKey, _T("RepeatRate"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
RegCloseKey(hKey);
NotifyWinUserSystem(NWUS_KEYBD_REPEAT_CHANGED);
}
KNCECOMM_API void knceRestoreKeyRepeatSpeed() {
if (--g_savedKeyRepeatRefCount > 0)
return;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\keybd"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
DWORD val = 0;
DWORD size = sizeof(DWORD);
val = (DWORD)g_savedKeyRepeatInitialDelay;
RegSetValueEx(hKey, _T("InitialDelay"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
val = (DWORD)g_savedKeyRepeatRate;
RegSetValueEx(hKey, _T("RepeatRate"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
RegCloseKey(hKey);
NotifyWinUserSystem(NWUS_KEYBD_REPEAT_CHANGED);
}
KNCECOMM_API HFONT knceCreateFont(const TCHAR *faceName, int pointSize,
int isBold, int isItalic) {
LOGFONT logFont = {0};
_tcsncpy(logFont.lfFaceName, faceName, LF_FACESIZE);
if (isBold)
logFont.lfWeight = FW_BOLD;
if (isItalic)
logFont.lfItalic = true;
HDC hDC = GetDC(NULL);
logFont.lfHeight = -ceil(GetDeviceCaps(hDC, LOGPIXELSY) *
pointSize / 720.0);
ReleaseDC(NULL, hDC);
logFont.lfCharSet = DEFAULT_CHARSET;
return CreateFontIndirect(&logFont);
}
KNCECOMM_API void knceGetDefaultFontName(TCHAR *fontName, int fontNameLen) {
tstring selectedFaceName;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\knatech\\kncecomm"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
TCHAR defaultFontNameCStr[LF_FACESIZE];
DWORD size = LF_FACESIZE;
if (RegQueryValueEx(hKey, _T("DefaultFontName"), NULL, NULL,
(BYTE *)defaultFontNameCStr, &size) == 0) {
selectedFaceName = defaultFontNameCStr;
}
_tcsncpy(fontName, selectedFaceName.c_str(), fontNameLen);
}
KNCECOMM_API void knceSetDefaultFontName(const TCHAR *fontName) {
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\knatech\\kncecomm"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
RegSetValueEx(hKey, _T("DefaultFontName"), 0, REG_SZ,
(const BYTE *)fontName, (_tcslen(fontName) + 1) * sizeof(TCHAR));
RegCloseKey(hKey);
}
KNCECOMM_API HFONT knceCreateDefaultFont(int isVariable, int pointSize,
int isBold, int isItalic) {
int i, j;
tstring selectedFaceName;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\knatech\\kncecomm"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
TCHAR defaultFontNameCStr[LF_FACESIZE];
DWORD size = LF_FACESIZE;
if (RegQueryValueEx(hKey, _T("DefaultFontName"), NULL, NULL,
(BYTE *)defaultFontNameCStr, &size) == 0) {
selectedFaceName = defaultFontNameCStr;
}
RegCloseKey(hKey);
if (selectedFaceName.empty()) {
vector<tstring> fontNames;
EnumFonts(GetDC(NULL), NULL, enumFontsProc, (LPARAM)&fontNames);
int numFonts = fontNames.size();
if (isVariable) {
// try localized
int numLocalized = g_localizedPropFontNames.size();
for (i = 0; i < numLocalized; i++) {
tstring testFontName = g_localizedPropFontNames[i];
for (j = 0; j < numFonts; j++) {
if (fontNames[j] == testFontName) {
selectedFaceName = testFontName;
break;
}
}
if (!selectedFaceName.empty())
break;
}
// fallback to collected variable fonts
if (selectedFaceName.empty()) {
vector<tstring> variableFontNames;
EnumFonts(GetDC(NULL), NULL, enumVariableFontsProc,
(LPARAM)&variableFontNames);
if (!variableFontNames.empty())
selectedFaceName = variableFontNames[0];
if (selectedFaceName == _T("Tahoma")) {
if (variableFontNames.size() > 1)
selectedFaceName = variableFontNames[1];
else
selectedFaceName = _T("");
}
}
}
else {
// try localized
int numLocalized = g_localizedFixedFontNames.size();
for (i = 0; i < numLocalized; i++) {
tstring testFontName = g_localizedFixedFontNames[i];
for (j = 0; j < numFonts; j++) {
if (fontNames[j] == testFontName) {
selectedFaceName = testFontName;
break;
}
}
if (!selectedFaceName.empty())
break;
}
// fallback to collected fixed fonts
if (selectedFaceName.empty()) {
vector<tstring> fixedFontNames;
EnumFonts(GetDC(NULL), NULL, enumFixedFontsProc,
(LPARAM)&fixedFontNames);
if (!fixedFontNames.empty())
selectedFaceName = fixedFontNames[0];
}
}
// finally, fallback to all collected fonts
if (selectedFaceName.empty()) {
if (numFonts > 0)
selectedFaceName = fontNames[0];
if (selectedFaceName == _T("Tahoma")) {
if (numFonts > 1)
selectedFaceName = fontNames[1];
else
selectedFaceName = _T("");
}
}
}
LOGFONT logFont = {0};
if (!selectedFaceName.empty())
_tcscpy(logFont.lfFaceName, selectedFaceName.c_str());
logFont.lfPitchAndFamily = isVariable ? VARIABLE_PITCH : FIXED_PITCH;
if (isBold)
logFont.lfWeight = FW_BOLD;
if (isItalic)
logFont.lfItalic = true;
HDC hDC = GetDC(NULL);
logFont.lfHeight = -ceil(GetDeviceCaps(hDC, LOGPIXELSY) *
pointSize / 720.0);
ReleaseDC(NULL, hDC);
logFont.lfCharSet = DEFAULT_CHARSET;
return CreateFontIndirect(&logFont);
}
KNCECOMM_API int knceObtainFontNames(KnceFontName **fontNames, int pitchType) {
int i;
vector<tstring> names;
switch (pitchType) {
case KNCE_FONT_PITCH_FIXED:
EnumFonts(GetDC(NULL), NULL, enumFixedFontsProc, (LPARAM)&names);
break;
case KNCE_FONT_PITCH_VARIABLE:
EnumFonts(GetDC(NULL), NULL, enumVariableFontsProc, (LPARAM)&names);
break;
default:
EnumFonts(GetDC(NULL), NULL, enumFontsProc, (LPARAM)&names);
break;
}
int numNames = names.size();
*fontNames = (KnceFontName *)malloc(numNames * sizeof(KnceFontName));
for (i = 0; i < numNames; i++)
_tcsncpy((*fontNames)[i].fontName, names[i].c_str(), LF_FACESIZE);
return numNames;
}
KNCECOMM_API int knceFontExists(const TCHAR *name) {
return EnumFonts(GetDC(NULL), NULL, checkFontProc,
(LPARAM)&tstring(name)) == 0;
}
KNCECOMM_API void knceGetFontAttributes(HFONT hFont, TCHAR *faceName,
int faceNameSize, int *pointSize, int *isBold, int *isItalic) {
LOGFONT logFont;
GetObject(hFont, sizeof(LOGFONT), &logFont);
_tcsncpy(faceName, logFont.lfFaceName, faceNameSize);
HDC hDC = GetDC(NULL);
*pointSize = -ceil(logFont.lfHeight * 720.0 /
GetDeviceCaps(hDC, LOGPIXELSY));
ReleaseDC(NULL, hDC);
*isItalic = logFont.lfItalic != 0 ? 1 : 0;
*isBold = logFont.lfWeight >= FW_BOLD ? 1 : 0;
}
KNCECOMM_API void knceSetDialogFont(HWND hDlg, HFONT hFont) {
SendMessage(hDlg, WM_SETFONT, (WPARAM)hFont, 0);
HWND hChild = GetWindow(hDlg, GW_CHILD);
if (hChild != NULL) {
SendMessage(hChild, WM_SETFONT, (WPARAM)hFont, 0);
while (true) {
hChild = GetWindow(hChild, GW_HWNDNEXT);
if (hChild == NULL)
break;
SendMessage(hChild, WM_SETFONT, (WPARAM)hFont, 0);
}
}
}
KNCECOMM_API int knceMatchFileExtension(const TCHAR *fileName,
const TCHAR *pat) {
tstring fileNameStr = fileName;
tstring patStr = pat;
if (patStr == _T("*.*"))
return 1;
if (patStr.length() < 2 || patStr.substr(0, 2) != _T("*."))
return 0;
int fileNameLen = fileNameStr.length();
tstring ext = patStr.substr(1);
int extLen = ext.length();
if (fileNameLen < extLen)
return 0;
tstring fileExt = fileNameStr.substr(fileNameLen - extLen, extLen);
if (!matchStringsIgnoreCase(fileExt, ext))
return 0;
return 1;
}
KNCECOMM_API int knceMatchMultiFileExtension(const TCHAR *fileName,
const TCHAR *pats) {
int i;
vector<tstring> patList;
split(patList, pats, _T(";"));
int numPats = patList.size();
for (i = 0; i < numPats; i++) {
if (knceMatchFileExtension(fileName, patList[i].c_str()))
return 1;
}
return 0;
}
KNCECOMM_API void knceDebugMessageBox(HWND hOwnerWindow,
const TCHAR *msg, ...) {
va_list args;
va_start(args, msg);
TCHAR msgCStr[256];
_vsntprintf(msgCStr, 256, msg, args);
MessageBox(hOwnerWindow, msgCStr, _T("Debug"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
va_end(args);
}
static int CALLBACK enumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@'))
names->push_back(lplf->lfFaceName);
return 1;
}
static int CALLBACK enumFixedFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == FIXED_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK enumVariableFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == VARIABLE_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK checkFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
const tstring *name = (tstring *)lpData;
if (tstring(lplf->lfFaceName) == *name)
return 0;
return 1;
}
static bool matchStringsIgnoreCase(const tstring &str1, const tstring &str2) {
return toLowerString(str1) == toLowerString(str2);
}
static std::tstring toLowerString(const std::tstring &str) {
tstring newStr = str;
transform(newStr.begin(), newStr.end(), newStr.begin(), _totlower);
return newStr;
}
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim) {
tstring strWork = str;
int cutAt = 0;
while ((cutAt = strWork.find_first_of(delim)) != tstring::npos) {
if (cutAt > 0)
result.push_back(strWork.substr(0, cutAt));
strWork = strWork.substr(cutAt + 1);
}
if (strWork.length() > 0)
result.push_back(strWork);
}

128
kncecomm-0.18/kncecomm.h Normal file
View File

@ -0,0 +1,128 @@
#ifndef KNCECOMM_H_
#define KNCECOMM_H_
#include <vector>
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
#ifdef KNCECOMM_EXPORTS
#define KNCECOMM_API __declspec(dllexport)
#else
#define KNCECOMM_API __declspec(dllimport)
#endif
#define HARD_KEY_POWER 0x11
#define HARD_KEY_WHOLESEARCH 0x70
#define HARD_KEY_CONTENTS1 0x71
#define HARD_KEY_CONTENTS2 0x72
#define HARD_KEY_CONTENTS3 0x73
#define HARD_KEY_CONTENTS4 0x74
#define HARD_KEY_SWITCH 0x75
#define HARD_KEY_BOOKMARKS 0x76
#define HARD_KEY_HOME 0x79
#define HARD_KEY_MENU 0x24
#define HARD_KEY_HYPHEN 0xbd
#define HARD_KEY_FUNCTION 0x14
#define HARD_KEY_CLEAR 0x23
#define HARD_KEY_BACKSPACE 0x08
#define HARD_KEY_PAGEUP 0x21
#define HARD_KEY_PAGEDOWN 0x22
#define HARD_KEY_VOLUMEUP 0xdb
#define HARD_KEY_VOLUMEDOWN 0xdd
#define HARD_KEY_LARGER 0xbe
#define HARD_KEY_SMALLER 0xbc
#define HARD_KEY_VOICE 0xdc
#define HARD_KEY_DESCRIPTION 0xba
#define HARD_KEY_SJUMP 0xbf
#define HARD_KEY_BACK 0x1b
#define HARD_KEY_EXECUTE 0x0d
#define HARD_KEY_LEFT 0x25
#define HARD_KEY_UP 0x26
#define HARD_KEY_RIGHT 0x27
#define HARD_KEY_DOWN 0x28
#define KNCE_FONT_PITCH_ALL 0
#define KNCE_FONT_PITCH_FIXED 1
#define KNCE_FONT_PITCH_VARIABLE 2
struct KnceChooseDirectoryParams {
TCHAR initialPath[MAX_PATH];
TCHAR directory[MAX_PATH];
};
struct KnceChooseFileParams {
bool isSaveFile;
const TCHAR *filters;
TCHAR initialPath[MAX_PATH];
TCHAR fileName[MAX_PATH];
};
struct KnceChooseFontParams {
HFONT hFont;
int isFixedOnly;
};
struct KnceChooseApplicationParams {
TCHAR title[256];
TCHAR fileName[MAX_PATH];
};
struct KnceFontName {
TCHAR fontName[LF_FACESIZE];
};
extern "C" {
KNCECOMM_API int knceChooseDirectory(HWND hOwnerWindow,
KnceChooseDirectoryParams *params);
KNCECOMM_API int knceChooseFile(HWND hOwnerWindow,
KnceChooseFileParams *params);
KNCECOMM_API int knceChooseFont(HWND hOwnerWindow,
KnceChooseFontParams *params);
KNCECOMM_API int knceCaptureKey(HWND hOwnerWindow, int *capturedKeyCode);
KNCECOMM_API int knceChooseApplication(HWND hOwnerWindow,
KnceChooseApplicationParams *params);
KNCECOMM_API HWND knceCreateWaitBox(HWND hOwnerWindow, const TCHAR *msg);
KNCECOMM_API void knceDestroyWaitBox(HWND hWnd);
KNCECOMM_API void knceGetCurrentDirectory(TCHAR *path, int pathSize);
KNCECOMM_API int knceCompareFileTime(int *failed, const TCHAR *fileName1,
const TCHAR *fileName2);
KNCECOMM_API int knceRegisterHotKey(HWND hWnd, unsigned int mods,
unsigned int keyCode);
KNCECOMM_API int knceUnregisterHotKey(HWND hWnd, int id);
KNCECOMM_API int knceRealKeyCodeToName(TCHAR *name, int nameSize, int code);
KNCECOMM_API int knceRealKeyNameToCode(const TCHAR *name);
KNCECOMM_API void knceChangeKeyRepeatSpeed(int initDelay, int repeatRate);
KNCECOMM_API void knceRestoreKeyRepeatSpeed();
KNCECOMM_API HFONT knceCreateFont(const TCHAR *faceName,
int pointSize, int isBold, int isItalic);
KNCECOMM_API void knceGetDefaultFontName(TCHAR *fontName, int fontNameLen);
KNCECOMM_API void knceSetDefaultFontName(const TCHAR *fontName);
KNCECOMM_API HFONT knceCreateDefaultFont(int isVariable,
int pointSize, int isBold, int isItalic);
KNCECOMM_API int knceObtainFontNames(KnceFontName **fontNames, int pitchType);
KNCECOMM_API int knceFontExists(const TCHAR *name);
KNCECOMM_API void knceGetFontAttributes(HFONT hFont, TCHAR *faceName,
int faceNameSize, int *pointSize, int *isBold, int *isItalic);
KNCECOMM_API void knceSetDialogFont(HWND hDlg, HFONT hFont);
KNCECOMM_API int knceMatchFileExtension(const TCHAR *fileName,
const TCHAR *pat);
KNCECOMM_API int knceMatchMultiFileExtension(const TCHAR *fileName,
const TCHAR *pats);
KNCECOMM_API void knceDebugMessageBox(HWND hOwnerWindow,
const TCHAR *msg, ...);
}
#endif /* KNCECOMM_H_ */

33
kncecomm-0.18/kncecomm.mk Normal file
View File

@ -0,0 +1,33 @@
TARGET=kncecomm-0.18.dll
CPP=clarm
CPPFLAGS=/nologo /W3 /O2 /EHsc /QRarch4T /QRinterwork-return \
/D "ARM" /D "_ARM_" /D "ARMV4I" /D UNDER_CE=400 \
/D "UNICODE" /D "_UNICODE" \
/D "KNCECOMM_EXPORTS"
LDFLAGS=/NOLOGO /DLL /SUBSYSTEM:WINDOWSCE
LIBS=
OBJS=\
kncecomm.obj \
kncedirdlg.obj \
kncefiledlg.obj \
kncefontdlg.obj \
kncecapkeydlg.obj \
knceappdlg.obj \
kncewaitbox.obj
RESOURCE=kncecomm.res
all : $(TARGET)
$(TARGET) : $(OBJS) $(RESOURCE)
link $(LDFLAGS) /OUT:$@ $(OBJS) $(RESOURCE) $(LIBS)
clean :
-del $(TARGET) $(OBJS) kncecomm-0.18.exp kncecomm-0.18.lib
kncecomm.obj : kncecomm.h
kncedirdlg.obj : kncecomm.h
kncefiledlg.obj : kncecomm.h
kncefontdlg.obj : kncecomm.h
kncecapkeydlg.obj : kncecomm.h
knceappdlg.obj : kncecomm.h
kncewaitbox : kncecomm.h

BIN
kncecomm-0.18/kncecomm.res Normal file

Binary file not shown.

View File

@ -0,0 +1,219 @@
#include "kncecomm.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL = 102,
IDC_CHOOSE_FILE_DIRECTORY_LIST = 103,
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onDirectoryList(HWND hDlg, int event);
static void updateDirectoryList(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceDirDlgData {
HFONT hFont;
KnceChooseDirectoryParams *chooseDirectoryParams;
tstring currentPath;
};
bool showChooseDirectoryDialog(HWND hOwnerWindow,
KnceChooseDirectoryParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_DIRECTORY"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FILE_DIRECTORY_LIST:
onDirectoryList(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceDirDlgData *data = new KnceDirDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->hFont = knceCreateDefaultFont(true, 100, false, false);
knceSetDialogFont(hDlg, data->hFont);
data->chooseDirectoryParams = (KnceChooseDirectoryParams *)params;
data->currentPath = data->chooseDirectoryParams->initialPath;
if (data->currentPath.empty())
data->currentPath = _T("\\");
updateDirectoryList(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
if (GetFocus() == hDirList) {
onDirectoryList(hDlg, LBN_DBLCLK);
return;
}
_tcsncpy(data->chooseDirectoryParams->directory, data->currentPath.c_str(),
MAX_PATH);
DeleteObject(data->hFont);
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
DeleteObject(data->hFont);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onDirectoryList(HWND hDlg, int event) {
const int dirDispLen = MAX_PATH + 2;
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_DBLCLK)
return;
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
int selected = SendMessage(hDirList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring dirDisp;
TCHAR dirDispCStr[dirDispLen];
if (SendMessage(hDirList, LB_GETTEXTLEN, selected, 0) < dirDispLen) {
SendMessage(hDirList, LB_GETTEXT, selected, (LPARAM)dirDispCStr);
dirDisp = dirDispCStr;
}
if (dirDisp == _T("(Up...)")) {
int pos = data->currentPath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = data->currentPath.substr(0, pos);
}
else {
tstring dirName = dirDisp.substr(1, dirDisp.length() - 2);
if (data->currentPath == _T("\\"))
data->currentPath += dirName;
else
data->currentPath += _T("\\") + dirName;
}
updateDirectoryList(hDlg);
}
static void updateDirectoryList(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
bool isRoot = data->currentPath == _T("\\");
tstring dirName;
if (isRoot)
dirName = _T("[My Device]");
else {
dirName = _T("[") + data->currentPath.substr(
data->currentPath.rfind(_T('\\')) + 1) + _T("]");
}
HWND hDirLabel = GetDlgItem(hDlg, IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL);
SetWindowText(hDirLabel, dirName.c_str());
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
SendMessage(hDirList, LB_RESETCONTENT, 0, 0);
if (!isRoot)
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)_T("(Up...)"));
tstring findPath;
if (isRoot)
findPath = _T("\\*.*");
else
findPath = data->currentPath + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)dirDisp.c_str());
}
while (FindNextFile(hFind, &fd)) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0,
(LPARAM)dirDisp.c_str());
}
}
}
FindClose(hFind);
int numDirs = SendMessage(hDirList, LB_GETCOUNT, 0, 0);
if (isRoot)
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
else {
if (numDirs > 1)
SendMessage(hDirList, LB_SETCURSEL, 1, 0);
else
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
}
}

View File

@ -0,0 +1,458 @@
#include "kncecomm.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FILE_FILE_LIST = 101,
IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL = 102,
IDC_CHOOSE_FILE_DIRECTORY_LIST = 103,
IDC_CHOOSE_FILE_FILE_NAME_BOX = 104,
IDC_CHOOSE_FILE_TYPE_COMBO = 105
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static bool onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onFileList(HWND hDlg, int event);
static void onDirectoryList(HWND hDlg, int event);
static void onTypeCombo(HWND hDlg, int event);
static void onFileNameBox(HWND hDlg, int event);
static void updateFileList(HWND hDlg);
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim);
static tstring appendFileExtension(const tstring &fileName,
const tstring &pat);
extern HINSTANCE g_hInstance;
struct KnceFileDlgData {
HFONT hFont;
KnceChooseFileParams *chooseFileParams;
vector<pair<tstring, tstring> > filters;
tstring currentPath;
bool eventProcessing;
};
bool showChooseFileDialog(HWND hOwnerWindow, KnceChooseFileParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_FILE"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return onInitDialog(hDlg, (void *)lParam);
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FILE_FILE_LIST:
onFileList(hDlg, event);
break;
case IDC_CHOOSE_FILE_DIRECTORY_LIST:
onDirectoryList(hDlg, event);
break;
case IDC_CHOOSE_FILE_FILE_NAME_BOX:
onFileNameBox(hDlg, event);
break;
case IDC_CHOOSE_FILE_TYPE_COMBO:
onTypeCombo(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static bool onInitDialog(HWND hDlg, void *params) {
int i;
KnceFileDlgData *data = new KnceFileDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->hFont = knceCreateDefaultFont(true, 100, false, false);
knceSetDialogFont(hDlg, data->hFont);
data->chooseFileParams = (KnceChooseFileParams *)params;
data->eventProcessing = false;
vector<tstring> filterParts;
split(filterParts, data->chooseFileParams->filters, _T("|"));
int numFilters = filterParts.size() / 2;
for (i = 0; i < numFilters; i++) {
data->filters.push_back(make_pair(filterParts[i * 2],
filterParts[i * 2 + 1]));
}
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
HWND hFileNameBox = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_NAME_BOX);
if (data->chooseFileParams->isSaveFile) {
SetWindowText(hDlg, _T("Save File"));
unsigned long style = GetWindowLong(hFileList, GWL_STYLE);
SetWindowLong(hFileList, GWL_STYLE, style | LBS_NOSEL);
SetWindowPos(hFileList, NULL, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED));
}
else {
ShowWindow(hFileNameBox, SW_HIDE);
RECT rect;
GetWindowRect(hFileList, &rect);
SetWindowPos(hFileList, NULL, 0, 0, rect.right - rect.left, 155,
SWP_NOMOVE | SWP_NOZORDER);
}
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
for (i = 0; i < numFilters; i++) {
SendMessage(hTypeCombo, CB_ADDSTRING, 0,
(LPARAM)data->filters[i].first.c_str());
}
if (numFilters > 0)
SendMessage(hTypeCombo, CB_SETCURSEL, 0, 0);
tstring fileName;
tstring filePath = data->chooseFileParams->fileName;
if (filePath.empty()) {
data->currentPath = data->chooseFileParams->initialPath;
if (data->currentPath.empty())
data->currentPath = _T("\\");
}
else {
int pos = filePath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = filePath.substr(0, pos);
fileName = filePath.substr(pos + 1);
}
updateFileList(hDlg);
ShowWindow(hDlg, SW_SHOW);
if (data->chooseFileParams->isSaveFile) {
if (fileName.empty())
SetWindowText(hFileNameBox, _T("untitled"));
else
SetWindowText(hFileNameBox, fileName.c_str());
SendMessage(hFileNameBox, EM_SETSEL, 0, -1);
SetFocus(hFileNameBox);
return false;
}
else
return true;
}
static void onOk(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
if (GetFocus() == hDirList) {
onDirectoryList(hDlg, LBN_DBLCLK);
return;
}
tstring fileName;
if (data->chooseFileParams->isSaveFile) {
HWND hFileNameBox = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_NAME_BOX);
TCHAR fileNameCStr[MAX_PATH];
GetWindowText(hFileNameBox, fileNameCStr, MAX_PATH);
fileName = fileNameCStr;
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
int typeIndex = SendMessage(hTypeCombo, CB_GETCURSEL, 0, 0);
tstring pat = data->filters[typeIndex].second;
vector<tstring> exts;
split(exts, pat, _T(";"));
if (!exts.empty())
fileName = appendFileExtension(fileName, exts[0]);
}
else {
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
int selected = SendMessage(hFileList, LB_GETCURSEL, 0, 0);
TCHAR fileNameCStr[MAX_PATH];
if (SendMessage(hFileList, LB_GETTEXTLEN, selected, 0) < MAX_PATH) {
SendMessage(hFileList, LB_GETTEXT, selected, (LPARAM)fileNameCStr);
fileName = fileNameCStr;
}
}
tstring filePath;
if (data->currentPath == _T("\\"))
filePath = data->currentPath + fileName;
else
filePath = data->currentPath + _T("\\") + fileName;
_tcsncpy(data->chooseFileParams->fileName, filePath.c_str(), MAX_PATH);
if (data->chooseFileParams->isSaveFile) {
FILE *file = _tfopen(filePath.c_str(), _T("r"));
if (file != NULL) {
fclose(file);
tstring msg = _T("File ") + fileName + _T(" already exists. ")
_T("Overwrite?");
if (MessageBox(hDlg, msg.c_str(), _T("Confirm"),
MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
{
return;
}
}
}
DeleteObject(data->hFont);
EndDialog(hDlg, IDOK);
}
static void onCancel(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
DeleteObject(data->hFont);
EndDialog(hDlg, IDCANCEL);
}
static void onFileList(HWND hDlg, int event) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_SELCHANGE || data->eventProcessing)
return;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
int selected = SendMessage(hFileList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring fileName;
TCHAR fileNameCStr[MAX_PATH];
if (SendMessage(hFileList, LB_GETTEXTLEN, selected, 0) < MAX_PATH) {
SendMessage(hFileList, LB_GETTEXT, selected, (LPARAM)fileNameCStr);
fileName = fileNameCStr;
}
HWND hFileNameBox = GetDlgItem(hDlg,
IDC_CHOOSE_FILE_FILE_NAME_BOX);
data->eventProcessing = true;
SetWindowText(hFileNameBox, fileName.c_str());
data->eventProcessing = false;
if (!data->chooseFileParams->isSaveFile) {
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
}
static void onDirectoryList(HWND hDlg, int event) {
const int dirDispLen = MAX_PATH + 2;
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_DBLCLK)
return;
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
int selected = SendMessage(hDirList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring dirDisp;
TCHAR dirDispCStr[dirDispLen];
if (SendMessage(hDirList, LB_GETTEXTLEN, selected, 0) < dirDispLen) {
SendMessage(hDirList, LB_GETTEXT, selected, (LPARAM)dirDispCStr);
dirDisp = dirDispCStr;
}
if (dirDisp == _T("(Up...)")) {
int pos = data->currentPath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = data->currentPath.substr(0, pos);
}
else {
tstring dirName = dirDisp.substr(1, dirDisp.length() - 2);
if (data->currentPath == _T("\\"))
data->currentPath += dirName;
else
data->currentPath += _T("\\") + dirName;
}
updateFileList(hDlg);
}
static void onFileNameBox(HWND hDlg, int event) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != EN_CHANGE || data->eventProcessing)
return;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
data->eventProcessing = true;
SendMessage(hFileList, LB_SETCURSEL, -1, 0);
data->eventProcessing = false;
}
static void onTypeCombo(HWND hDlg, int event) {
if (event == CBN_SELCHANGE)
updateFileList(hDlg);
}
static void updateFileList(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
bool isRoot = data->currentPath == _T("\\");
tstring dirName;
if (isRoot)
dirName = _T("[My Device]");
else {
dirName = _T("[") + data->currentPath.substr(
data->currentPath.rfind(_T('\\')) + 1) + _T("]");
}
HWND hDirLabel = GetDlgItem(hDlg, IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL);
SetWindowText(hDirLabel, dirName.c_str());
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
int typeIndex = SendMessage(hTypeCombo, CB_GETCURSEL, 0, 0);
tstring pat = data->filters[typeIndex].second;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
SendMessage(hFileList, LB_RESETCONTENT, 0, 0);
SendMessage(hDirList, LB_RESETCONTENT, 0, 0);
if (!isRoot)
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)_T("(Up...)"));
tstring findPath;
if (isRoot)
findPath = _T("\\*.*");
else
findPath = data->currentPath + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)dirDisp.c_str());
}
else if (knceMatchMultiFileExtension(fd.cFileName, pat.c_str()))
SendMessage(hFileList, LB_ADDSTRING, 0, (LPARAM)fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0,
(LPARAM)dirDisp.c_str());
}
else if (knceMatchMultiFileExtension(fd.cFileName, pat.c_str()))
SendMessage(hFileList, LB_ADDSTRING, 0, (LPARAM)fd.cFileName);
}
}
FindClose(hFind);
if (!data->chooseFileParams->isSaveFile) {
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
}
if (SendMessage(hFileList, LB_GETCOUNT, 0, 0) > 0) {
SendMessage(hFileList, LB_SETCURSEL, 0, 0);
onFileList(hDlg, LBN_SELCHANGE);
}
int numDirs = SendMessage(hDirList, LB_GETCOUNT, 0, 0);
if (isRoot)
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
else {
if (numDirs > 1)
SendMessage(hDirList, LB_SETCURSEL, 1, 0);
else
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
}
}
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim) {
tstring strWork = str;
int cutAt = 0;
while ((cutAt = strWork.find_first_of(delim)) != tstring::npos) {
if (cutAt > 0)
result.push_back(strWork.substr(0, cutAt));
strWork = strWork.substr(cutAt + 1);
}
if (strWork.length() > 0)
result.push_back(strWork);
}
static tstring appendFileExtension(const tstring &fileName,
const tstring &pat) {
if (knceMatchFileExtension(fileName.c_str(), pat.c_str()))
return fileName;
if (pat.length() < 2 || pat.substr(0, 2) != _T("*."))
return fileName;
return fileName + pat.substr(1);
}

View File

@ -0,0 +1,240 @@
#include "kncecomm.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FONT_NAME_LIST = 102,
IDC_CHOOSE_FONT_SIZE_LIST = 104,
IDC_CHOOSE_FONT_STYLE_LIST = 106,
IDC_CHOOSE_FONT_EXAMPLE_LABEL = 107,
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *params);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onNameList(HWND hDlg, int event);
static void onSizeList(HWND hDlg, int event);
static void onStyleList(HWND hDlg, int event);
static void updateFont(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceFontDlgData {
HFONT hFont;
KnceChooseFontParams *chooseFontParams;
HFONT hCurrentFont;
bool isInitializing;
};
bool showChooseFontDialog(HWND hOwnerWindow, KnceChooseFontParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_FONT"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FONT_NAME_LIST:
onNameList(hDlg, event);
break;
case IDC_CHOOSE_FONT_SIZE_LIST:
onSizeList(hDlg, event);
break;
case IDC_CHOOSE_FONT_STYLE_LIST:
onStyleList(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
static int fontSizes[] = {8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26,
28, 36, 48, 72};
int i;
KnceFontDlgData *data = new KnceFontDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->hFont = knceCreateDefaultFont(true, 100, false, false);
knceSetDialogFont(hDlg, data->hFont);
data->chooseFontParams = (KnceChooseFontParams *)params;
HWND hFontNameList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_NAME_LIST);
KnceFontName *fontNames = NULL;
int numFonts = knceObtainFontNames(&fontNames,
data->chooseFontParams->isFixedOnly);
for (i = 0; i < numFonts; i++) {
SendMessage(hFontNameList, LB_ADDSTRING, 0,
(LPARAM)fontNames[i].fontName);
}
free(fontNames);
HWND hFontSizeList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_SIZE_LIST);
TCHAR sizeCStr[16];
int numSizes = sizeof(fontSizes) / sizeof(int);
for (i = 0; i < numSizes; i++) {
_sntprintf(sizeCStr, 16, _T("%d"), fontSizes[i]);
SendMessage(hFontSizeList, LB_ADDSTRING, 0, (LPARAM)sizeCStr);
}
HWND hFontStyleList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_STYLE_LIST);
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Normal"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Italic"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Bold"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Bold Italic"));
data->isInitializing = true;
HFONT inputFont = data->chooseFontParams->hFont;
if (inputFont == NULL)
data->hCurrentFont = knceCreateDefaultFont(false, 120, false, false);
else {
LOGFONT logFont;
GetObject(inputFont, sizeof(LOGFONT), &logFont);
data->hCurrentFont = CreateFontIndirect(&logFont);
}
TCHAR fontNameCStr[256];
int pointSize = 0;
int isBold = 0;
int isItalic = 0;
knceGetFontAttributes(data->hCurrentFont, fontNameCStr, 256, &pointSize,
&isBold, &isItalic);
int itemIndex = SendMessage(hFontNameList, LB_FINDSTRINGEXACT, -1,
(LPARAM)fontNameCStr);
SendMessage(hFontNameList, LB_SETCURSEL, itemIndex, 0);
_sntprintf(sizeCStr, 16, _T("%d"), pointSize / 10);
itemIndex = SendMessage(hFontSizeList, LB_FINDSTRINGEXACT, -1,
(LPARAM)sizeCStr);
SendMessage(hFontSizeList, LB_SETCURSEL, itemIndex, 0);
itemIndex = (isItalic ? 0x01 : 0x00) | (isBold ? 0x02 : 0x00);
SendMessage(hFontStyleList, LB_SETCURSEL, itemIndex, 0);
HWND hExampleLabel = GetDlgItem(hDlg, IDC_CHOOSE_FONT_EXAMPLE_LABEL);
SendMessage(hExampleLabel, WM_SETFONT, (WPARAM)data->hCurrentFont, 0);
data->isInitializing = false;
updateFont(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
data->chooseFontParams->hFont = data->hCurrentFont;
DeleteObject(data->hFont);
EndDialog(hDlg, IDOK);
}
static void onCancel(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
DeleteObject(data->hCurrentFont);
DeleteObject(data->hFont);
EndDialog(hDlg, IDCANCEL);
}
static void onNameList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void onSizeList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void onStyleList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void updateFont(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (data->isInitializing)
return;
DeleteObject(data->hCurrentFont);
HWND hFontNameList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_NAME_LIST);
int fontNameIndex = SendMessage(hFontNameList, LB_GETCURSEL, 0, 0);
TCHAR *fontNameBuf = new TCHAR[SendMessage(hFontNameList, LB_GETTEXTLEN,
fontNameIndex, 0) + 1];
SendMessage(hFontNameList, LB_GETTEXT, fontNameIndex, (LPARAM)fontNameBuf);
HWND hFontSizeList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_SIZE_LIST);
int fontSizeIndex = SendMessage(hFontSizeList, LB_GETCURSEL, 0, 0);
TCHAR *sizeBuf = new TCHAR[SendMessage(hFontSizeList, LB_GETTEXTLEN,
fontSizeIndex, 0) + 1];
SendMessage(hFontSizeList, LB_GETTEXT, fontSizeIndex, (LPARAM)sizeBuf);
int pointSize = _ttoi(sizeBuf) * 10;
HWND hFontStyleList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_STYLE_LIST);
int fontStyleIndex = SendMessage(hFontStyleList, LB_GETCURSEL, 0, 0);
bool isBold = (fontStyleIndex & 0x02) != 0;
bool isItalic = (fontStyleIndex & 0x01) != 0;
data->hCurrentFont = knceCreateFont(fontNameBuf, pointSize, isBold,
isItalic);
delete [] fontNameBuf;
delete [] sizeBuf;
HWND hExampleLabel = GetDlgItem(hDlg, IDC_CHOOSE_FONT_EXAMPLE_LABEL);
SendMessage(hExampleLabel, WM_SETFONT, (WPARAM)data->hCurrentFont, 0);
}

View File

@ -0,0 +1,147 @@
#include "kncecomm.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
MESSAGE_MARGIN = 25
};
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
static void onCreate(HWND hWnd, CREATESTRUCT *createStruct);
static void onDestroy(HWND hWnd);
static void onPaint(HWND hWnd, HDC hDC);
static void changeWindowLayout(HWND hWnd);
extern HINSTANCE g_hInstance;
struct WaitBoxData {
tstring message;
};
void registerWaitBoxClass() {
WNDCLASS windowClass;
memset(&windowClass, 0, sizeof(WNDCLASS));
windowClass.lpfnWndProc = wndProc;
windowClass.hInstance = g_hInstance;
windowClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
windowClass.lpszClassName = _T("KNCommonLibWaitBox");
RegisterClass(&windowClass);
}
void unregisterWaitBoxClass() {
UnregisterClass(_T("KNCommonLibWaitBox"), g_hInstance);
}
HWND createWaitBox(HWND hOwnerWindow, const tstring &msg) {
HWND hWnd = CreateWindowEx(
0,
_T("KNCommonLibWaitBox"), _T(""),
WS_POPUP | WS_BORDER,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hOwnerWindow, NULL, g_hInstance, (void *)&msg);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return hWnd;
}
void destroyWaitBox(HWND hWnd) {
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam) {
switch (msg) {
case WM_CREATE:
onCreate(hWnd, (CREATESTRUCT *)lParam);
return 0;
case WM_DESTROY:
onDestroy(hWnd);
return 0;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
//switch (id) {
//}
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT paintStruct;
HDC hDC = BeginPaint(hWnd, &paintStruct);
onPaint(hWnd, hDC);
EndPaint(hWnd, &paintStruct);
return 0;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
static void onCreate(HWND hWnd, CREATESTRUCT *createStruct) {
WaitBoxData *data = new WaitBoxData();
SetWindowLong(hWnd, GWL_USERDATA, (long)data);
data->message = *(const tstring *)createStruct->lpCreateParams;
if (data->message.empty())
data->message = _T("Please wait...");
changeWindowLayout(hWnd);
}
static void onDestroy(HWND hWnd) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
delete data;
}
static void onPaint(HWND hWnd, HDC hDC) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
int prevBkMode = SetBkMode(hDC, TRANSPARENT);
ExtTextOut(hDC, MESSAGE_MARGIN, MESSAGE_MARGIN, 0, NULL,
data->message.c_str(), data->message.size(), NULL);
SetBkMode(hDC, prevBkMode);
}
static void changeWindowLayout(HWND hWnd) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
HDC hDC = GetDC(hWnd);
SIZE textSize;
GetTextExtentExPointW(hDC, data->message.c_str(), data->message.size(), 0,
NULL, NULL, &textSize);
ReleaseDC(hWnd, hDC);
int windowWidth = textSize.cx + MESSAGE_MARGIN * 2 + 2;
int windowHeight = textSize.cy + MESSAGE_MARGIN * 2 + 2;
RECT desktopRect;
HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktopRect);
MoveWindow(hWnd, (desktopRect.right - windowWidth) / 2,
(desktopRect.bottom - windowHeight) / 2, windowWidth, windowHeight,
false);
}

674
kncedlg-0.10/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

285
kncedlg-0.10/knceappdlg.cpp Normal file
View File

@ -0,0 +1,285 @@
#include "kncedlg.h"
#include <string>
#include <algorithm>
#include <windows.h>
#include <knceutil.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_APPLICATION_LIST = 101,
IDC_PATH_EDIT = 102,
IDC_PATH_BROWSE = 103
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onApplicationList(HWND hDlg, int event);
static void onPathEdit(HWND hDlg, int event);
static void onPathBrowse(HWND hDlg, int event);
static void updateApplicationList(HWND hDlg);
static void addToBucket(vector<pair<tstring, tstring> > &captToPath,
const tstring &dir);
extern HINSTANCE g_hInstance;
struct KnceAppDlgData {
KnceChooseApplicationParams *chooseApplicationParams;
vector<tstring> applicationPaths;
bool eventProcessing;
};
bool showChooseApplicationDialog(HWND hOwnerWindow,
KnceChooseApplicationParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_APPLICATION"),
hOwnerWindow, (DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_APPLICATION_LIST:
onApplicationList(hDlg, event);
break;
case IDC_PATH_EDIT:
onPathEdit(hDlg, event);
break;
case IDC_PATH_BROWSE:
onPathBrowse(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceAppDlgData *data = new KnceAppDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->chooseApplicationParams = (KnceChooseApplicationParams *)params;
data->eventProcessing = false;
KnceUtil::adjustDialogLayout(hDlg);
updateApplicationList(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
GetWindowText(hPathEdit, data->chooseApplicationParams->fileName,
MAX_PATH);
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
int index = SendMessage(hAppList, LB_GETCURSEL, 0, 0);
if (index == -1) {
tstring title = data->chooseApplicationParams->fileName;
int sepPos = title.rfind(_T('\\'));
if (sepPos != tstring::npos)
title = title.substr(sepPos + 1);
int extPos = title.rfind(_T('.'));
if (extPos != tstring::npos)
title = title.substr(0, extPos);
_tcsncpy(data->chooseApplicationParams->title, title.c_str(), 256);
}
else {
TCHAR *appNameBuf = new TCHAR[
SendMessage(hAppList, LB_GETTEXTLEN, index, 0) + 1];
SendMessage(hAppList, LB_GETTEXT, index, (LPARAM)appNameBuf);
_tcsncpy(data->chooseApplicationParams->title, appNameBuf, 256);
delete [] appNameBuf;
}
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onApplicationList(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_SELCHANGE || data->eventProcessing)
return;
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
int index = SendMessage(hAppList, LB_GETCURSEL, 0, 0);
if (index == -1)
return;
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
data->eventProcessing = true;
SetWindowText(hPathEdit, data->applicationPaths[index].c_str());
data->eventProcessing = false;
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
static void onPathEdit(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != EN_CHANGE || data->eventProcessing)
return;
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
data->eventProcessing = true;
SendMessage(hAppList, LB_SETCURSEL, -1, 0);
data->eventProcessing = false;
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
static void onPathBrowse(HWND hDlg, int event) {
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
KnceChooseFileParams params = {0};
params.isSaveFile = false;
params.filters = _T("Programs (*.exe)|*.exe|All files (*.*)|*.*");
if (knceChooseFile(hDlg, &params)) {
HWND hPathEdit = GetDlgItem(hDlg, IDC_PATH_EDIT);
SetWindowText(hPathEdit, params.fileName);
}
}
static void updateApplicationList(HWND hDlg) {
int i;
KnceAppDlgData *data = (KnceAppDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
vector<pair<tstring, tstring> > captToPath;
tstring dir = _T("\\NAND3\\ƒAƒvƒŠ");
tstring findPath = dir + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
}
}
FindClose(hFind);
dir = _T("\\Storage Card\\ƒAƒvƒŠ");
findPath = dir + _T("\\*.*");
hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
addToBucket(captToPath, dir + _T("\\") + fd.cFileName);
}
}
FindClose(hFind);
HWND hAppList = GetDlgItem(hDlg, IDC_APPLICATION_LIST);
SendMessage(hAppList, LB_RESETCONTENT, 0, 0);
data->applicationPaths.clear();
int numApps = captToPath.size();
for (i = 0; i < numApps; i++) {
SendMessage(hAppList, LB_ADDSTRING, 0,
(LPARAM)captToPath[i].first.c_str());
data->applicationPaths.push_back(captToPath[i].second);
}
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
}
static void addToBucket(vector<pair<tstring, tstring> > &captToPath,
const tstring &dir) {
tstring indexFileName = dir + _T("\\index.din");
tstring appFileName = dir + _T("\\AppMain.exe");
if (GetFileAttributes(indexFileName.c_str()) == -1 ||
GetFileAttributes(appFileName.c_str()) == -1) {
return;
}
tstring capt = dir.substr(dir.rfind('\\') + 1);
tstring captLower = capt;
transform(captLower.begin(), captLower.end(), captLower.begin(),
_totlower);
vector<pair<tstring, tstring> >::iterator iter = captToPath.begin();
for ( ; iter != captToPath.end(); iter++) {
tstring captTemp = iter->first;
transform(captTemp.begin(), captTemp.end(), captTemp.begin(),
_totlower);
if (captTemp.compare(captLower) > 0)
break;
}
captToPath.insert(iter, make_pair(capt, appFileName));
}

View File

@ -0,0 +1,145 @@
#include "kncedlg.h"
#include <string>
#include <windows.h>
#include <knceutil.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_KEY_LABEL = 103
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam,
LPARAM lParam);
static void onInitDialog(HWND hDlg, void *params);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onTimer(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceCapKeyDlgData {
int *capturedKeyCode;
};
bool showCaptureKeyDialog(HWND hOwnerWindow, int *capturedKeyCode) {
int ret = DialogBoxParam(g_hInstance, _T("CAPTURE_KEY"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)capturedKeyCode);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
default:
return false;
}
return true;
}
case WM_TIMER:
onTimer(hDlg);
return true;
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceCapKeyDlgData *data = new KnceCapKeyDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->capturedKeyCode = (int *)params;
*data->capturedKeyCode = -1;
KnceUtil::adjustDialogLayout(hDlg);
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
SetTimer(hDlg, 1, 100, NULL);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
KillTimer(hDlg, 1);
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
KillTimer(hDlg, 1);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onTimer(HWND hDlg) {
int i;
KnceCapKeyDlgData *data = (KnceCapKeyDlgData *)GetWindowLong(hDlg,
GWL_USERDATA);
int keyCode = -1;
for (i = 0; i < 256; i++) {
if (GetAsyncKeyState(i) != 0) {
keyCode = i;
break;
}
}
if (keyCode == -1 || keyCode == 1 ||
keyCode == HARD_KEY_EXECUTE ||
keyCode == HARD_KEY_BACK ||
keyCode == HARD_KEY_LEFT || keyCode == HARD_KEY_UP ||
keyCode == HARD_KEY_RIGHT || keyCode == HARD_KEY_DOWN)
{
return;
}
*data->capturedKeyCode = keyCode;
tstring keyName;
KnceUtil::hardKeyCodeToName(keyName, keyCode);
HWND hKeyLabel = GetDlgItem(hDlg, IDC_KEY_LABEL);
SetWindowText(hKeyLabel, keyName.c_str());
HWND hOkButton = GetDlgItem(hDlg, IDOK);
if (!IsWindowEnabled(hOkButton)) {
EnableWindow(hOkButton, true);
SetFocus(hOkButton);
}
}

214
kncedlg-0.10/kncedirdlg.cpp Normal file
View File

@ -0,0 +1,214 @@
#include "kncedlg.h"
#include <string>
#include <windows.h>
#include <knceutil.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL = 102,
IDC_CHOOSE_FILE_DIRECTORY_LIST = 103,
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onDirectoryList(HWND hDlg, int event);
static void updateDirectoryList(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceDirDlgData {
KnceChooseDirectoryParams *chooseDirectoryParams;
tstring currentPath;
};
bool showChooseDirectoryDialog(HWND hOwnerWindow,
KnceChooseDirectoryParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_DIRECTORY"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FILE_DIRECTORY_LIST:
onDirectoryList(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
KnceDirDlgData *data = new KnceDirDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->chooseDirectoryParams = (KnceChooseDirectoryParams *)params;
data->currentPath = data->chooseDirectoryParams->initialPath;
if (data->currentPath.empty())
data->currentPath = _T("\\");
KnceUtil::adjustDialogLayout(hDlg);
updateDirectoryList(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
if (GetFocus() == hDirList) {
onDirectoryList(hDlg, LBN_DBLCLK);
return;
}
_tcsncpy(data->chooseDirectoryParams->directory, data->currentPath.c_str(),
MAX_PATH);
EndDialog(hDlg, IDOK);
delete data;
}
static void onCancel(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
EndDialog(hDlg, IDCANCEL);
delete data;
}
static void onDirectoryList(HWND hDlg, int event) {
const int dirDispLen = MAX_PATH + 2;
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_DBLCLK)
return;
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
int selected = SendMessage(hDirList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring dirDisp;
TCHAR dirDispCStr[dirDispLen];
if (SendMessage(hDirList, LB_GETTEXTLEN, selected, 0) < dirDispLen) {
SendMessage(hDirList, LB_GETTEXT, selected, (LPARAM)dirDispCStr);
dirDisp = dirDispCStr;
}
if (dirDisp == _T("(Up...)")) {
int pos = data->currentPath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = data->currentPath.substr(0, pos);
}
else {
tstring dirName = dirDisp.substr(1, dirDisp.length() - 2);
if (data->currentPath == _T("\\"))
data->currentPath += dirName;
else
data->currentPath += _T("\\") + dirName;
}
updateDirectoryList(hDlg);
}
static void updateDirectoryList(HWND hDlg) {
KnceDirDlgData *data = (KnceDirDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
bool isRoot = data->currentPath == _T("\\");
tstring dirName;
if (isRoot)
dirName = _T("[My Device]");
else {
dirName = _T("[") + data->currentPath.substr(
data->currentPath.rfind(_T('\\')) + 1) + _T("]");
}
HWND hDirLabel = GetDlgItem(hDlg, IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL);
SetWindowText(hDirLabel, dirName.c_str());
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
SendMessage(hDirList, LB_RESETCONTENT, 0, 0);
if (!isRoot)
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)_T("(Up...)"));
tstring findPath;
if (isRoot)
findPath = _T("\\*.*");
else
findPath = data->currentPath + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)dirDisp.c_str());
}
while (FindNextFile(hFind, &fd)) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0,
(LPARAM)dirDisp.c_str());
}
}
}
FindClose(hFind);
int numDirs = SendMessage(hDirList, LB_GETCOUNT, 0, 0);
if (isRoot)
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
else {
if (numDirs > 1)
SendMessage(hDirList, LB_SETCURSEL, 1, 0);
else
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
}
}

Binary file not shown.

Binary file not shown.

130
kncedlg-0.10/kncedlg.cpp Normal file
View File

@ -0,0 +1,130 @@
#include "kncedlg.h"
#include <algorithm>
#include <map>
using namespace std;
enum {
NWUS_KEYBD_REPEAT_CHANGED = 2
};
extern "C" void WINAPI NotifyWinUserSystem(UINT uEvent);
bool showChooseDirectoryDialog(HWND hOwnerWindow,
KnceChooseDirectoryParams *params);
bool showChooseFileDialog(HWND hOwnerWindow, KnceChooseFileParams *params);
bool showChooseFontDialog(HWND hOwnerWindow, KnceChooseFontParams *params);
bool showCaptureKeyDialog(HWND hOwnerWindow, int *capturedKeyCode);
bool showChooseApplicationDialog(HWND hOwnerWindow,
KnceChooseApplicationParams *params);
void registerWaitBoxClass();
void unregisterWaitBoxClass();
HWND createWaitBox(HWND hOwnerWindow, const tstring &msg);
void destroyWaitBox(HWND hWnd);
HINSTANCE g_hInstance = NULL;
BOOL APIENTRY DllMain(HANDLE hInst, DWORD fdwReason, LPVOID pvReserved) {
if (fdwReason == DLL_PROCESS_ATTACH) {
g_hInstance = (HINSTANCE)hInst;
registerWaitBoxClass();
}
else if (fdwReason == DLL_PROCESS_DETACH)
unregisterWaitBoxClass();
return true;
}
KNCEDLG_API int knceChooseDirectory(HWND hOwnerWindow,
KnceChooseDirectoryParams *params) {
return showChooseDirectoryDialog(hOwnerWindow, params);
}
KNCEDLG_API int knceChooseFile(HWND hOwnerWindow,
KnceChooseFileParams *params) {
return showChooseFileDialog(hOwnerWindow, params);
}
KNCEDLG_API int knceChooseFont(HWND hOwnerWindow,
KnceChooseFontParams *params) {
return showChooseFontDialog(hOwnerWindow, params);
}
KNCEDLG_API int knceCaptureKey(HWND hOwnerWindow,
int *capturedKeyCode) {
return showCaptureKeyDialog(hOwnerWindow, capturedKeyCode);
}
KNCEDLG_API int knceChooseApplication(HWND hOwnerWindow,
KnceChooseApplicationParams *params) {
return showChooseApplicationDialog(hOwnerWindow, params);
}
KNCEDLG_API HWND knceCreateWaitBox(HWND hOwnerWindow,
const TCHAR *msg) {
if (msg == NULL)
return createWaitBox(hOwnerWindow, _T(""));
else
return createWaitBox(hOwnerWindow, msg);
}
KNCEDLG_API void knceDestroyWaitBox(HWND hWnd) {
destroyWaitBox(hWnd);
}
static int CALLBACK enumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@'))
names->push_back(lplf->lfFaceName);
return 1;
}
static int CALLBACK enumFixedFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == FIXED_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK enumVariableFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == VARIABLE_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK checkFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
const tstring *name = (tstring *)lpData;
if (tstring(lplf->lfFaceName) == *name)
return 0;
return 1;
}

58
kncedlg-0.10/kncedlg.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef KNCEDLG_H_
#define KNCEDLG_H_
#include <vector>
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
#ifdef KNCEDLG_EXPORTS
#define KNCEDLG_API __declspec(dllexport)
#else
#define KNCEDLG_API __declspec(dllimport)
#endif
struct KnceChooseDirectoryParams {
TCHAR initialPath[MAX_PATH];
TCHAR directory[MAX_PATH];
};
struct KnceChooseFileParams {
bool isSaveFile;
const TCHAR *filters;
TCHAR initialPath[MAX_PATH];
TCHAR fileName[MAX_PATH];
};
struct KnceChooseFontParams {
HFONT hFont;
int isFixedOnly;
};
struct KnceChooseApplicationParams {
TCHAR title[256];
TCHAR fileName[MAX_PATH];
};
extern "C" {
KNCEDLG_API int knceChooseDirectory(HWND hOwnerWindow,
KnceChooseDirectoryParams *params);
KNCEDLG_API int knceChooseFile(HWND hOwnerWindow,
KnceChooseFileParams *params);
KNCEDLG_API int knceChooseFont(HWND hOwnerWindow,
KnceChooseFontParams *params);
KNCEDLG_API int knceCaptureKey(HWND hOwnerWindow, int *capturedKeyCode);
KNCEDLG_API int knceChooseApplication(HWND hOwnerWindow,
KnceChooseApplicationParams *params);
KNCEDLG_API HWND knceCreateWaitBox(HWND hOwnerWindow, const TCHAR *msg);
KNCEDLG_API void knceDestroyWaitBox(HWND hWnd);
}
#endif /* KNCEDLG_H_ */

34
kncedlg-0.10/kncedlg.mk Normal file
View File

@ -0,0 +1,34 @@
TARGET=kncedlg-0.10.dll
CPP=clarm
CPPFLAGS=/nologo /W3 /O2 /EHsc /QRarch4T /QRinterwork-return \
/D "ARM" /D "_ARM_" /D "ARMV4I" /D UNDER_CE=400 \
/D "UNICODE" /D "_UNICODE" \
/D "KNCEDLG_EXPORTS" \
/I../knceutil-0.11
LDFLAGS=/NOLOGO /DLL /SUBSYSTEM:WINDOWSCE
LIBS=../knceutil-0.11/knceutil-0.11.lib
OBJS=\
kncedlg.obj \
kncedirdlg.obj \
kncefiledlg.obj \
kncefontdlg.obj \
kncecapkeydlg.obj \
knceappdlg.obj \
kncewaitbox.obj
RESOURCE=kncedlg.res
all : $(TARGET)
$(TARGET) : $(OBJS) $(RESOURCE)
link $(LDFLAGS) /OUT:$@ $(OBJS) $(RESOURCE) $(LIBS)
clean :
-del $(TARGET) $(OBJS) kncedlg-0.10.exp kncedlg-0.10.lib
kncedlg.obj : kncedlg.h
kncedirdlg.obj : kncedlg.h
kncefiledlg.obj : kncedlg.h
kncefontdlg.obj : kncedlg.h
kncecapkeydlg.obj : kncedlg.h
knceappdlg.obj : kncedlg.h
kncewaitbox : kncedlg.h

BIN
kncedlg-0.10/kncedlg.res Normal file

Binary file not shown.

View File

@ -0,0 +1,459 @@
#include "kncedlg.h"
#include <string>
#include <windows.h>
#include <knceutil.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FILE_FILE_LIST = 101,
IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL = 102,
IDC_CHOOSE_FILE_DIRECTORY_LIST = 103,
IDC_CHOOSE_FILE_FILE_NAME_BOX = 104,
IDC_CHOOSE_FILE_TYPE_COMBO = 105
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static bool onInitDialog(HWND hDlg, void *createStruct);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onFileList(HWND hDlg, int event);
static void onDirectoryList(HWND hDlg, int event);
static void onTypeCombo(HWND hDlg, int event);
static void onFileNameBox(HWND hDlg, int event);
static void updateFileList(HWND hDlg);
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim);
static tstring appendFileExtension(const tstring &fileName,
const tstring &pat);
extern HINSTANCE g_hInstance;
struct KnceFileDlgData {
KnceChooseFileParams *chooseFileParams;
vector<pair<tstring, tstring> > filters;
tstring currentPath;
bool eventProcessing;
};
bool showChooseFileDialog(HWND hOwnerWindow, KnceChooseFileParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_FILE"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return onInitDialog(hDlg, (void *)lParam);
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FILE_FILE_LIST:
onFileList(hDlg, event);
break;
case IDC_CHOOSE_FILE_DIRECTORY_LIST:
onDirectoryList(hDlg, event);
break;
case IDC_CHOOSE_FILE_FILE_NAME_BOX:
onFileNameBox(hDlg, event);
break;
case IDC_CHOOSE_FILE_TYPE_COMBO:
onTypeCombo(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static bool onInitDialog(HWND hDlg, void *params) {
int i;
KnceFileDlgData *data = new KnceFileDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->chooseFileParams = (KnceChooseFileParams *)params;
data->eventProcessing = false;
KnceUtil::adjustDialogLayout(hDlg);
vector<tstring> filterParts;
split(filterParts, data->chooseFileParams->filters, _T("|"));
int numFilters = filterParts.size() / 2;
for (i = 0; i < numFilters; i++) {
data->filters.push_back(make_pair(filterParts[i * 2],
filterParts[i * 2 + 1]));
}
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
HWND hFileNameBox = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_NAME_BOX);
if (data->chooseFileParams->isSaveFile) {
SetWindowText(hDlg, _T("Save File"));
unsigned long style = GetWindowLong(hFileList, GWL_STYLE);
SetWindowLong(hFileList, GWL_STYLE, style | LBS_NOSEL);
SetWindowPos(hFileList, NULL, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED));
}
else {
ShowWindow(hFileNameBox, SW_HIDE);
RECT nameRect;
GetWindowRect(hFileNameBox, &nameRect);
RECT listRect;
GetWindowRect(hFileList, &listRect);
SetWindowPos(hFileList, NULL, 0, 0, listRect.right - listRect.left,
nameRect.bottom - listRect.top, SWP_NOMOVE | SWP_NOZORDER);
}
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
for (i = 0; i < numFilters; i++) {
SendMessage(hTypeCombo, CB_ADDSTRING, 0,
(LPARAM)data->filters[i].first.c_str());
}
if (numFilters > 0)
SendMessage(hTypeCombo, CB_SETCURSEL, 0, 0);
tstring fileName;
tstring filePath = data->chooseFileParams->fileName;
if (filePath.empty()) {
data->currentPath = data->chooseFileParams->initialPath;
if (data->currentPath.empty())
data->currentPath = _T("\\");
}
else {
int pos = filePath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = filePath.substr(0, pos);
fileName = filePath.substr(pos + 1);
}
updateFileList(hDlg);
ShowWindow(hDlg, SW_SHOW);
if (data->chooseFileParams->isSaveFile) {
if (fileName.empty())
SetWindowText(hFileNameBox, _T("untitled"));
else
SetWindowText(hFileNameBox, fileName.c_str());
SendMessage(hFileNameBox, EM_SETSEL, 0, -1);
SetFocus(hFileNameBox);
return false;
}
else
return true;
}
static void onOk(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
if (GetFocus() == hDirList) {
onDirectoryList(hDlg, LBN_DBLCLK);
return;
}
tstring fileName;
if (data->chooseFileParams->isSaveFile) {
HWND hFileNameBox = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_NAME_BOX);
TCHAR fileNameCStr[MAX_PATH];
GetWindowText(hFileNameBox, fileNameCStr, MAX_PATH);
fileName = fileNameCStr;
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
int typeIndex = SendMessage(hTypeCombo, CB_GETCURSEL, 0, 0);
tstring pat = data->filters[typeIndex].second;
vector<tstring> exts;
split(exts, pat, _T(";"));
if (!exts.empty())
fileName = appendFileExtension(fileName, exts[0]);
}
else {
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
int selected = SendMessage(hFileList, LB_GETCURSEL, 0, 0);
TCHAR fileNameCStr[MAX_PATH];
if (SendMessage(hFileList, LB_GETTEXTLEN, selected, 0) < MAX_PATH) {
SendMessage(hFileList, LB_GETTEXT, selected, (LPARAM)fileNameCStr);
fileName = fileNameCStr;
}
}
tstring filePath;
if (data->currentPath == _T("\\"))
filePath = data->currentPath + fileName;
else
filePath = data->currentPath + _T("\\") + fileName;
_tcsncpy(data->chooseFileParams->fileName, filePath.c_str(), MAX_PATH);
if (data->chooseFileParams->isSaveFile) {
FILE *file = _tfopen(filePath.c_str(), _T("r"));
if (file != NULL) {
fclose(file);
tstring msg = _T("File ") + fileName + _T(" already exists. ")
_T("Overwrite?");
if (MessageBox(hDlg, msg.c_str(), _T("Confirm"),
MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
{
return;
}
}
}
EndDialog(hDlg, IDOK);
}
static void onCancel(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
EndDialog(hDlg, IDCANCEL);
}
static void onFileList(HWND hDlg, int event) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_SELCHANGE || data->eventProcessing)
return;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
int selected = SendMessage(hFileList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring fileName;
TCHAR fileNameCStr[MAX_PATH];
if (SendMessage(hFileList, LB_GETTEXTLEN, selected, 0) < MAX_PATH) {
SendMessage(hFileList, LB_GETTEXT, selected, (LPARAM)fileNameCStr);
fileName = fileNameCStr;
}
HWND hFileNameBox = GetDlgItem(hDlg,
IDC_CHOOSE_FILE_FILE_NAME_BOX);
data->eventProcessing = true;
SetWindowText(hFileNameBox, fileName.c_str());
data->eventProcessing = false;
if (!data->chooseFileParams->isSaveFile) {
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, true);
}
}
static void onDirectoryList(HWND hDlg, int event) {
const int dirDispLen = MAX_PATH + 2;
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != LBN_DBLCLK)
return;
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
int selected = SendMessage(hDirList, LB_GETCURSEL, 0, 0);
if (selected == -1)
return;
tstring dirDisp;
TCHAR dirDispCStr[dirDispLen];
if (SendMessage(hDirList, LB_GETTEXTLEN, selected, 0) < dirDispLen) {
SendMessage(hDirList, LB_GETTEXT, selected, (LPARAM)dirDispCStr);
dirDisp = dirDispCStr;
}
if (dirDisp == _T("(Up...)")) {
int pos = data->currentPath.rfind(_T('\\'));
if (pos == 0)
data->currentPath = _T("\\");
else
data->currentPath = data->currentPath.substr(0, pos);
}
else {
tstring dirName = dirDisp.substr(1, dirDisp.length() - 2);
if (data->currentPath == _T("\\"))
data->currentPath += dirName;
else
data->currentPath += _T("\\") + dirName;
}
updateFileList(hDlg);
}
static void onFileNameBox(HWND hDlg, int event) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (event != EN_CHANGE || data->eventProcessing)
return;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
data->eventProcessing = true;
SendMessage(hFileList, LB_SETCURSEL, -1, 0);
data->eventProcessing = false;
}
static void onTypeCombo(HWND hDlg, int event) {
if (event == CBN_SELCHANGE)
updateFileList(hDlg);
}
static void updateFileList(HWND hDlg) {
KnceFileDlgData *data =
(KnceFileDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
bool isRoot = data->currentPath == _T("\\");
tstring dirName;
if (isRoot)
dirName = _T("[My Device]");
else {
dirName = _T("[") + data->currentPath.substr(
data->currentPath.rfind(_T('\\')) + 1) + _T("]");
}
HWND hDirLabel = GetDlgItem(hDlg, IDC_CHOOSE_FILE_CURRENT_DIRECTORY_LABEL);
SetWindowText(hDirLabel, dirName.c_str());
HWND hTypeCombo = GetDlgItem(hDlg, IDC_CHOOSE_FILE_TYPE_COMBO);
int typeIndex = SendMessage(hTypeCombo, CB_GETCURSEL, 0, 0);
tstring pat = data->filters[typeIndex].second;
HWND hFileList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_FILE_LIST);
HWND hDirList = GetDlgItem(hDlg, IDC_CHOOSE_FILE_DIRECTORY_LIST);
SendMessage(hFileList, LB_RESETCONTENT, 0, 0);
SendMessage(hDirList, LB_RESETCONTENT, 0, 0);
if (!isRoot)
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)_T("(Up...)"));
tstring findPath;
if (isRoot)
findPath = _T("\\*.*");
else
findPath = data->currentPath + _T("\\*.*");
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(findPath.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0, (LPARAM)dirDisp.c_str());
}
else if (KnceUtil::matchMultiFileExtension(fd.cFileName, pat.c_str()))
SendMessage(hFileList, LB_ADDSTRING, 0, (LPARAM)fd.cFileName);
while (FindNextFile(hFind, &fd)) {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
tstring dirDisp = _T("[") + tstring(fd.cFileName) + _T("]");
SendMessage(hDirList, LB_ADDSTRING, 0,
(LPARAM)dirDisp.c_str());
}
else if (KnceUtil::matchMultiFileExtension(fd.cFileName,
pat.c_str())) {
SendMessage(hFileList, LB_ADDSTRING, 0, (LPARAM)fd.cFileName);
}
}
}
FindClose(hFind);
if (!data->chooseFileParams->isSaveFile) {
HWND hOkButton = GetDlgItem(hDlg, IDOK);
EnableWindow(hOkButton, false);
}
if (SendMessage(hFileList, LB_GETCOUNT, 0, 0) > 0) {
SendMessage(hFileList, LB_SETCURSEL, 0, 0);
onFileList(hDlg, LBN_SELCHANGE);
}
int numDirs = SendMessage(hDirList, LB_GETCOUNT, 0, 0);
if (isRoot)
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
else {
if (numDirs > 1)
SendMessage(hDirList, LB_SETCURSEL, 1, 0);
else
SendMessage(hDirList, LB_SETCURSEL, 0, 0);
}
}
static void split(vector<tstring> &result, const tstring &str,
const tstring &delim) {
tstring strWork = str;
int cutAt = 0;
while ((cutAt = strWork.find_first_of(delim)) != tstring::npos) {
if (cutAt > 0)
result.push_back(strWork.substr(0, cutAt));
strWork = strWork.substr(cutAt + 1);
}
if (strWork.length() > 0)
result.push_back(strWork);
}
static tstring appendFileExtension(const tstring &fileName,
const tstring &pat) {
if (KnceUtil::matchFileExtension(fileName.c_str(), pat.c_str()))
return fileName;
if (pat.length() < 2 || pat.substr(0, 2) != _T("*."))
return fileName;
return fileName + pat.substr(1);
}

View File

@ -0,0 +1,240 @@
#include "kncedlg.h"
#include <string>
#include <windows.h>
#include <knceutil.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
IDC_CHOOSE_FONT_NAME_LIST = 102,
IDC_CHOOSE_FONT_SIZE_LIST = 104,
IDC_CHOOSE_FONT_STYLE_LIST = 106,
IDC_CHOOSE_FONT_EXAMPLE_LABEL = 107,
};
static BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static void onInitDialog(HWND hDlg, void *params);
static void onOk(HWND hDlg);
static void onCancel(HWND hDlg);
static void onNameList(HWND hDlg, int event);
static void onSizeList(HWND hDlg, int event);
static void onStyleList(HWND hDlg, int event);
static void updateFont(HWND hDlg);
extern HINSTANCE g_hInstance;
struct KnceFontDlgData {
KnceChooseFontParams *chooseFontParams;
HFONT hCurrentFont;
bool isInitializing;
};
bool showChooseFontDialog(HWND hOwnerWindow, KnceChooseFontParams *params) {
int ret = DialogBoxParam(g_hInstance, _T("CHOOSE_FONT"), hOwnerWindow,
(DLGPROC)dlgProc, (LPARAM)params);
return ret == IDOK;
}
BOOL WINAPI dlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
onInitDialog(hDlg, (void *)lParam);
return true;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
switch (id) {
case IDOK:
onOk(hDlg);
break;
case IDCANCEL:
onCancel(hDlg);
break;
case IDC_CHOOSE_FONT_NAME_LIST:
onNameList(hDlg, event);
break;
case IDC_CHOOSE_FONT_SIZE_LIST:
onSizeList(hDlg, event);
break;
case IDC_CHOOSE_FONT_STYLE_LIST:
onStyleList(hDlg, event);
break;
default:
return false;
}
return true;
}
}
return false;
}
static void onInitDialog(HWND hDlg, void *params) {
static int fontSizes[] = {8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26,
28, 36, 48, 72};
int i;
KnceFontDlgData *data = new KnceFontDlgData();
SetWindowLong(hDlg, GWL_USERDATA, (long)data);
data->chooseFontParams = (KnceChooseFontParams *)params;
KnceUtil::adjustDialogLayout(hDlg);
HWND hFontNameList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_NAME_LIST);
vector<tstring> fontNames;
int numFonts = KnceUtil::obtainFontNames(fontNames,
data->chooseFontParams->isFixedOnly);
for (i = 0; i < numFonts; i++) {
SendMessage(hFontNameList, LB_ADDSTRING, 0,
(LPARAM)fontNames[i].c_str());
}
HWND hFontSizeList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_SIZE_LIST);
TCHAR sizeCStr[16];
int numSizes = sizeof(fontSizes) / sizeof(int);
for (i = 0; i < numSizes; i++) {
_sntprintf(sizeCStr, 16, _T("%d"), fontSizes[i]);
SendMessage(hFontSizeList, LB_ADDSTRING, 0, (LPARAM)sizeCStr);
}
HWND hFontStyleList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_STYLE_LIST);
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Normal"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Italic"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Bold"));
SendMessage(hFontStyleList, LB_ADDSTRING, 0, (LPARAM)_T("Bold Italic"));
data->hCurrentFont = NULL;
data->isInitializing = true;
HFONT inputFont = data->chooseFontParams->hFont;
if (inputFont == NULL) {
SendMessage(hFontNameList, LB_SETCURSEL, 0, 0);
SendMessage(hFontSizeList, LB_SETCURSEL, 0, 0);
SendMessage(hFontStyleList, LB_SETCURSEL, 0, 0);
}
else {
LOGFONT logFont;
GetObject(inputFont, sizeof(LOGFONT), &logFont);
data->hCurrentFont = CreateFontIndirect(&logFont);
tstring fontName;
int pointSize = 0;
bool isBold = false;
bool isItalic = false;
KnceUtil::getFontAttributes(data->hCurrentFont, fontName, pointSize,
isBold, isItalic);
int itemIndex = SendMessage(hFontNameList, LB_FINDSTRINGEXACT, -1,
(LPARAM)fontName.c_str());
if (itemIndex == -1)
itemIndex = 0;
SendMessage(hFontNameList, LB_SETCURSEL, itemIndex, 0);
_sntprintf(sizeCStr, 16, _T("%d"), pointSize / 10);
itemIndex = SendMessage(hFontSizeList, LB_FINDSTRINGEXACT, -1,
(LPARAM)sizeCStr);
if (itemIndex == -1)
itemIndex = 0;
SendMessage(hFontSizeList, LB_SETCURSEL, itemIndex, 0);
itemIndex = (isItalic ? 0x01 : 0x00) | (isBold ? 0x02 : 0x00);
SendMessage(hFontStyleList, LB_SETCURSEL, itemIndex, 0);
}
data->isInitializing = false;
updateFont(hDlg);
ShowWindow(hDlg, SW_SHOW);
}
static void onOk(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
data->chooseFontParams->hFont = data->hCurrentFont;
EndDialog(hDlg, IDOK);
}
static void onCancel(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
DeleteObject(data->hCurrentFont);
EndDialog(hDlg, IDCANCEL);
}
static void onNameList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void onSizeList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void onStyleList(HWND hDlg, int event) {
if (event == LBN_SELCHANGE)
updateFont(hDlg);
}
static void updateFont(HWND hDlg) {
KnceFontDlgData *data =
(KnceFontDlgData *)GetWindowLong(hDlg, GWL_USERDATA);
if (data->isInitializing)
return;
if (data->hCurrentFont != NULL)
DeleteObject(data->hCurrentFont);
HWND hFontNameList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_NAME_LIST);
int fontNameIndex = SendMessage(hFontNameList, LB_GETCURSEL, 0, 0);
TCHAR *fontNameBuf = new TCHAR[SendMessage(hFontNameList, LB_GETTEXTLEN,
fontNameIndex, 0) + 1];
SendMessage(hFontNameList, LB_GETTEXT, fontNameIndex, (LPARAM)fontNameBuf);
HWND hFontSizeList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_SIZE_LIST);
int fontSizeIndex = SendMessage(hFontSizeList, LB_GETCURSEL, 0, 0);
TCHAR *sizeBuf = new TCHAR[SendMessage(hFontSizeList, LB_GETTEXTLEN,
fontSizeIndex, 0) + 1];
SendMessage(hFontSizeList, LB_GETTEXT, fontSizeIndex, (LPARAM)sizeBuf);
int pointSize = _ttoi(sizeBuf) * 10;
HWND hFontStyleList = GetDlgItem(hDlg, IDC_CHOOSE_FONT_STYLE_LIST);
int fontStyleIndex = SendMessage(hFontStyleList, LB_GETCURSEL, 0, 0);
bool isBold = (fontStyleIndex & 0x02) != 0;
bool isItalic = (fontStyleIndex & 0x01) != 0;
data->hCurrentFont = KnceUtil::createFont(fontNameBuf, pointSize, isBold,
isItalic);
delete [] fontNameBuf;
delete [] sizeBuf;
HWND hExampleLabel = GetDlgItem(hDlg, IDC_CHOOSE_FONT_EXAMPLE_LABEL);
SendMessage(hExampleLabel, WM_SETFONT, (WPARAM)data->hCurrentFont, 0);
}

View File

@ -0,0 +1,147 @@
#include "kncedlg.h"
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
using namespace std;
enum {
MESSAGE_MARGIN = 25
};
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
static void onCreate(HWND hWnd, CREATESTRUCT *createStruct);
static void onDestroy(HWND hWnd);
static void onPaint(HWND hWnd, HDC hDC);
static void changeWindowLayout(HWND hWnd);
extern HINSTANCE g_hInstance;
struct WaitBoxData {
tstring message;
};
void registerWaitBoxClass() {
WNDCLASS windowClass;
memset(&windowClass, 0, sizeof(WNDCLASS));
windowClass.lpfnWndProc = wndProc;
windowClass.hInstance = g_hInstance;
windowClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
windowClass.lpszClassName = _T("KNCommonLibWaitBox");
RegisterClass(&windowClass);
}
void unregisterWaitBoxClass() {
UnregisterClass(_T("KNCommonLibWaitBox"), g_hInstance);
}
HWND createWaitBox(HWND hOwnerWindow, const tstring &msg) {
HWND hWnd = CreateWindowEx(
0,
_T("KNCommonLibWaitBox"), _T(""),
WS_POPUP | WS_BORDER,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hOwnerWindow, NULL, g_hInstance, (void *)&msg);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return hWnd;
}
void destroyWaitBox(HWND hWnd) {
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam) {
switch (msg) {
case WM_CREATE:
onCreate(hWnd, (CREATESTRUCT *)lParam);
return 0;
case WM_DESTROY:
onDestroy(hWnd);
return 0;
case WM_COMMAND:
{
int id = LOWORD(wParam);
int event = HIWORD(wParam);
//switch (id) {
//}
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT paintStruct;
HDC hDC = BeginPaint(hWnd, &paintStruct);
onPaint(hWnd, hDC);
EndPaint(hWnd, &paintStruct);
return 0;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
static void onCreate(HWND hWnd, CREATESTRUCT *createStruct) {
WaitBoxData *data = new WaitBoxData();
SetWindowLong(hWnd, GWL_USERDATA, (long)data);
data->message = *(const tstring *)createStruct->lpCreateParams;
if (data->message.empty())
data->message = _T("Please wait...");
changeWindowLayout(hWnd);
}
static void onDestroy(HWND hWnd) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
delete data;
}
static void onPaint(HWND hWnd, HDC hDC) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
int prevBkMode = SetBkMode(hDC, TRANSPARENT);
ExtTextOut(hDC, MESSAGE_MARGIN, MESSAGE_MARGIN, 0, NULL,
data->message.c_str(), data->message.size(), NULL);
SetBkMode(hDC, prevBkMode);
}
static void changeWindowLayout(HWND hWnd) {
WaitBoxData *data = (WaitBoxData *)GetWindowLong(hWnd, GWL_USERDATA);
HDC hDC = GetDC(hWnd);
SIZE textSize;
GetTextExtentExPointW(hDC, data->message.c_str(), data->message.size(), 0,
NULL, NULL, &textSize);
ReleaseDC(hWnd, hDC);
int windowWidth = textSize.cx + MESSAGE_MARGIN * 2 + 2;
int windowHeight = textSize.cy + MESSAGE_MARGIN * 2 + 2;
RECT desktopRect;
HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktopRect);
MoveWindow(hWnd, (desktopRect.right - windowWidth) / 2,
(desktopRect.bottom - windowHeight) / 2, windowWidth, windowHeight,
false);
}

674
knceutil-0.12/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

573
knceutil-0.12/knceutil.cpp Normal file
View File

@ -0,0 +1,573 @@
#include "knceutil.h"
#include <algorithm>
using namespace std;
enum {
NWUS_KEYBD_REPEAT_CHANGED = 2
};
extern "C" void WINAPI NotifyWinUserSystem(UINT uEvent);
static int CALLBACK enumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData);
static int CALLBACK enumFixedFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
static int CALLBACK enumVariableFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
static int CALLBACK checkFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData);
map<int, tstring> KnceUtil::m_hardKeyCodeToNameTable;
map<tstring, int> KnceUtil::m_hardKeyNameToCodeTable;
int KnceUtil::m_savedKeyRepeatRefCount = 0;
int KnceUtil::m_savedKeyRepeatInitialDelay = 0;
int KnceUtil::m_savedKeyRepeatRate = 0;
static int CALLBACK enumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@'))
names->push_back(lplf->lfFaceName);
return 1;
}
static int CALLBACK enumFixedFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == FIXED_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK enumVariableFontsProc(const LOGFONT *lplf,
const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
vector<tstring> *names = (vector<tstring> *)lpData;
if (lplf->lfFaceName[0] != _T('@') &&
((lplf->lfPitchAndFamily & 0x03) == VARIABLE_PITCH))
{
names->push_back(lplf->lfFaceName);
}
return 1;
}
static int CALLBACK checkFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm,
DWORD dwType, LPARAM lpData)
{
const tstring *name = (tstring *)lpData;
if (tstring(lplf->lfFaceName) == *name)
return 0;
return 1;
}
tstring KnceUtil::getCurrentDirectory() {
TCHAR modulePath[MAX_PATH];
GetModuleFileName(NULL, modulePath, MAX_PATH);
TCHAR *p = _tcschr(modulePath, _T('\0'));
for ( ; p >= modulePath; p--) {
if (*p == _T('\\')) {
*p = _T('\0');
break;
}
}
return modulePath;
}
int KnceUtil::compareFileTime(bool &failed, const tstring &fileName1,
const tstring &fileName2) {
failed = false;
WIN32_FIND_DATA fd1;
HANDLE hFind = FindFirstFile(fileName1.c_str(), &fd1);
if (hFind == INVALID_HANDLE_VALUE) {
failed = true;
return 0;
}
FindClose(hFind);
WIN32_FIND_DATA fd2;
hFind = FindFirstFile(fileName2.c_str(), &fd2);
if (hFind == INVALID_HANDLE_VALUE) {
failed = true;
return 0;
}
int result = CompareFileTime(&fd1.ftLastWriteTime, &fd2.ftLastWriteTime);
FindClose(hFind);
return result;
}
int KnceUtil::registerHotKey(HWND hWnd, unsigned int mods,
unsigned int keyCode)
{
TCHAR hotKeyNameCStr[64];
_sntprintf(hotKeyNameCStr, 64, _T("KNCECOMM_HOTKEY_%d_%d"), keyCode, mods);
int hotKeyId = GlobalAddAtom(hotKeyNameCStr);
if (!RegisterHotKey(hWnd, hotKeyId, mods, keyCode)) {
GlobalDeleteAtom(hotKeyId);
return 0;
}
return hotKeyId;
}
bool KnceUtil::unregisterHotKey(HWND hWnd, int id) {
if (id == 0)
return true;
bool ret = UnregisterHotKey(hWnd, id) != 0;
GlobalDeleteAtom(id);
return ret;
}
bool KnceUtil::hardKeyCodeToName(tstring &name, int code) {
if (m_hardKeyCodeToNameTable.empty())
createKeyCodeTable();
if (code < 0 || code > 255)
return false;
map<int, tstring>::const_iterator iter =
m_hardKeyCodeToNameTable.find(code);
if (iter == m_hardKeyCodeToNameTable.end()) {
TCHAR nameCStr[256];
_sntprintf(nameCStr, 256, _T("UNKNOWN%d"), code);
name = nameCStr;
}
else
name = iter->second.c_str();
return true;
}
int KnceUtil::hardKeyNameToCode(const tstring &name) {
if (m_hardKeyNameToCodeTable.empty())
createKeyCodeTable();
map<tstring, int>::const_iterator iter =
m_hardKeyNameToCodeTable.find(name);
if (iter == m_hardKeyNameToCodeTable.end()) {
int code = 0;
if (_stscanf(name.c_str(), _T("UNKNOWN%d"), &code) == 1) {
if (code < 0 || code > 255)
return -1;
else
return code;
}
else
return -1;
}
else
return iter->second;
}
void KnceUtil::changeKeyRepeatSpeed(int initDelay, int repeatRate) {
if (m_savedKeyRepeatRefCount++ > 0)
return;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\keybd"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
DWORD val = 0;
DWORD size = sizeof(DWORD);
RegQueryValueEx(hKey, _T("InitialDelay"), NULL, 0,
(BYTE *)&val, &size);
m_savedKeyRepeatInitialDelay = val;
RegQueryValueEx(hKey, _T("RepeatRate"), NULL, 0, (BYTE *)&val, &size);
m_savedKeyRepeatRate = val;
val = (DWORD)initDelay;
RegSetValueEx(hKey, _T("InitialDelay"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
val = (unsigned long)repeatRate;
RegSetValueEx(hKey, _T("RepeatRate"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
RegCloseKey(hKey);
NotifyWinUserSystem(NWUS_KEYBD_REPEAT_CHANGED);
}
void KnceUtil::restoreKeyRepeatSpeed() {
if (--m_savedKeyRepeatRefCount > 0)
return;
HKEY hKey = NULL;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\keybd"), 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
DWORD val = 0;
DWORD size = sizeof(DWORD);
val = (DWORD)m_savedKeyRepeatInitialDelay;
RegSetValueEx(hKey, _T("InitialDelay"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
val = (DWORD)m_savedKeyRepeatRate;
RegSetValueEx(hKey, _T("RepeatRate"), 0, REG_DWORD, (const BYTE *)&val,
sizeof(DWORD));
RegCloseKey(hKey);
NotifyWinUserSystem(NWUS_KEYBD_REPEAT_CHANGED);
}
HFONT KnceUtil::createFont(const tstring &faceName, int pointSize,
bool isBold, bool isItalic, int pitchType) {
LOGFONT logFont = {0};
if (faceName.empty()) {
vector<tstring> fontNames;
obtainFontNames(fontNames, pitchType);
if (!fontNames.empty())
_tcsncpy(logFont.lfFaceName, fontNames[0].c_str(), LF_FACESIZE);
}
else
_tcsncpy(logFont.lfFaceName, faceName.c_str(), LF_FACESIZE);
if (isBold)
logFont.lfWeight = FW_BOLD;
if (isItalic)
logFont.lfItalic = true;
logFont.lfPitchAndFamily = pitchType;
HDC hDC = GetDC(NULL);
logFont.lfHeight = -ceil(GetDeviceCaps(hDC, LOGPIXELSY) *
pointSize / 720.0);
ReleaseDC(NULL, hDC);
logFont.lfCharSet = DEFAULT_CHARSET;
return CreateFontIndirect(&logFont);
}
int KnceUtil::obtainFontNames(vector<tstring> &fontNames, int pitchType) {
switch (pitchType) {
case KNCE_FONT_PITCH_FIXED:
EnumFonts(GetDC(NULL), NULL, enumFixedFontsProc, (LPARAM)&fontNames);
break;
case KNCE_FONT_PITCH_VARIABLE:
EnumFonts(GetDC(NULL), NULL, enumVariableFontsProc, (LPARAM)&fontNames);
break;
default:
EnumFonts(GetDC(NULL), NULL, enumFontsProc, (LPARAM)&fontNames);
break;
}
return fontNames.size();
}
bool KnceUtil::fontExists(const tstring &name) {
return EnumFonts(GetDC(NULL), NULL, checkFontProc, (LPARAM)&name) == 0;
}
void KnceUtil::getFontAttributes(HFONT hFont, tstring &faceName,
int &pointSize, bool &isBold, bool &isItalic) {
LOGFONT logFont;
GetObject(hFont, sizeof(LOGFONT), &logFont);
faceName = logFont.lfFaceName;
HDC hDC = GetDC(NULL);
pointSize = -ceil(logFont.lfHeight * 720.0 /
GetDeviceCaps(hDC, LOGPIXELSY));
ReleaseDC(NULL, hDC);
isItalic = logFont.lfItalic != 0;
isBold = logFont.lfWeight >= FW_BOLD;
}
bool KnceUtil::matchFileExtension(const tstring &fileName,
const tstring &pat) {
if (pat == _T("*.*"))
return true;
if (pat.length() < 2 || pat.substr(0, 2) != _T("*."))
return false;
int fileNameLen = fileName.length();
tstring ext = pat.substr(1);
int extLen = ext.length();
if (fileNameLen < extLen)
return false;
tstring fileExt = fileName.substr(fileNameLen - extLen, extLen);
if (!matchStringsIgnoreCase(fileExt, ext))
return false;
return true;
}
bool KnceUtil::matchMultiFileExtension(const tstring &fileName,
const tstring &pats) {
int i;
vector<tstring> patList;
split(patList, pats, _T(";"));
int numPats = patList.size();
for (i = 0; i < numPats; i++) {
if (matchFileExtension(fileName, patList[i].c_str()))
return true;
}
return false;
}
void KnceUtil::debugMessageBox(HWND hOwnerWindow,
const TCHAR *msg, ...) {
va_list args;
va_start(args, msg);
TCHAR msgCStr[256];
_vsntprintf(msgCStr, 256, msg, args);
MessageBox(hOwnerWindow, msgCStr, _T("Debug"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
va_end(args);
}
bool KnceUtil::matchStringsIgnoreCase(const tstring &str1, const tstring &str2) {
return toLowerString(str1) == toLowerString(str2);
}
tstring KnceUtil::toLowerString(const tstring &str) {
tstring newStr = str;
transform(newStr.begin(), newStr.end(), newStr.begin(), _totlower);
return newStr;
}
void KnceUtil::split(vector<tstring> &result, const tstring &str,
const tstring &delim) {
tstring strWork = str;
int cutAt = 0;
while ((cutAt = strWork.find_first_of(delim)) != tstring::npos) {
if (cutAt > 0)
result.push_back(strWork.substr(0, cutAt));
strWork = strWork.substr(cutAt + 1);
}
if (strWork.length() > 0)
result.push_back(strWork);
}
void KnceUtil::createKeyCodeTable() {
int i;
static int realKeyCodes[] = {
0x11, 0x70,
0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x79, 0x24,
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55,
0x49, 0x4f, 0x50,
0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4a,
0x4b, 0x4c,
0x5a, 0x58, 0x43, 0x56, 0x42, 0x4e, 0x4d,
0xbd,
0x14, 0x23, 0x08,
0x21, 0x22, 0xdb, 0xdd,
0xbe, 0xbc,
0xdc, 0xba, 0xbf,
0x1b, 0x0d,
0x25, 0x26, 0x27, 0x28
};
static TCHAR *realKeyCStrs[] = {
_T("POWER"), _T("WHOLESEARCH"),
_T("CONTENTS1"), _T("CONTENTS2"), _T("CONTENTS3"), _T("CONTENTS4"),
_T("SWITCH"), _T("BOOKMARKS"), _T("LIBRARY"), _T("MENU"),
_T("Q"), _T("W"), _T("E"), _T("R"), _T("T"), _T("Y"), _T("U"),
_T("I"), _T("O"), _T("P"),
_T("A"), _T("S"), _T("D"), _T("F"), _T("G"), _T("H"), _T("J"),
_T("K"), _T("L"),
_T("Z"), _T("X"), _T("C"), _T("V"), _T("B"), _T("N"), _T("M"),
_T("HYPHEN"),
_T("FUNCTION"), _T("CLEAR"), _T("BACKSPACE"),
_T("PAGEUP"), _T("PAGEDOWN"), _T("VOLUMEUP"), _T("VOLUMEDOWN"),
_T("LARGER"), _T("SMALLER"),
_T("VOICE"), _T("DESCRIPTION"), _T("SJUMP"),
_T("BACK"),_T("EXECUTE"),
_T("LEFT"), _T("UP"), _T("RIGHT"), _T("DOWN")
};
int numRealKeys = sizeof(realKeyCodes) / sizeof(int);
for (i = 0; i < numRealKeys; i++) {
m_hardKeyCodeToNameTable[realKeyCodes[i]] = realKeyCStrs[i];
m_hardKeyNameToCodeTable[realKeyCStrs[i]] = realKeyCodes[i];
}
}
void KnceUtil::centerWindow(HWND hWnd) {
RECT workAreaRect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0);
RECT windowRect = {0};
GetWindowRect(hWnd, &windowRect);
int windowWidth = windowRect.right - windowRect.left;
int windowHeight = windowRect.bottom - windowRect.top;
MoveWindow(hWnd, (workAreaRect.right - windowWidth) / 2,
(workAreaRect.bottom - windowHeight) / 2, windowWidth, windowHeight,
false);
}
void KnceUtil::adjustDialogLayout(HWND hDlg) {
//long baseUnits = GetDialogBaseUnits();
int baseX = 7; //LOWORD(baseUnits);
int baseY = 14; //HIWORD(baseUnits);
RECT rect = {0, 0, 1000, 1000};
MapDialogRect(hDlg, &rect);
double scaleX = rect.right / 1000.0;
double scaleY = rect.bottom / 1000.0;
RECT clientRect;
GetClientRect(hDlg, &clientRect);
int newWidth = clientRect.right / scaleX / 4.0 * baseX;
int newHeight = clientRect.bottom / scaleY / 8.0 * baseY;
newWidth += GetSystemMetrics(SM_CXEDGE) +
GetSystemMetrics(SM_CXBORDER) +
GetSystemMetrics(SM_CXFIXEDFRAME);
newHeight += GetSystemMetrics(SM_CYEDGE) +
GetSystemMetrics(SM_CYBORDER) +
GetSystemMetrics(SM_CYFIXEDFRAME) +
GetSystemMetrics(SM_CYCAPTION);
SetWindowPos(hDlg, NULL, 0, 0, newWidth, newHeight,
SWP_NOMOVE | SWP_NOZORDER);
TCHAR classNameCStr[256];
RECT childRect;
HWND hChild = GetWindow(hDlg, GW_CHILD);
while (hChild != NULL) {
GetClassName(hChild, classNameCStr, 256);
if (_tcsicmp(classNameCStr, _T("combobox")) == 0)
SendMessage(hChild, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&childRect);
else
GetWindowRect(hChild, &childRect);
POINT pt = {childRect.left, childRect.top};
ScreenToClient(hDlg, &pt);
int newLeft = pt.x / scaleX / 4.0 * baseX;
int newTop = pt.y / scaleY / 8.0 * baseY;
newWidth = (childRect.right - childRect.left) /
scaleX / 4.0 * baseX;
newHeight = (childRect.bottom - childRect.top) /
scaleY / 8.0 * baseY;
SetWindowPos(hChild, NULL, newLeft, newTop, newWidth, newHeight,
SWP_NOZORDER);
hChild = GetWindow(hChild, GW_HWNDNEXT);
}
if ((GetWindowLong(hDlg, GWL_STYLE) & DS_CENTER) != 0)
centerWindow(hDlg);
}
void KnceUtil::dialogUnitsToPixels(int &xUnits, int &yUnits) {
//long baseUnits = GetDialogBaseUnits();
int baseX = 7; //LOWORD(baseUnits);
int baseY = 14; //HIWORD(baseUnits);
xUnits = xUnits / 4.0 * baseX;
yUnits = yUnits / 8.0 * baseY;
}
bool KnceUtil::readPropertyFile(map<tstring, tstring> &props,
const tstring &fileName) {
FILE *file = _tfopen(fileName.c_str(), _T("r"));
if (file == NULL)
return false;
TCHAR lineBuf[1024];
char mbLineBuf[sizeof(lineBuf) * 2];
while (true) {
if (fgets(mbLineBuf, sizeof(mbLineBuf), file) == NULL)
break;
char *cr = strchr(mbLineBuf, '\n');
if (cr != NULL)
*cr = '\0';
MultiByteToWideChar(932, 0, mbLineBuf, -1, lineBuf, sizeof(lineBuf));
tstring line = lineBuf;
int pos = line.find(_T('='));
props[line.substr(0, pos)] = line.substr(pos + 1);
}
fclose(file);
return true;
}
bool KnceUtil::writePropertyFile(const tstring &fileName,
const map<tstring, tstring> &props) {
FILE *file = _tfopen(fileName.c_str(), _T("w"));
if (file == NULL)
return false;
char mbLineBuf[1024 * 2];
map<tstring, tstring>::const_iterator iter = props.begin();
for ( ; iter != props.end(); iter++) {
tstring line = iter->first + _T("=") + iter->second + _T("\n");
WideCharToMultiByte(932, 0, line.c_str(), -1, mbLineBuf,
sizeof(mbLineBuf), NULL, NULL);
fputs(mbLineBuf, file);
}
fclose(file);
return true;
}

106
knceutil-0.12/knceutil.h Normal file
View File

@ -0,0 +1,106 @@
#ifndef KNCEUTIL_H_
#define KNCEUTIL_H_
#include <vector>
#include <map>
#include <string>
#include <windows.h>
#ifdef UNICODE
namespace std { typedef wstring tstring; }
#else
namespace std { typedef string tstring; }
#endif
enum {
HARD_KEY_POWER = 0x11,
HARD_KEY_WHOLESEARCH = 0x70,
HARD_KEY_CONTENTS1 = 0x71,
HARD_KEY_CONTENTS2 = 0x72,
HARD_KEY_CONTENTS3 = 0x73,
HARD_KEY_CONTENTS4 = 0x74,
HARD_KEY_SWITCH = 0x75,
HARD_KEY_BOOKMARKS = 0x76,
HARD_KEY_HOME = 0x79,
HARD_KEY_MENU = 0x24,
HARD_KEY_HYPHEN = 0xbd,
HARD_KEY_FUNCTION = 0x14,
HARD_KEY_CLEAR = 0x23,
HARD_KEY_BACKSPACE = 0x08,
HARD_KEY_PAGEUP = 0x21,
HARD_KEY_PAGEDOWN = 0x22,
HARD_KEY_VOLUMEUP = 0xdb,
HARD_KEY_VOLUMEDOWN = 0xdd,
HARD_KEY_LARGER = 0xbe,
HARD_KEY_SMALLER = 0xbc,
HARD_KEY_VOICE = 0xdc,
HARD_KEY_DESCRIPTION = 0xba,
HARD_KEY_SJUMP = 0xbf,
HARD_KEY_BACK = 0x1b,
HARD_KEY_EXECUTE = 0x0d,
HARD_KEY_LEFT = 0x25,
HARD_KEY_UP = 0x26,
HARD_KEY_RIGHT = 0x27,
HARD_KEY_DOWN = 0x28,
KNCE_FONT_PITCH_ALL = 0,
KNCE_FONT_PITCH_FIXED = 1,
KNCE_FONT_PITCH_VARIABLE = 2
};
class KnceUtil {
public:
static std::tstring getCurrentDirectory();
static int compareFileTime(bool &failed, const std::tstring &fileName1,
const std::tstring &fileName2);
static int registerHotKey(HWND hWnd, unsigned int mods,
unsigned int keyCode);
static bool unregisterHotKey(HWND hWnd, int id);
static bool hardKeyCodeToName(std::tstring &name, int code);
static int hardKeyNameToCode(const std::tstring &name);
static void changeKeyRepeatSpeed(int initDelay, int repeatRate);
static void restoreKeyRepeatSpeed();
static HFONT createFont(const std::tstring &faceName, int pointSize,
bool isBold = false, bool isItalic = false,
int pitchType = KNCE_FONT_PITCH_ALL);
static int obtainFontNames(std::vector<std::tstring> &fontNames,
int pitchType = KNCE_FONT_PITCH_ALL);
static bool fontExists(const std::tstring &name);
static void getFontAttributes(HFONT hFont, std::tstring &faceName,
int &pointSize, bool &isBold, bool &isItalic);
static bool matchFileExtension(const std::tstring &fileName,
const std::tstring &pat);
static bool matchMultiFileExtension(const std::tstring &fileName,
const std::tstring &pats);
static void debugMessageBox(HWND hOwnerWindow, const TCHAR *msg,
...);
static bool matchStringsIgnoreCase(const std::tstring &str1,
const std::tstring &str2);
static std::tstring toLowerString(const std::tstring &str);
static void split(std::vector<std::tstring> &result,
const std::tstring &str, const std::tstring &delim);
static void centerWindow(HWND hWnd);
static void adjustDialogLayout(HWND hDlg);
static void dialogUnitsToPixels(int &xUnits, int &yUnits);
static bool readPropertyFile(std::map<std::tstring, std::tstring> &props,
const std::tstring &fileName);
static bool writePropertyFile(const std::tstring &fileName,
const std::map<std::tstring, std::tstring> &props);
private:
static void createKeyCodeTable();
static std::map<int, std::tstring> m_hardKeyCodeToNameTable;
static std::map<std::tstring, int> m_hardKeyNameToCodeTable;
static int m_savedKeyRepeatRefCount;
static int m_savedKeyRepeatInitialDelay;
static int m_savedKeyRepeatRate;
};
#endif /* KNCEUTIL_H_ */

17
knceutil-0.12/knceutil.mk Normal file
View File

@ -0,0 +1,17 @@
TARGET=knceutil-0.12.lib
CPP=clarm
CPPFLAGS=/nologo /W3 /O2 /EHsc /QRarch4T /QRinterwork-return \
/D "ARM" /D "_ARM_" /D "ARMV4I" /D UNDER_CE=400 \
/D "UNICODE" /D "_UNICODE"
OBJS=\
knceutil.obj
all : $(TARGET)
$(TARGET) : $(OBJS)
lib /NOLOGO /OUT:$@ $(OBJS)
clean :
-del $(TARGET) $(OBJS)
knceutil.obj : knceutil.h