8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 21:23:03 +01:00

CORE-1595 and CORE-2784.

This commit is contained in:
robocop 2009-12-03 10:23:58 +00:00
parent e549a772f9
commit b68e858e76

View File

@ -75,7 +75,8 @@ static bool parse_args(LPCSTR);
THREAD_ENTRY_DECLARE start_and_watch_server(THREAD_ENTRY_PARAM);
THREAD_ENTRY_DECLARE swap_icons(THREAD_ENTRY_PARAM);
void write_log(int, const char*);
static void addTaskBarIcons(HINSTANCE hInstance, HWND hWnd, BOOL& bInTaskBar);
static void write_log(int, const char*);
HWND DisplayPropSheet(HWND, HINSTANCE);
LRESULT CALLBACK GeneralPage(HWND, UINT, WPARAM, LPARAM);
@ -253,9 +254,7 @@ static THREAD_ENTRY_DECLARE WINDOW_main(THREAD_ENTRY_PARAM)
// If we're a service, don't create a window
if (service_flag)
{
gds__thread_start(start_and_watch_server, 0, THREAD_medium, 0, &thread_id);
if (thread_id == (DWORD) -1)
if (gds__thread_start(start_and_watch_server, 0, THREAD_medium, 0, &thread_id))
{
// error starting server thread
char szMsgString[256];
@ -272,7 +271,7 @@ static THREAD_ENTRY_DECLARE WINDOW_main(THREAD_ENTRY_PARAM)
{
char szMsgString[256];
LoadString(hInstance_gbl, IDS_ALREADYSTARTED, szMsgString, 256);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK | MB_ICONHAND);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK | MB_ICONSTOP);
gds__log(szMsgString);
return 0;
}
@ -294,7 +293,7 @@ static THREAD_ENTRY_DECLARE WINDOW_main(THREAD_ENTRY_PARAM)
{
char szMsgString[256];
LoadString(hInstance_gbl, IDS_REGERROR, szMsgString, 256);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK | MB_ICONSTOP);
return 0;
}
@ -312,14 +311,12 @@ static THREAD_ENTRY_DECLARE WINDOW_main(THREAD_ENTRY_PARAM)
hWndGbl = hWnd;
// begin a new thread for calling the start_and_watch_server
gds__thread_start(start_and_watch_server, 0, THREAD_medium, 0, &thread_id);
if (thread_id == (DWORD) -1)
if (gds__thread_start(start_and_watch_server, 0, THREAD_medium, 0, &thread_id))
{
// error starting server thread
char szMsgString[256];
LoadString(hInstance_gbl, IDS_CANT_START_THREAD, szMsgString, 256);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK);
MessageBox(NULL, szMsgString, GUARDIAN_APP_LABEL, MB_OK | MB_ICONSTOP);
gds__log(szMsgString);
DestroyWindow(hWnd);
return 0;
@ -372,6 +369,7 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
static bool bStartup = false;
static HINSTANCE hInstance = NULL;
static unsigned long thread_id;
static UINT s_uTaskbarRestart;
hInstance = (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
switch (message)
@ -450,7 +448,15 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
case WM_SWITCHICONS:
nRestarts++;
gds__thread_start(swap_icons, hWnd, THREAD_medium, 0, &thread_id);
{ // scope
DWORD thr_exit = 0;
if (thread_id == 0 ||
!GetExitCodeThread(reinterpret_cast<HANDLE>(thread_id), &thr_exit) ||
thr_exit != STILL_ACTIVE)
{
gds__thread_start(swap_icons, hWnd, THREAD_medium, 0, &thread_id);
}
} // scope
break;
case ON_NOTIFYICON:
@ -475,42 +481,8 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
break;
case WM_CREATE:
if (!service_flag)
{
HICON hIcon = (HICON) LoadImage(hInstance, MAKEINTRESOURCE(IDI_IBGUARD),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = IDI_IBGUARD;
nid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;
nid.uCallbackMessage = ON_NOTIFYICON;
nid.hIcon = hIcon;
lstrcpy(nid.szTip, GUARDIAN_APP_LABEL);
// This will be true if we are using the explorer interface
bInTaskBar = Shell_NotifyIcon(NIM_ADD, &nid);
if (hIcon)
DestroyIcon(hIcon);
// This will be true if we are using the program manager interface
if (!bInTaskBar)
{
char szMsgString[256];
HMENU hSysMenu = GetSystemMenu(hWnd, FALSE);
DeleteMenu(hSysMenu, SC_RESTORE, MF_BYCOMMAND);
AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
LoadString(hInstance, IDS_SVRPROPERTIES, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_SVRPROPERTIES, szMsgString);
LoadString(hInstance, IDS_SHUTDOWN, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_SHUTDOWN, szMsgString);
LoadString(hInstance, IDS_PROPERTIES, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_PROPERTIES, szMsgString);
DestroyMenu(hSysMenu);
}
}
s_uTaskbarRestart = RegisterWindowMessage("TaskbarCreated");
addTaskBarIcons(hInstance, hWnd, bInTaskBar);
break;
case WM_QUERYOPEN:
@ -520,6 +492,7 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
case WM_SYSCOMMAND:
if (!bInTaskBar)
{
switch (wParam)
{
case SC_RESTORE:
@ -546,6 +519,7 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
}
return TRUE;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_DESTROY:
@ -563,8 +537,11 @@ static LRESULT CALLBACK WindowFunc(HWND hWnd, UINT message, WPARAM wParam, LPARA
break;
default:
if(message == s_uTaskbarRestart)
addTaskBarIcons(hInstance, hWnd, bInTaskBar);
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
@ -718,7 +695,7 @@ THREAD_ENTRY_DECLARE start_and_watch_server(THREAD_ENTRY_PARAM)
}
else
{
MessageBox(NULL, out_buf, NULL, MB_OK);
MessageBox(NULL, out_buf, NULL, MB_OK | MB_ICONSTOP);
PostMessage(hWndGbl, WM_CLOSE, 0, 0);
}
return 0;
@ -751,7 +728,8 @@ THREAD_ENTRY_DECLARE start_and_watch_server(THREAD_ENTRY_PARAM)
}
else
{
while (WaitForSingleObject(procHandle, INFINITE) == WAIT_FAILED);
while (WaitForSingleObject(procHandle, INFINITE) == WAIT_FAILED)
;
GetExitCodeProcess(procHandle, &exit_status);
CloseHandle(procHandle);
}
@ -987,7 +965,7 @@ LRESULT CALLBACK GeneralPage(HWND hDlg, UINT unMsg, WPARAM /*wParam*/, LPARAM lP
}
THREAD_ENTRY_DECLARE swap_icons(THREAD_ENTRY_PARAM param)
THREAD_ENTRY_DECLARE swap_icons(THREAD_ENTRY_PARAM param)
{
/******************************************************************************
*
@ -1046,7 +1024,48 @@ THREAD_ENTRY_DECLARE swap_icons(THREAD_ENTRY_PARAM param)
}
void write_log(int log_action, const char* buff)
static void addTaskBarIcons(HINSTANCE hInstance, HWND hWnd, BOOL& bInTaskBar)
{
if (!service_flag)
{
HICON hIcon = (HICON) LoadImage(hInstance, MAKEINTRESOURCE(IDI_IBGUARD),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = IDI_IBGUARD;
nid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;
nid.uCallbackMessage = ON_NOTIFYICON;
nid.hIcon = hIcon;
lstrcpy(nid.szTip, GUARDIAN_APP_LABEL);
// This will be true if we are using the explorer interface
bInTaskBar = Shell_NotifyIcon(NIM_ADD, &nid);
if (hIcon)
DestroyIcon(hIcon);
// This will be true if we are using the program manager interface
if (!bInTaskBar)
{
char szMsgString[256];
HMENU hSysMenu = GetSystemMenu(hWnd, FALSE);
DeleteMenu(hSysMenu, SC_RESTORE, MF_BYCOMMAND);
AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
LoadString(hInstance, IDS_SVRPROPERTIES, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_SVRPROPERTIES, szMsgString);
LoadString(hInstance, IDS_SHUTDOWN, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_SHUTDOWN, szMsgString);
LoadString(hInstance, IDS_PROPERTIES, szMsgString, 256);
AppendMenu(hSysMenu, MF_STRING, IDM_PROPERTIES, szMsgString);
DestroyMenu(hSysMenu);
}
}
}
static void write_log(int log_action, const char* buff)
{
/******************************************************************************
*