Skip to content

Commit

Permalink
upd code
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypp committed Dec 4, 2023
1 parent e8396db commit 2c9bfd8
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 104 deletions.
16 changes: 8 additions & 8 deletions src/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ VOID _app_initializeregion (
height = _r_calc_rectheight (&monitor_context->rect);

// load cursor
monitor_context->hcursor = LoadCursor (_r_sys_getimagebase (), MAKEINTRESOURCE (IDI_MAIN));
monitor_context->hcursor = LoadCursorW (_r_sys_getimagebase (), MAKEINTRESOURCE (IDI_MAIN));

// create pen
pen_size = _r_dc_getsystemmetrics (SM_CXBORDER, dpi_value) * 4;
Expand Down Expand Up @@ -242,7 +242,7 @@ HWND _app_showdummy (

CopyRect (&dummy_context.rect, rect);

hdummy = CreateWindowEx (0, DUMMY_CLASS_DLG, _r_app_getname (), WS_POPUP | WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL, _r_sys_getimagebase (), &dummy_context);
hdummy = CreateWindowExW (0, DUMMY_CLASS_DLG, _r_app_getname (), WS_POPUP | WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL, _r_sys_getimagebase (), &dummy_context);

return hdummy;
}
Expand Down Expand Up @@ -386,13 +386,13 @@ INT_PTR CALLBACK RegionProc (

case WM_LBUTTONDOWN:
{
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_START, 0), lparam);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_START, 0), lparam);
break;
}

case WM_MBUTTONDOWN:
{
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_CANCEL, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_CANCEL, 0), 0);
break;
}

Expand All @@ -406,7 +406,7 @@ INT_PTR CALLBACK RegionProc (
if (!GetCursorPos (&pt))
break;

hmenu = LoadMenu (NULL, MAKEINTRESOURCE (IDM_REGION));
hmenu = LoadMenuW (NULL, MAKEINTRESOURCE (IDM_REGION));

if (!hmenu)
break;
Expand All @@ -423,7 +423,7 @@ INT_PTR CALLBACK RegionProc (
command_id = _r_menu_popup (hsubmenu, hwnd, &pt, FALSE);

if (command_id)
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (command_id, 0), MAKELPARAM (pt.x, pt.y));
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (command_id, 0), MAKELPARAM (pt.x, pt.y));
}

DestroyMenu (hmenu);
Expand Down Expand Up @@ -536,7 +536,7 @@ INT_PTR CALLBACK RegionProc (
case WM_KEYDOWN:
{
if (wparam == VK_ESCAPE)
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_CANCEL, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDM_REGION_CANCEL, 0), 0);

break;
}
Expand Down Expand Up @@ -776,7 +776,7 @@ INT_PTR CALLBACK TimerProc (

length = (INT)(INT_PTR)_r_str_getlength (text);

DrawTextEx (hdc_buffered, text, length, &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX, NULL);
DrawTextExW (hdc_buffered, text, length, &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX, NULL);

EndBufferedPaint (hdpaint, TRUE);
}
Expand Down
48 changes: 0 additions & 48 deletions src/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,6 @@

#pragma once

#define DUMMY_CLASS_DLG L"DummyDlg"

typedef struct _MONITOR_CONTEXT
{
HWND hwnd;
HCURSOR hcursor;
RECT rect;

union
{
struct
{
HDC hcapture;
HDC hcapture_mask;
HBITMAP hbitmap;
HBITMAP hbitmap_mask;
HPEN hpen;
HPEN hpen_draw;
HDC hdc;

POINT pt_start;
POINT pt_end;

BOOLEAN is_drawing;
} region;

struct
{
PSHOT_INFO shot_info;
HFONT hfont;
volatile LONG timer_value;
} timer;
};
} MONITOR_CONTEXT, *PMONITOR_CONTEXT;

typedef struct _TIMER_CONTEXT
{
HWND hwnd;
LONG timer_value;
PSHOT_INFO shot_info;
} TIMER_CONTEXT, *PTIMER_CONTEXT;

typedef struct _DUMMY_CONTEXT
{
HWND hwnd;
RECT rect;
} DUMMY_CONTEXT, *PDUMMY_CONTEXT;

BOOL CALLBACK enum_monitor_timer_callback (
_In_ HMONITOR hmonitor,
_In_ HDC hdc,
Expand Down
11 changes: 5 additions & 6 deletions src/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ VOID _app_playsound ()
if (!_r_config_getboolean (L"IsPlaySound", TRUE))
return;

PlaySound (MAKEINTRESOURCE (IDW_MAIN), _r_sys_getimagebase (), SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME | SND_SENTRY | SND_RESOURCE);
PlaySoundW (MAKEINTRESOURCE (IDW_MAIN), _r_sys_getimagebase (), SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME | SND_SENTRY | SND_RESOURCE);
}

LONG _app_getimageformat_id ()
Expand Down Expand Up @@ -224,20 +224,19 @@ PR_STRING _app_uniquefilename (
WCHAR time_format[MAX_PATH];
SYSTEMTIME st;
PR_STRING name_prefix;
PR_STRING string;
PR_STRING string = NULL;
PIMAGE_FORMAT format;

format = _app_getimageformat_data ();

name_prefix = _r_config_getstring (L"FilenamePrefix", FILE_FORMAT_NAME_PREFIX);
string = NULL;

if (name_type == NAME_DATE)
{
GetLocalTime (&st);

if (GetDateFormat (LOCALE_SYSTEM_DEFAULT, 0, &st, FILE_FORMAT_DATE_FORMAT_1, date_format, RTL_NUMBER_OF (date_format)) &&
GetTimeFormat (LOCALE_SYSTEM_DEFAULT, 0, &st, FILE_FORMAT_DATE_FORMAT_2, time_format, RTL_NUMBER_OF (time_format)))
if (GetDateFormatW (LOCALE_SYSTEM_DEFAULT, 0, &st, FILE_FORMAT_DATE_FORMAT_1, date_format, RTL_NUMBER_OF (date_format)) &&
GetTimeFormatW (LOCALE_SYSTEM_DEFAULT, 0, &st, FILE_FORMAT_DATE_FORMAT_2, time_format, RTL_NUMBER_OF (time_format)))
{
_r_obj_movereference (&string, _r_format_string (
L"%s\\%s%s-%s.%s",
Expand Down Expand Up @@ -506,7 +505,7 @@ VOID _app_screenshot (

hmonitor = MonitorFromPoint (pt, MONITOR_DEFAULTTONEAREST);

if (GetMonitorInfo (hmonitor, &monitor_info))
if (GetMonitorInfoW (hmonitor, &monitor_info))
{
_r_wnd_recttorectangle (&shot_info->rectangle, &monitor_info.rcMonitor);

Expand Down
75 changes: 43 additions & 32 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ VOID _app_key2string (
}
else
{
scan_code = MapVirtualKey (vk_code, MAPVK_VK_TO_VSC);
scan_code = MapVirtualKeyW (vk_code, MAPVK_VK_TO_VSC);

GetKeyNameText ((scan_code << 16), key_name, RTL_NUMBER_OF (key_name));
GetKeyNameTextW ((scan_code << 16), key_name, RTL_NUMBER_OF (key_name));
}

_r_str_append (buffer, length, key_name);
Expand All @@ -62,10 +62,10 @@ BOOLEAN _app_hotkeyinit (
UINT hk_monitor;
UINT hk_window;
UINT hk_region;
BOOLEAN is_nofullscreen;
BOOLEAN is_nomonitor;
BOOLEAN is_nowindow;
BOOLEAN is_noregion;
BOOLEAN is_nofullscreen = FALSE;
BOOLEAN is_nomonitor = FALSE;
BOOLEAN is_nowindow = FALSE;
BOOLEAN is_noregion = FALSE;

UnregisterHotKey (hwnd, HOTKEY_ID_FULLSCREEN);
UnregisterHotKey (hwnd, HOTKEY_ID_MONITOR);
Expand All @@ -77,11 +77,6 @@ BOOLEAN _app_hotkeyinit (
hk_window = _r_config_getlong (L"HotkeyWindow", HOTKEY_WINDOW);
hk_region = _r_config_getlong (L"HotkeyRegion", HOTKEY_REGION);

is_nofullscreen = FALSE;
is_nomonitor = FALSE;
is_nowindow = FALSE;
is_noregion = FALSE;

if (_r_config_getboolean (L"HotkeyFullscreenEnabled", FALSE))
{
if (hk_fullscreen)
Expand Down Expand Up @@ -358,10 +353,10 @@ INT_PTR CALLBACK SettingsProc (
if (_r_combobox_getcurrentitem (hwnd, IDC_REGION_CB) == CB_ERR)
_r_combobox_setcurrentitem (hwnd, IDC_REGION_CB, 0);

PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDC_FULLSCREEN_CB, CBN_SELCHANGE), 0);
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDC_MONITOR_CB, CBN_SELCHANGE), 0);
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDC_WINDOW_CB, CBN_SELCHANGE), 0);
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDC_REGION_CB, CBN_SELCHANGE), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDC_FULLSCREEN_CB, CBN_SELCHANGE), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDC_MONITOR_CB, CBN_SELCHANGE), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDC_WINDOW_CB, CBN_SELCHANGE), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDC_REGION_CB, CBN_SELCHANGE), 0);

break;
}
Expand Down Expand Up @@ -474,7 +469,7 @@ INT_PTR CALLBACK SettingsProc (

if (!_app_hotkeyinit (_r_app_gethwnd (), hwnd))
{
SetWindowLongPtr (hwnd, DWLP_MSGRESULT, -1);
SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, -1);

return (INT_PTR)-1;
}
Expand Down Expand Up @@ -536,8 +531,23 @@ VOID _app_initdropdownmenu (

string = _r_config_getstring (L"FilenamePrefix", FILE_FORMAT_NAME_PREFIX);

_r_menu_setitemtextformat (hmenu, IDM_FILENAME_INDEX, FALSE, FILE_FORMAT_NAME_FORMAT L".%s", _r_obj_getstringordefault (string, FILE_FORMAT_NAME_PREFIX), START_IDX, format->ext);
_r_menu_setitemtextformat (hmenu, IDM_FILENAME_DATE, FALSE, L"%s" FILE_FORMAT_DATE_FORMAT_1 L"-" FILE_FORMAT_DATE_FORMAT_2 L".%s", _r_obj_getstringordefault (string, FILE_FORMAT_NAME_PREFIX), format->ext);
_r_menu_setitemtextformat (
hmenu,
IDM_FILENAME_INDEX,
FALSE,
FILE_FORMAT_NAME_FORMAT L".%s",
_r_obj_getstringordefault (string, FILE_FORMAT_NAME_PREFIX),
START_IDX, format->ext
);

_r_menu_setitemtextformat (
hmenu,
IDM_FILENAME_DATE,
FALSE,
L"%s" FILE_FORMAT_DATE_FORMAT_1 L"-" FILE_FORMAT_DATE_FORMAT_2 L".%s",
_r_obj_getstringordefault (string, FILE_FORMAT_NAME_PREFIX),
format->ext
);

if (string)
_r_obj_dereference (string);
Expand Down Expand Up @@ -646,9 +656,9 @@ VOID _app_initialize ()
wcex.lpszClassName = DUMMY_CLASS_DLG;
wcex.lpfnWndProc = &DummyProc;
wcex.hbrBackground = GetSysColorBrush (COLOR_WINDOW);
wcex.hCursor = LoadCursor (NULL, IDC_ARROW);
wcex.hCursor = LoadCursorW (NULL, IDC_ARROW);

RegisterClassEx (&wcex);
RegisterClassExW (&wcex);
}

INT_PTR CALLBACK DlgProc (
Expand Down Expand Up @@ -827,7 +837,7 @@ INT_PTR CALLBACK DlgProc (
SAFE_DELETE_HANDLE (config.hregion_mutex);
SAFE_DELETE_HANDLE (config.hshot_evt);

UnregisterClass (DUMMY_CLASS_DLG, _r_sys_getimagebase ());
UnregisterClassW (DUMMY_CLASS_DLG, _r_sys_getimagebase ());

_r_tray_destroy (hwnd, &GUID_TrayIcon);

Expand Down Expand Up @@ -861,7 +871,7 @@ INT_PTR CALLBACK DlgProc (
break;
}

PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (command_id, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (command_id, 0), 0);

break;
}
Expand All @@ -880,13 +890,13 @@ INT_PTR CALLBACK DlgProc (

case WM_LBUTTONUP:
{
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDM_TRAY_SHOW, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDM_TRAY_SHOW, 0), 0);
break;
}

case WM_MBUTTONUP:
{
PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDM_EXPLORE, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDM_EXPLORE, 0), 0);
break;
}

Expand All @@ -904,7 +914,7 @@ INT_PTR CALLBACK DlgProc (

SetForegroundWindow (hwnd); // don't touch

hmenu = LoadMenu (NULL, MAKEINTRESOURCE (IDM_TRAY));
hmenu = LoadMenuW (NULL, MAKEINTRESOURCE (IDM_TRAY));

if (hmenu)
{
Expand Down Expand Up @@ -957,7 +967,7 @@ INT_PTR CALLBACK DlgProc (
_r_menu_setitemtext (hsubmenu, IDM_TRAY_EXIT, FALSE, _r_locale_getstring (IDS_EXIT));

// initialize settings submenu
hmenu_settings = LoadMenu (NULL, MAKEINTRESOURCE (IDM_SETTINGS));
hmenu_settings = LoadMenuW (NULL, MAKEINTRESOURCE (IDM_SETTINGS));

if (hmenu_settings)
{
Expand Down Expand Up @@ -990,22 +1000,24 @@ INT_PTR CALLBACK DlgProc (
case WM_NOTIFY:
{
LPNMHDR nmlp;
LPNMBCDROPDOWN lpdropdown;

nmlp = (LPNMHDR)lparam;

switch (nmlp->code)
{
case BCN_DROPDOWN:
{
LPNMBCDROPDOWN lpdropdown;

lpdropdown = (LPNMBCDROPDOWN)lparam;

if (lpdropdown->hdr.idFrom != IDC_SETTINGS)
break;

PostMessage (hwnd, WM_COMMAND, MAKEWPARAM (IDC_SETTINGS, 0), 0);
PostMessageW (hwnd, WM_COMMAND, MAKEWPARAM (IDC_SETTINGS, 0), 0);

SetWindowLongPtrW (hwnd, DWLP_MSGRESULT, TRUE);

SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE);
return TRUE;

break;
Expand Down Expand Up @@ -1036,8 +1048,7 @@ INT_PTR CALLBACK DlgProc (

return FALSE;
}
else if ((ctrl_id >= IDX_DELAY &&
ctrl_id <= IDX_DELAY + RTL_NUMBER_OF (timer_array)))
else if ((ctrl_id >= IDX_DELAY && ctrl_id <= IDX_DELAY + RTL_NUMBER_OF (timer_array)))
{
LONG index;

Expand Down Expand Up @@ -1095,7 +1106,7 @@ INT_PTR CALLBACK DlgProc (
if (!GetWindowRect (hbutton, &rect))
break;

hmenu = LoadMenu (NULL, MAKEINTRESOURCE (IDM_SETTINGS));
hmenu = LoadMenuW (NULL, MAKEINTRESOURCE (IDM_SETTINGS));

if (!hmenu)
break;
Expand Down
Loading

0 comments on commit 2c9bfd8

Please sign in to comment.