Skip to content

Commit

Permalink
Merge pull request #1 from nosolosoftware/feature/accents-window-title
Browse files Browse the repository at this point in the history
Feature/accents window title
  • Loading branch information
pacop authored Jul 12, 2021
2 parents 12f63c6 + 984ab4d commit 711b093
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [0.3.0] - 12-07-2021

### Changed
- Added support for accents at the window's title

# [0.2.0] - 03-09-2020

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "win-control",
"version": "0.2.0",
"version": "0.3.0",
"description": "Windows manipulation made easy for node.js",
"author": "Francisco Padillo <[email protected]>",
"license": "MIT",
Expand Down
15 changes: 9 additions & 6 deletions src/c++/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ Napi::Value Window::Exists(const Napi::CallbackInfo& info) {
}

Napi::Value Window::GetTitle(const Napi::CallbackInfo& info) {
char wndTitle[256];
GetWindowText(this->_identifier, wndTitle, sizeof(wndTitle));
int lengthWindowText = GetWindowTextLength(this->_identifier);
std::wstring title(lengthWindowText, L'\0');
GetWindowTextW(this->_identifier, &title[0], lengthWindowText);

return Napi::String::New(info.Env(), wndTitle);
return Napi::String::New(info.Env(), std::u16string(title.begin(), title.end()));
}

Napi::Value Window::GetClassName(const Napi::CallbackInfo& info) {
Expand Down Expand Up @@ -274,10 +275,12 @@ Napi::Value Window::GetProcessInfo(const Napi::CallbackInfo& info) {
// Para solicitar datos de este proceso necesitamos crear un puntero a el
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, lpdwProcessId);

char wndTitle[256];
GetWindowText(this->_identifier, wndTitle, sizeof(wndTitle));
int lengthWindowText = GetWindowTextLength(this->_identifier);
std::wstring title(lengthWindowText, L'\0');
GetWindowTextW(this->_identifier, &title[0], lengthWindowText);

result.Set("windowText", Napi::String::New(info.Env(), wndTitle));
result.Set("windowText", Napi::String::New(info.Env(),
std::u16string(title.begin(), title.end())));

// Comprobamos que tenemos acceso para consultar el proceso, y que el puntero esta bien
if (NULL != hProcess) {
Expand Down

0 comments on commit 711b093

Please sign in to comment.