0

Whenever Skype is in Default View, the TConversationWindow's become children of the tSkMainForm Window.

I am having problems finding out which TConversationWindow is active - however it's not like an MDI interface - only one TConversationWindow is visible, like if it was a Tab/Page.

When I do GetForegroundWindow, Skype's MainForm handle is returned (tSkMainForm). Is there any way that I can get the foreground TConversationWindow within Skype?

This question of mine has screenshots of Skype's Default View, if you need it. :)

EDIT: Here is a screenshot of the Winspector Hierachy:

enter image description here

EDIT2: I tried going thru the windows like this:

procedure TForm1.Button1Click(Sender: TObject);
  function GetClassName(Handle: HWND): String;
  var
  Buffer: array[0..MAX_PATH] of Char;
  begin
  Windows.GetClassName(Handle, @Buffer, MAX_PATH);
  Result := String(Buffer);
  end;
Var
 Wnd: HWND;
 SkypeWnd: HWND;
begin
 SkypeWnd := FindWindow('tSkMainForm',nil);

 Wnd := GetTopWindow(SkypeWnd);

 while (GetClassName(Wnd) <> 'TConversationForm') and (Wnd <> 0) and (not IsWindowVisible(Wnd)) do
 begin
   Wnd := GetNextWindow(Wnd,GW_HWNDNEXT);
 end;

 Label1.Caption := GetClassName(Wnd)+' - '+GetHandleText(wnd);

end;

The above is supposed to find the visible window, however when I debug it, it never enters the Begin End within the While loop, and Label1 displays "TChromeMenu - ChromeToolbar". When I remove the IsWindowVisible check, it atleast finds a TConversationForm. What am I doing wrong?

EDIT3: By placing the IsWindowVisible and getClassName check inside the loop, and break when true, I managed to do it. :)

Community
  • 1
  • 1
Jeff
  • 12,085
  • 12
  • 82
  • 152
  • 1
    What about `EnumerateWindows` or FindWindow to get it? – David Heffernan Jul 01 '11 at 12:39
  • I think you have to use z-order of the child windows to determine which one is on top. – ain Jul 01 '11 at 12:42
  • There is no such function "EnumerateWindows", `FindWindow` is not applicable here too. Best bet is `GetWindow(.., GW_HWNDFIRST)` call. – Premature Optimization Jul 01 '11 at 12:47
  • @David - `FindWindow` and `FindWindowEx` does not return the expected `TConversationWindow`. How would `EnumWindows` help me in this situation? @ain - How would I do that? :) – Jeff Jul 01 '11 at 12:48
  • @Downvoter - The first parameter, would that be the parent window? – Jeff Jul 01 '11 at 12:51
  • @David - The window is a child of `tSkMainForm` – Jeff Jul 01 '11 at 13:05
  • @David - please see edited post, I added a screenshot of Winspector :) – Jeff Jul 01 '11 at 13:11
  • @David **All the same if it's children you want call EnumChildWindows.ChildWindows** - That will list the children, but AFAIK it wont give me the active one? – Jeff Jul 01 '11 at 13:28
  • Define what you mean by active. – David Heffernan Jul 01 '11 at 13:52
  • @David - I mean "the window I am currently looking at", because in **default view**, you can only see one `TConversationForm` at a time. :) – Jeff Jul 01 '11 at 15:25
  • @Jeff It depends then on the Skype implementation but it's easy to guess how it would be done. Either the active one is above the others in the z-order. Or, more likely, the inactive conversation windows are all invisible. Easy enough to check which it is. – David Heffernan Jul 01 '11 at 15:30
  • @David - So how do I compare? Get next window untill I find one that is visible? – Jeff Jul 01 '11 at 16:34
  • EnumChildWindows and stop when you have one with the right class and that's visible. Maybe. – David Heffernan Jul 01 '11 at 16:39
  • @DavidHeffernan let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1060/discussion-between-jeff-and-david-heffernan) – Jeff Jul 01 '11 at 16:41
  • @David - I edited my OP with some code, that is behaving weird. – Jeff Jul 01 '11 at 18:10

1 Answers1

0

By placing the IsWindowVisible and getClassName check inside the loop, and break when true, I managed to do it. :)

Jeff
  • 12,085
  • 12
  • 82
  • 152