Skip to content

Commit

Permalink
Initial work on set active window
Browse files Browse the repository at this point in the history
  • Loading branch information
EladBezalel committed May 5, 2015
1 parent f03721f commit 4d3990e
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ NAN_METHOD(Minimize) {

HWND hwnd = (HWND)args[0]->Uint32Value();

ShowWindow(hwnd, 6);
ShowWindow(hwnd, SW_MINIMIZE);
}

NAN_METHOD(Show) {
NanScope();

HWND hwnd = (HWND)args[0]->Uint32Value();

ShowWindow(hwnd, SW_SHOW);
}

NAN_METHOD(Maximize) {
NanScope();

HWND hwnd = (HWND)args[0]->Uint32Value();

ShowWindow(hwnd, 3);
ShowWindow(hwnd, SW_MAXIMIZE);
}

NAN_METHOD(IsForeground) {
Expand Down Expand Up @@ -152,7 +160,15 @@ NAN_METHOD(Close) {

HWND hwnd = (HWND)args[0]->Uint32Value();

ShowWindow(hwnd, 0);
ShowWindow(hwnd, SW_HIDE);
}

NAN_METHOD(Restore) {
NanScope();

HWND hwnd = (HWND)args[0]->Uint32Value();

ShowWindow(hwnd, SW_RESTORE);
}

NAN_METHOD(SetToForeground) {
Expand All @@ -164,6 +180,32 @@ NAN_METHOD(SetToForeground) {
SetForegroundWindow(hwnd);
}

NAN_METHOD(Activate) {
NanScope();

HWND hwnd = (HWND)args[0]->Uint32Value();
int result;

if (hwnd != GetForegroundWindow()) {
DWORD lForeThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
DWORD lThisThreadID = GetWindowThreadProcessId(hwnd, NULL);

if (lForeThreadID != lThisThreadID) {
AttachThreadInput(lForeThreadID, lThisThreadID, TRUE);
result = SetForegroundWindow(hwnd);
AttachThreadInput(lForeThreadID, lThisThreadID, FALSE);
} else {
result = SetForegroundWindow(hwnd);
}

if (IsIconic(hwnd)) {
ShowWindow(hwnd, SW_RESTORE);
} else {
ShowWindow(hwnd, SW_SHOW);
}
}
}

LRESULT CALLBACK DisableZWindowProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode >= 0) {
// lParam is the pointer to the struct containing the data needed, so cast and assign it to kdbStruct.
Expand Down Expand Up @@ -299,6 +341,15 @@ void init(Handle<Object> exports) {
exports->Set(NanNew<String>("minimize"),
NanNew<FunctionTemplate>(Minimize)->GetFunction());

exports->Set(NanNew<String>("activate"),
NanNew<FunctionTemplate>(Activate)->GetFunction());

exports->Set(NanNew<String>("restore"),
NanNew<FunctionTemplate>(Restore)->GetFunction());

exports->Set(NanNew<String>("show"),
NanNew<FunctionTemplate>(Show)->GetFunction());

exports->Set(NanNew<String>("maximize"),
NanNew<FunctionTemplate>(Maximize)->GetFunction());

Expand Down

0 comments on commit 4d3990e

Please sign in to comment.