- 1 year ago
Highlighting Windows or MacOs Screen without impacting clickable area
To highlight a specific area of the screen on Windows or macOS without impacting the clickable area, you can use overlay techniques or transparent windows. Here's an approach for each platform:
Windows:
In Windows, you can create a transparent window with a colored overlay to highlight the desired area. The transparent window will allow interaction with the underlying elements while still providing a visual highlight. You can achieve this using a combination of the Win32 API and window styles.
Here's a basic example using Win32 API in C++:
cpp#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Draw the colored overlay
RECT rect = { 100, 100, 300, 300 }; // Example rectangle to highlight
SetBkColor(hdc, RGB(255, 0, 0)); // Red overlay color
ExtTextOut(hdc, rect.left, rect.top, ETO_OPAQUE, &rect, NULL, 0, NULL);
EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
const wchar_t className[] = L"HighlightWindowClass";
WNDCLASS wndClass = { 0 };
wndClass.lpfnWndProc = WindowProc;
wndClass.hInstance = hInstance;
wndClass.lpszClassName = className;
if (!RegisterClass(&wndClass))
return -1;
HWND hwnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, className, L"Highlight Window", WS_POPUP, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);
SetLayeredWindowAttributes(hwnd, RGB(255, 255, 255), 100, LWA_COLORKEY);
ShowWindow(hwnd, nCmdShow);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
In this example, we create a transparent window using the
WS_EX_LAYERED
andWS_EX_TRANSPARENT
window styles. We handle theWM_PAINT
message to draw the colored overlay using theSetBkColor
andExtTextOut
functions.macOS:
On macOS, you can utilize the Core Graphics framework to draw a transparent overlay on the screen. By creating a transparent window with a borderless, non-opaque view, you can highlight the desired area without affecting the clickable elements underneath.
Here's an example using Objective-C:
objc#import <Cocoa/Cocoa.h>
@interface HighlightWindow : NSWindow
@end
@implementation HighlightWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}
@end
@interface HighlightView : NSView
@end
@implementation HighlightView
- (void)drawRect:(NSRect)dirtyRect {
// Draw the colored overlay
NSRect rect = NSMakeRect(100,