J
John paul coder
Guest
Hello All,
We developed a phone control application that is integrated with one UI application and one stand alone application (without any UI)
My Understanding from the code:
I got to know from the existing code is that MessageLoop for GetMessage is not required when phone control application is running with UI application. Because UI application has it's windows message loop running at the backend. And we are calling CreateInvisibleWindow() function.
And when we are running stand alone application (without windows UI), we are not getting messages from PHONE and no windows message loop running at the backend So we are using MessageLoop for GetMessage by calling CreateWindowAndMessageLoop.
Someone please clarify the below questions:
How CreateInvisibleWindow() works without MessageLoop for GetMessage?
If the UI application's messaging thread pumps the messages, why again to use "CreateInvisibleWindow" function?
Below is the code snippet:
CSoftphoneImpl::CSoftphoneImpl(ISFEventListener *f_hSFEventListener,string f_StrSFID, bool f_nStartedWithUI)
{
m_hEventListener = f_hSFEventListener;
m_nStartedWithUI = f_nStartedWithUI;
m_hLogManager = m_hEventListener->getLogger();
if(m_nStartedWithUI)
{
CreateInvisibleWindow();
}
else
{
m_nEventThread = std::thread(&CSoftphoneImpl::CreateWindowAndMessageLoop, this);
}
m_hWndSoftphoneHandler = 0;
m_hInstance = GetModuleHandle(0);
m_strSoftPhoneName = f_StrSFID;
m_boPHONEConnected = false;
m_hCallObj = nullptr;
m_eSoftphoneState = Softphone_IDLE_STATE;
m_boOnHookEvntRecvd = false;
m_boHookSwitchEvntRecvd = false;
m_boDeviceOnHookOff = false;
m_boSpeakerOn = false;
m_boRedialNotSupported = false;
m_boIncomingWhileActive = false;
m_boISMultipleHSSupported = false;
//connect to the Softphone Handler
connect();
}
void WINAPI CSoftphoneImpl::CreateInvisibleWindow()
{
HINSTANCE hInst = m_hInstance;
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = StaticWndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"PHONEImplInvisWinClsName";
wc.hIcon = NULL;
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_HAND);
RegisterClassEx(&wc);
m_hInvisWinHandle = CreateWindowEx(NULL, L"PHONEImplInvisWinClsName",
L"SecomAppInvisibleWindow", NULL/*WS_POPUP*/, CW_USEDEFAULT,
CW_USEDEFAULT, 800, 600, HWND_MESSAGE, NULL, hInst, NULL);
ShowWindow(m_hInvisWinHandle, SW_HIDE);
UpdateWindow(m_hInvisWinHandle);
return;
}
LRESULT CALLBACK CSoftphoneImpl::StaticWndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
GetWindowLong(hWnd, GWLP_USERDATA);
return ms_hActiveInstance->WndProc(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK CSoftphoneImpl::WndProc(HWND f_hwnd, UINT f_mMsg, WPARAM f_wParam, LPARAM f_lParam)
{
switch (f_mMsg)
{
case PHONE_SECOM_HID_MUTE_OFF:
{
onMuteMsgRecvd( false );
break;
}
case PHONE_SECOM_HID_MUTE_ON:
{
onMuteMsgRecvd( true );
break;
}
}
bool CSoftphoneImpl::connect()
{
Sleep(200);
m_hWndSoftphoneAdapter = m_hInvisWinHandle;
m_hWndSoftphoneHandler = ::FindWindow( nullptr, HID_INVISIBLE_WINDOW_NAME);
DWORD WINAPI CSoftphoneImpl::CreateWindowAndMessageLoop(LPVOID)
{
HINSTANCE hInst = m_hInstance;
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = StaticWndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"PHONEImplInvisWinClsName";
wc.hIcon = NULL;
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_HAND);
RegisterClassEx(&wc);
m_hInvisWinHandle = CreateWindowEx(NULL, L"PHONEImplInvisWinClsName",
L"SecomAppInvisibleWindow", NULL/*WS_POPUP*/, CW_USEDEFAULT,
CW_USEDEFAULT, 800, 600, HWND_MESSAGE, NULL, hInst, NULL);
ShowWindow(m_hInvisWinHandle, SW_HIDE);
UpdateWindow(m_hInvisWinHandle);
while (GetMessage(&msg, m_hInvisWinHandle, 0, 0) && m_boAlive)
{
Sleep(500);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Thanks in advance.
Continue reading...
We developed a phone control application that is integrated with one UI application and one stand alone application (without any UI)
My Understanding from the code:
I got to know from the existing code is that MessageLoop for GetMessage is not required when phone control application is running with UI application. Because UI application has it's windows message loop running at the backend. And we are calling CreateInvisibleWindow() function.
And when we are running stand alone application (without windows UI), we are not getting messages from PHONE and no windows message loop running at the backend So we are using MessageLoop for GetMessage by calling CreateWindowAndMessageLoop.
Someone please clarify the below questions:
How CreateInvisibleWindow() works without MessageLoop for GetMessage?
If the UI application's messaging thread pumps the messages, why again to use "CreateInvisibleWindow" function?
Below is the code snippet:
CSoftphoneImpl::CSoftphoneImpl(ISFEventListener *f_hSFEventListener,string f_StrSFID, bool f_nStartedWithUI)
{
m_hEventListener = f_hSFEventListener;
m_nStartedWithUI = f_nStartedWithUI;
m_hLogManager = m_hEventListener->getLogger();
if(m_nStartedWithUI)
{
CreateInvisibleWindow();
}
else
{
m_nEventThread = std::thread(&CSoftphoneImpl::CreateWindowAndMessageLoop, this);
}
m_hWndSoftphoneHandler = 0;
m_hInstance = GetModuleHandle(0);
m_strSoftPhoneName = f_StrSFID;
m_boPHONEConnected = false;
m_hCallObj = nullptr;
m_eSoftphoneState = Softphone_IDLE_STATE;
m_boOnHookEvntRecvd = false;
m_boHookSwitchEvntRecvd = false;
m_boDeviceOnHookOff = false;
m_boSpeakerOn = false;
m_boRedialNotSupported = false;
m_boIncomingWhileActive = false;
m_boISMultipleHSSupported = false;
//connect to the Softphone Handler
connect();
}
void WINAPI CSoftphoneImpl::CreateInvisibleWindow()
{
HINSTANCE hInst = m_hInstance;
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = StaticWndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"PHONEImplInvisWinClsName";
wc.hIcon = NULL;
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_HAND);
RegisterClassEx(&wc);
m_hInvisWinHandle = CreateWindowEx(NULL, L"PHONEImplInvisWinClsName",
L"SecomAppInvisibleWindow", NULL/*WS_POPUP*/, CW_USEDEFAULT,
CW_USEDEFAULT, 800, 600, HWND_MESSAGE, NULL, hInst, NULL);
ShowWindow(m_hInvisWinHandle, SW_HIDE);
UpdateWindow(m_hInvisWinHandle);
return;
}
LRESULT CALLBACK CSoftphoneImpl::StaticWndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
GetWindowLong(hWnd, GWLP_USERDATA);
return ms_hActiveInstance->WndProc(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK CSoftphoneImpl::WndProc(HWND f_hwnd, UINT f_mMsg, WPARAM f_wParam, LPARAM f_lParam)
{
switch (f_mMsg)
{
case PHONE_SECOM_HID_MUTE_OFF:
{
onMuteMsgRecvd( false );
break;
}
case PHONE_SECOM_HID_MUTE_ON:
{
onMuteMsgRecvd( true );
break;
}
}
bool CSoftphoneImpl::connect()
{
Sleep(200);
m_hWndSoftphoneAdapter = m_hInvisWinHandle;
m_hWndSoftphoneHandler = ::FindWindow( nullptr, HID_INVISIBLE_WINDOW_NAME);
DWORD WINAPI CSoftphoneImpl::CreateWindowAndMessageLoop(LPVOID)
{
HINSTANCE hInst = m_hInstance;
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = StaticWndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"PHONEImplInvisWinClsName";
wc.hIcon = NULL;
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_HAND);
RegisterClassEx(&wc);
m_hInvisWinHandle = CreateWindowEx(NULL, L"PHONEImplInvisWinClsName",
L"SecomAppInvisibleWindow", NULL/*WS_POPUP*/, CW_USEDEFAULT,
CW_USEDEFAULT, 800, 600, HWND_MESSAGE, NULL, hInst, NULL);
ShowWindow(m_hInvisWinHandle, SW_HIDE);
UpdateWindow(m_hInvisWinHandle);
while (GetMessage(&msg, m_hInvisWinHandle, 0, 0) && m_boAlive)
{
Sleep(500);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Thanks in advance.
Continue reading...