mirror of https://github.com/OpenVPN/openvpn-gui
Some refactoring to help code reuse
- Move MsgToEventLog from main.c to misc.c - Move dpi_initialize from main.c to misc.c Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/529/head
parent
b2f60c239a
commit
b828e763ad
|
@ -25,6 +25,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "main.h"
|
||||
#include "misc.h"
|
||||
#include "config_parser.h"
|
||||
|
||||
static int
|
||||
|
|
58
main.c
58
main.c
|
@ -410,34 +410,6 @@ ResumeConnections()
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get dpi of the system and set the scale factor.
|
||||
* The system dpi may be different from the per monitor dpi on
|
||||
* Win 8.1 later. We set dpi awareness to system-dpi level in the
|
||||
* manifest, and let Windows automatically re-scale windows
|
||||
* if/when dpi changes dynamically.
|
||||
*/
|
||||
static void
|
||||
dpi_initialize(void)
|
||||
{
|
||||
UINT dpix = 0;
|
||||
HDC hdc = GetDC(NULL);
|
||||
|
||||
if (hdc)
|
||||
{
|
||||
dpix = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
PrintDebug(L"System DPI: dpix = %u", dpix);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintDebug(L"GetDC failed, using default dpi = 96 (error = %lu)", GetLastError());
|
||||
dpix = 96;
|
||||
}
|
||||
|
||||
DpiSetScale(&o, dpix);
|
||||
}
|
||||
|
||||
static int
|
||||
HandleCopyDataMessage(const COPYDATASTRUCT *copy_data)
|
||||
{
|
||||
|
@ -584,7 +556,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
|||
|
||||
/* Save Window Handle */
|
||||
o.hWnd = hwnd;
|
||||
dpi_initialize();
|
||||
dpi_initialize(&o);
|
||||
|
||||
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
||||
|
||||
|
@ -947,34 +919,6 @@ DWORD GetDllVersion(LPCTSTR lpszDllName)
|
|||
return dwVersion;
|
||||
}
|
||||
|
||||
void
|
||||
MsgToEventLog(WORD type, wchar_t *format, ...)
|
||||
{
|
||||
const wchar_t *msg[2];
|
||||
wchar_t buf[256];
|
||||
int size = _countof(buf);
|
||||
|
||||
if (!o.event_log)
|
||||
{
|
||||
o.event_log = RegisterEventSource(NULL, TEXT(PACKAGE_NAME));
|
||||
if (!o.event_log)
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int nchar = vswprintf(buf, size-1, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (nchar == -1) return;
|
||||
|
||||
buf[size - 1] = '\0';
|
||||
|
||||
msg[0] = TEXT(PACKAGE_NAME);
|
||||
msg[1] = buf;
|
||||
ReportEventW(o.event_log, type, 0, 0, NULL, 2, 0, msg, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ErrorExit(int exit_code, const wchar_t *msg)
|
||||
{
|
||||
|
|
3
main.h
3
main.h
|
@ -140,9 +140,6 @@ void PrintDebugMsg(TCHAR *msg);
|
|||
|
||||
DWORD GetDllVersion(LPCTSTR lpszDllName);
|
||||
|
||||
#define DPI_SCALE(x) MulDiv(x, o.dpi_scale, 100)
|
||||
void MsgToEventLog(WORD type, wchar_t *format, ...);
|
||||
|
||||
void ErrorExit(int exit_code, const wchar_t *msg);
|
||||
|
||||
#endif
|
||||
|
|
57
misc.c
57
misc.c
|
@ -912,3 +912,60 @@ ParseManagementAddress(connection_t *c)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Write a message to the event log */
|
||||
void
|
||||
MsgToEventLog(WORD type, wchar_t *format, ...)
|
||||
{
|
||||
const wchar_t *msg[2];
|
||||
wchar_t buf[256];
|
||||
int size = _countof(buf);
|
||||
|
||||
if (!o.event_log)
|
||||
{
|
||||
o.event_log = RegisterEventSource(NULL, TEXT(PACKAGE_NAME));
|
||||
if (!o.event_log)
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int nchar = vswprintf(buf, size-1, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (nchar == -1) return;
|
||||
|
||||
buf[size - 1] = '\0';
|
||||
|
||||
msg[0] = TEXT(PACKAGE_NAME);
|
||||
msg[1] = buf;
|
||||
ReportEventW(o.event_log, type, 0, 0, NULL, 2, 0, msg, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get dpi of the system and set the scale factor.
|
||||
* The system dpi may be different from the per monitor dpi on
|
||||
* Win 8.1 later. We set dpi awareness to system-dpi level in the
|
||||
* manifest, and let Windows automatically re-scale windows
|
||||
* if/when dpi changes dynamically.
|
||||
*/
|
||||
void
|
||||
dpi_initialize(options_t *options)
|
||||
{
|
||||
UINT dpix = 0;
|
||||
HDC hdc = GetDC(NULL);
|
||||
|
||||
if (hdc)
|
||||
{
|
||||
dpix = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
PrintDebug(L"System DPI: dpix = %u", dpix);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintDebug(L"GetDC failed, using default dpi = 96 (error = %lu)", GetLastError());
|
||||
dpix = 96;
|
||||
}
|
||||
|
||||
DpiSetScale(options, dpix);
|
||||
}
|
||||
|
|
17
misc.h
17
misc.h
|
@ -109,4 +109,21 @@ BOOL find_free_tcp_port(SOCKADDR_IN *addr);
|
|||
*/
|
||||
BOOL ParseManagementAddress(connection_t *c);
|
||||
|
||||
/**
|
||||
* Get dpi of the system and set the scale factor.
|
||||
* @param o : pointer to the options struct
|
||||
* On return initializes o.dpi_scale using the logical pixels
|
||||
* per inch value of the system.
|
||||
*/
|
||||
#define DPI_SCALE(x) MulDiv(x, o.dpi_scale, 100)
|
||||
void dpi_initialize(options_t *o);
|
||||
|
||||
/**
|
||||
* Write a message to the event log
|
||||
* @param type : event log type
|
||||
* @param format : message format in printf style
|
||||
* @param ... : extra args
|
||||
*/
|
||||
void MsgToEventLog(WORD type, wchar_t *format, ...);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue