When Skype ICallChannelManagerEvents gets fired - c++

I am working on App to App communication using skype. My Requirement is When one skype user place Call/Video Call I wanted to use application stream to send message from One App Plugged in Skype to other App plugged in Skype.
In Separate Sample App I am able to send and receive message using Application Stream from One App to Other App but I wanted to Activate Application Stream When User place call.
Skype4COM expose these three event for ICallChannelManager
ICallChannelManagerEvents::Channels
ICallChannelManagerEvents::Created
ICallChannelManagerEvents::Message
I have registered these three events
hr = m_pCallChannelMgr.CreateInstance(__uuidof(CallChannelManager));
hr = SinkSkypeCallChannelMgrEvents::DispEventAdvise(m_pCallChannelMgr);
hr = m_pCallChannelMgr->CreateApplication(L"");
VARIANT_BOOL flag = m_pCallChannelMgr->GetCreated();
while(true )
{
if ( VARIANT_TRUE == flag) break;
flag = m_pCallChannelMgr->GetCreated();
Sleep(1000);
}
hr = m_pCallChannelMgr->Connect(m_Skypeptr);
when m_pCallChannelMgr->CreateApplication(); is called it fires ICallChannelManagerEvents::Created event.
I am Not sure about,When Other when two event ICallChannelManagerEvents::Channels and ICallChannelManagerEvents::Message gets fired.
Plz help me on this.

Problem Resolved when there is already a call in process and your plugin starts to hook in to Skype ICallChannelManagerEvents gets fired.

Related

How to detect if any app goes fullscreen or exiting fullscreen?

I need to disable notifications at my app when there is another app fullscreen like powerpoint or VLC to do not bother a user.
For now, I get to this code, but it always returns true. Whether there is some app fullscreen or not. I am not sure whether this should work only for app bars or also taskbar.
HWND hWnd;
hWnd = FindWindow(L"Shell_TrayWnd", nullptr);
if( hWnd )
{
APPBARDATA apd;
apd.cbSize = sizeof(APPBARDATA);
apd.hWnd = hWnd;
bool uState = bool(SHAppBarMessage(ABN_FULLSCREENAPP , &apd));
if(uState)
qDebug()<<"fullscreen";
else
qDebug()<<"not fullscreen";
}
ABN_FULLSCREENAPP is not a message you send to the shell, it's a message the shell sends to you when an application enters or leaves full screen mode. The message is sent to the owner of an app bar created with ABM_NEW.
Documentation is here.
My reading of the documentation is that you have to create an app bar to receive this message but you may be able to set it to zero height or width with ABM_SETPOS if you want to hide it.

XInputGetState hangs

I'm trying to use XInput API for my game engine (I'm using DirectX11 and C++). I just want to test if a controller is found so I #included and call XInputGetState but I get a strange behavior:
XINPUT_STATE state;
ZeroMemory(&state, sizeof(XINPUT_STATE));
DWORD result;
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
{
result = XInputGetState(i, &state);
if (result == ERROR_SUCCESS)
ErrorBox(L"found controller on port ");
}
if I connect a controller the program hangs and freezes, while if I disconnect the controller the game launches. If I step into the code with the debugger the result is that the controller is found and the message box is displayed.
Why?
EDIT the problem seems to be in the call to ErrorBox: this function just displays a Message Box using Win32 API.
There is a performance hit when you check for a controller that wasn't attached last time you called it because it has to enumerate device, open driver connects, etc. Therefore, you are recommended to round-robin calls to check for new controllers. If you get ERROR_DEVICE_NOT_CONNECTED back, you shouldn't call XInputGetState again for that slot for a little while. For an example of this, see GamePad class in the Directx Tool Ki and the ThrottleRetry function.
In other words, the loop you wrote before is not a good idea to call every frame unless there are XUSER_MAX_COUNT controllers actually connected.

How to activate already opened application when user tries to run it for the second time?

I am using Mutex to limit my application to only one instance. This is the code:
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MyTestApp");
if(hMutex == NULL)
ShowMessage(GetLastError());
else
if(GetLastError() == ERROR_ALREADY_EXISTS) {
ShowMessage("Application already running!");
// activate already running instance ?!
return -1;
}
I would like to expand it to activate the already running instance. How to do it? Thanks.
Assuming it's Win32 application:
1) Use FindWindow function with your window name and its class name you gave.
2) Use SetForegroundWindow with HWND FindWindow returned.
Once you have determined that no other instance of your application is running, overload the WndProc of your Main form handle a unique message (Like const unsigned int myMsgId = WM_USER + 100; for example) or you can use RegisterWindowMessage. When the 2nd instance of the application starts, broadcast a message with that message identifier PostMessage(NULL, myMsgId, 0, 0) before creating the main form and quit. The 1st instance of the app can react to it and bring itself to foreground using BringWindowToTop (if possible, vista and above do not allow this for obvious reasons). If bringing the app to foreground is not allowed, the status bar icon of your app will start flashing to get the attention of the user.
Sam

C++ Builder: Refresh FireMonkey Visual Component

I have a problem with C++ Builder and FireMonkey. I am creating a mobile application connected with a Datasnap Rest WebService. Some requests are a little bit long so I want to display a waiting message. Here is my code:
lbl_testConnexion->Text = "Please Wait...";
lbl_testConnexion->TextSettings->FontColor = TAlphaColorRec::Red;
this->Invalidate();
//Call to the Web Service
list<Colis>* l = WS->getListeColis("00DP0097");
lbl_testConnexion->Text = "Success!";
I tried functions Form->Invalidate() and Label->Repaint() but only the last text is displayed.
What can I do to dynamically refresh the Label in my function?
The change of the text has to be handled by the main thread which is blocked by the request. If you don't want to use a seperate thread for long requests you have to call Application->ProcessMessages().
lbl_testConnexion->Text = "Please Wait...";
lbl_testConnexion->TextSettings->FontColor = TAlphaColorRec::Red;
Application->ProcessMessages();
//Call to the Web Service
list<Colis>* l = WS->getListeColis("00DP0097");
lbl_testConnexion->Text = "Success!";
Note:
You have to be carefull with Application->ProcessMessages(). You can find many articles and discussions about this in the internet. When you work with the VCL there exists the method Update for controls of Type TWinControl which calls the function UpdateWindow of the WinAPI. Firemonkey does have a similar function, but only for Windows.
Include FMX.Platform.Win.hpp and replace Application->ProcessMessages() with UpdateWindow(Platform::Win::WindowHandleToPlatform(Handle)->Wnd)

Open URL with ShellExecute - SW_SHOWMAXIMIZED dont active window in C++

I used this function to open new tab in Chrome and active it:
ShellExecuteA(0,0,"chrome.exe","http://google.com --incognito",0,SW_SHOWMAXIMIZED);
but Chrome only open new tab but it doesnt active window.
(I call this function from global keyboard-hook of an application with no user interface, if user press specified key).
How I can fix it?
Looks like a bug in chrome.exe. I could repro with your ShellExecute call from a simple console app, if a regular (non-incognito) chrome.exe session was running and no incognito session was running. In other words, if a new incognito chrome session needed to be spawned, the regular session did not appear to correctly propagate the ShowWindow flags to the spawned incognito process. Another factor was that the activation failure also required the regular chrome session to be active before the test app ran. If any other app was active (say notepad.exe), then activation of the incognito session succeeded. The same behavior occurs with ShellExecuteEx and CreateProcess. Observing in Process Explorer (from sysinternals), it's clear that chrome.exe is forking the child process as necessary and then terminating itself. This makes it difficult to intercept an hProcess or processId in order to ultimately call SetActiveWindow.
Its not possible. You have to make Google Chrome as default browser and than try this:
(only tested on WinXP using
IE6)
first a function, that finds the default app for any File extension:**
enter code here
#include<Registry.hpp>
AnsiString GetDefaultApp(AnsiString ext)
{
TRegistry* reg = new(TRegistry);
reg->RootKey = HKEY_CURRENT_USER;
if(!reg->OpenKeyReadOnly("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\."+ext+"\\OpenWithList"))
return(NULL);
try
{
AnsiString MRUList = reg->ReadString("MRUList");
AnsiString ret = reg->ReadString(AnsiString(char(MRUList[1])));
return(ret);
}
catch(...)
{
return(NULL);
}
}
now the code to launch the default app for html files and giving
the URL as parameter:**
#include<shellapi>
void OpenURL(AnsiString URL)
{
AnsiString app = GetDefaultApp("html");
if(app == NULL)
return;
ShellExecute(NULL,"open",app.c_str(),URL.c_str(),NULL,SW_SHOWDEFAULT);
}
Now you can open a URL in a new Browser using this command:
OpenURL("http://www.AlgorithMan.de/");