You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
3.8 KiB
186 lines
3.8 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 19/04/2000
|
|
// Last modification: 08/10/2003
|
|
// Project Intruder Position Indicator
|
|
// SUBSYSTEM: Dialog
|
|
// FILE: Dialog.cpp
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of class CDialog
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
|
|
#include "Dialog.h"
|
|
|
|
CDialog::CDialog(LPCTSTR lpTemplateName )
|
|
{
|
|
m_hWnd = NULL;
|
|
m_hParent = NULL;
|
|
m_hThread = NULL;
|
|
m_bModal = NULL;
|
|
m_dwThreadId = 0UL;
|
|
m_hInstance = NULL;
|
|
|
|
m_pTemplateName = lpTemplateName;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDialog::CDialog" );
|
|
}
|
|
|
|
CDialog::~CDialog()
|
|
{
|
|
Destroy();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDialog::~CDialog" );
|
|
}
|
|
|
|
BOOL CDialog::DoModal(HWND hParent, BOOL bThread)
|
|
{
|
|
if(m_hThread)
|
|
{
|
|
if(::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
|
|
{
|
|
::CloseHandle(m_hThread);
|
|
m_hThread = NULL;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
m_hInstance = (HINSTANCE)::GetWindowLong(m_hParent = hParent, GWL_HINSTANCE);
|
|
|
|
if(bThread)
|
|
{
|
|
m_bModal = TRUE;
|
|
m_hParent = hParent;
|
|
|
|
m_hThread = ::CreateThread(NULL, 0UL, ThreadProcDialog, (LPVOID)this, 0UL, &m_dwThreadId);
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
m_bModal = TRUE;
|
|
m_hParent = hParent;
|
|
return ::DialogBoxParam(m_hInstance, m_pTemplateName, m_hParent,
|
|
DialogProcDialog, (LPARAM)this );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CDialog::Create(HWND hParent, BOOL bThread)
|
|
{
|
|
if(m_hThread)
|
|
{
|
|
if(::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
|
|
{
|
|
::CloseHandle(m_hThread);
|
|
|
|
m_hThread = NULL;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
m_hInstance = (HINSTANCE)::GetWindowLong(m_hParent = hParent, GWL_HINSTANCE);
|
|
|
|
if(bThread )
|
|
{
|
|
m_bModal = FALSE;
|
|
m_hParent = hParent;
|
|
m_hThread = ::CreateThread(NULL, 0UL, ThreadProcDialog, (LPVOID)this, 0UL, &m_dwThreadId);
|
|
}
|
|
else
|
|
if(m_hWnd = ::CreateDialogParam( m_hInstance, m_pTemplateName,
|
|
m_hParent, DialogProcDialog, (LPARAM)this ) )
|
|
{
|
|
::ShowWindow(m_hWnd, SW_SHOW);
|
|
::UpdateWindow(m_hWnd);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CDialog::Destroy()
|
|
{
|
|
if(m_hWnd)
|
|
{
|
|
if(m_bModal)
|
|
::EndDialog(m_hWnd, 0);
|
|
else
|
|
::DestroyWindow(m_hWnd);
|
|
|
|
m_hWnd = NULL;
|
|
}
|
|
|
|
if(m_hThread)
|
|
{
|
|
if(::GetCurrentThreadId() == m_dwThreadId)
|
|
::PostQuitMessage(0);
|
|
else
|
|
{
|
|
::PostThreadMessage(m_dwThreadId, WM_QUIT, 0, 0);
|
|
::WaitForSingleObject(m_hThread, INFINITE);
|
|
::CloseHandle(m_hThread);
|
|
|
|
m_hThread = NULL;
|
|
m_dwThreadId = 0UL;
|
|
m_hInstance = NULL;
|
|
m_hParent = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
DWORD CDialog::ThreadProc()
|
|
{
|
|
if(m_bModal )
|
|
{
|
|
return ::DialogBoxParam( m_hInstance, m_pTemplateName, m_hParent,
|
|
DialogProcDialog, (LPARAM)this );
|
|
}
|
|
else
|
|
{
|
|
if(m_hWnd = ::CreateDialogParam( m_hInstance, m_pTemplateName,
|
|
m_hParent, DialogProcDialog, (LPARAM)this))
|
|
{
|
|
::ShowWindow(m_hWnd, SW_SHOW);
|
|
::UpdateWindow(m_hWnd);
|
|
|
|
MSG msg;
|
|
|
|
while(::GetMessage(&msg, 0, 0, 0))
|
|
{
|
|
::TranslateMessage(&msg);
|
|
::DispatchMessage(&msg);
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
static BOOL CALLBACK DialogProcDialog(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if(uMsg == WM_INITDIALOG)
|
|
{
|
|
CDialog *self = (CDialog*)lParam;
|
|
|
|
self->m_hWnd = hWnd;
|
|
::SetWindowLong(hWnd, GWL_USERDATA, (DWORD)lParam);
|
|
|
|
return self->DialogProc(hWnd, uMsg, wParam, lParam);;
|
|
}
|
|
|
|
CDialog *self = (CDialog*)::GetWindowLong(hWnd, GWL_USERDATA);
|
|
|
|
if(self)
|
|
return self->DialogProc(hWnd, uMsg, wParam, lParam);
|
|
else
|
|
return FALSE;
|
|
}
|