Black Friday = Pricewatch Bekijk onze selectie van de beste Black Friday-deals en voorkom een miskoop.

[C#] Child focus zonder verliezen parent focus

Pagina: 1
Acties:

  • BastiaanN
  • Registratie: September 2003
  • Niet online
Hallo Iedereen,

Ik ben momenteel bezig met een goede collega om een tabbed interface te ontwikkelen voor PuTTY. de welbekende SSH en Telnet client (en ja we weten dat er al 1 bestaat, maar die werkt niet geheel lekker).

We plaatsen de PuTTY vensters een voor een in een paneel in een apart tabblad. Dit doen we middels de user32 api calls, SetParent en MoveWindow. Dit werkt allemaal prima en het functioneert ook gewoon op deze wijze. Een punt van aandacht is echter zodra er in het zwarte gedeelte van putty wordt geklikt, verliest het venster waarin hij in zit ( de parent dus ) zijn focus. Het probleem is nu dat je
  1. Twee keer moet alt+tabben om te switchen naar een andere applicatie
  2. Twee keer op de buttons op het parent form moet klikken voordat ze worden geactiveerd
De window styles veranderen schijnt ook niet te helpen, zelfs niet het instellen van WS_CHILD of WS_EX_CHILD. Zou iemand ons in de goede richting kunnen wijzen? 2 dagen googelen heeft ook nog geen resultaten opgeleverd.

Ten slot, omdat een plaatje meer zegt dan duizend woorden;

Afbeeldingslocatie: http://tweakers.net/ext/f/f1njHAl05SkPIEi6SIpwZUGs/thumb.png

[ Voor 0% gewijzigd door BastiaanN op 19-08-2008 10:22 . Reden: typo ]

Strava | :-( + ┌(^0^)┘= :-)


  • BastiaanN
  • Registratie: September 2003
  • Niet online
*schopt* anyone? :)

Strava | :-( + ┌(^0^)┘= :-)


Verwijderd

Probeer 's om naast SetParent ook SetOwner te zetten?

  • BastiaanN
  • Registratie: September 2003
  • Niet online
Verwijderd schreef op woensdag 20 augustus 2008 @ 20:08:
Probeer 's om naast SetParent ook SetOwner te zetten?
Zou je mij misschien kunnen vertellen hoe ik SetOwner kan aanroepen in C# ? Het enige referentie material op internet verwijst naar de classe Cwnd van C++ welke zover ik weet niet beschikbaar is in C#. ook de functie kan ik niet vinden in user32.dll

Strava | :-( + ┌(^0^)┘= :-)


Verwijderd

Oeps, SetOwner zit idd niet in user32.dll.
Maar met een beetje googlen op SetOwner kwam ik op
Visual Basic:
1
2
3
4
5
6
7
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Const GWL_HWNDPARENT = (-8)

Function SetOwner(ByVal HwndtoUse, ByVal HwndofOwner) As Long
    SetOwner = SetWindowLong(HwndtoUse, GWL_HWNDPARENT, HwndofOwner)
End Function

Is dan wel VB, maar volgens mij moet je hier wel wat mee kunnen...

  • BastiaanN
  • Registratie: September 2003
  • Niet online
Verwijderd schreef op woensdag 20 augustus 2008 @ 21:51:
Oeps, SetOwner zit idd niet in user32.dll.
Maar met een beetje googlen op SetOwner kwam ik op
Visual Basic:
1
2
3
4
5
6
7
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Const GWL_HWNDPARENT = (-8)

Function SetOwner(ByVal HwndtoUse, ByVal HwndofOwner) As Long
    SetOwner = SetWindowLong(HwndtoUse, GWL_HWNDPARENT, HwndofOwner)
End Function

Is dan wel VB, maar volgens mij moet je hier wel wat mee kunnen...
Dit is geen code om de owner te zetten maar de parent. Een quote van msdn m.b.t. GWL_HWNDPARENT
You must not call SetWindowLong with the GWL_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.
m.a.w. het is dus eigenlijk gewoon de SetParent functie maar niet de SetOwner :/

Strava | :-( + ┌(^0^)┘= :-)


  • farlane
  • Registratie: Maart 2000
  • Laatst online: 16-11 18:33
BastiaanN schreef op woensdag 20 augustus 2008 @ 22:12:
m.a.w. het is dus eigenlijk gewoon de SetParent functie maar niet de SetOwner :/
Lees deze post maar eens door waarom het eigenlijk GWL_HWNDOWNER had moeten heten

http://groups.google.com/...napi/msg/9aa4a2b504ee3adf

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.


  • BastiaanN
  • Registratie: September 2003
  • Niet online
Sorry voor de wat late reactie.

ik heb nu dus zowel SetParent als daarna GWL_HWNDPARENT in mijn code gezet, helaas nog geen effect. Als ik WS_EX_NOACTIVATE als extended style zet ben ik niet meer in staat om de focus op het putty object te zetten, maar kan ik ook geen keyboard en mouse events meer ontvangen. Het rare is dat ik al meerdere floating windows heb gezien die de focus ook niet "stelen" van andere klassen maar je wel gewoon in de textboxen in dit form kunt typen. Ik heb al meerdere codes bekeken maar nog steeds de gouden truuk niet kunnen vinden.

Hieronder de code die nu op dit moment voor het opstarten van de applicatie zorgt.

C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        private void initApplication()
        {

            // If control needs to be initialized/created
            if (created == false)
            {

                // Mark that control is created
                created = true;

                // Initialize handle value to invalid
                appHandle = IntPtr.Zero;

                // Start the remote application
                Process p = null;
                try
                {

                    ProcessStartInfo pStart = new ProcessStartInfo();
                    pStart.FileName = this.exeName;
                    pStart.Arguments = this.parameters;
                    pStart.CreateNoWindow = true;
                    pStart.UseShellExecute = true;
                    pStart.WindowStyle = ProcessWindowStyle.Minimized;

                    p = System.Diagnostics.Process.Start(pStart);
                    p.EnableRaisingEvents = true;

                    // Wait for process to be created and enter idle condition
                    p.WaitForInputIdle();

                    // Get the main handle
                    appHandle = p.MainWindowHandle;

                    while (appHandle == IntPtr.Zero)
                    {
                        System.Threading.Thread.Sleep(50);
                        p.Refresh();
                        appHandle = p.MainWindowHandle;
                    }
                    
                    // Maak een eventhandler aan voor het sluiten van
                    // het process
                    p.Exited += new EventHandler(eventProcessExited);

                    GetWindowThreadProcessId(appHandle, ref processID);

                    // Put it into this form
                    SetParent(appHandle, this.Handle);
                    SetWindowLong(appHandle, GWL_HWNDPARENT, (long)this.Handle);

                    // Set the style attributes for it to work properly.
                    SetWindowLong(appHandle, GWL_STYLE, 0x15EF0000 | WS_VISIBLE);                   

                    // Position the window.
                    this.positionWindow();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error");
                }
            }
        }

Strava | :-( + ┌(^0^)┘= :-)

Pagina: 1