Skip to content

Commit

Permalink
Added a few new static functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Jun 25, 2024
1 parent 6550263 commit f52be25
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cpp/SampleCommands/SampleFunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stdafx.h"
#include <Psapi.h>

/// <summary>
/// Evaluate torsion of a curve at a parmeter.
Expand Down Expand Up @@ -360,3 +361,48 @@ const CRhinoHatchPattern* CRhinoHatchTableHelper::FindOrCreateHatchPattern(CRhin
}
return rc;
}


/// <summary>
/// Returns true if Rhino was started as a standalone executable.
/// Returns false if Rhino was started by some other application or process.
/// </summary>
static bool IsRhinoRunningAsExe()
{
bool rc = false;
DWORD dwProcessId = ::GetCurrentProcessId();
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId);
if (hProcess)
{
wchar_t szPath[MAX_PATH];
DWORD dwLength = ::GetModuleFileNameEx(hProcess, 0, szPath, MAX_PATH);
::CloseHandle(hProcess);
if (dwLength > 0)
{
ON_wString name;
ON_FileSystemPath::SplitPath(szPath, nullptr, nullptr, &name, nullptr);
rc = name.EqualOrdinal(L"Rhino", true);
}
}
return rc;
}

/// <summary>
/// Returns true if Rhino has input focus.
/// </summary>
static bool RhinoHasFocus()
{
// Retrieves a handle to the foreground window
HWND hWnd = ::GetForegroundWindow();
if (hWnd != NULL)
{
// Retrieves the identifier of the thread that created the specified window
DWORD dwProcessId = 0;
::GetWindowThreadProcessId(hWnd, &dwProcessId);
// Retrieves the process identifier of the calling process (a.k.a. Rhino)
DWORD dwRhinoProcessId = ::GetCurrentProcessId();
// Compare and return
return (dwRhinoProcessId == dwProcessId);
}
return false;
}

0 comments on commit f52be25

Please sign in to comment.