Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Gestion du Focus

3 réponses
Avatar
Manuel Leclerc
Programme en C/Win32. Je crée une fenêtre primaire avec
CreateWindow et WS_OVERLAPPEDWINDOW, puis je crée des
fenêtres filles avec CreateWindow et WS_CHILD. En gros,
j'ai une fenêtre principale, une barre d'icône, un
panel à gauche, une barre de séparation, et un panel à
droite.

Problème : à l'initialisation j'utilise SetFocus sur une
de mes fenêtre filles (le panel de gauche). Quand j'utilise
[Alt]+[Tab] pour changer d'application (ou la souris) et
que je reviens sur ma fenêtre principale avec la même technique,
le focus n'est pas automatiquement remis sur la fille qui
l'avait. Si la fenêtre principale était une DialogBox, tout
serait automatique et la fenêtre "fille" (un contrôle) qui avait
le focus le récupérerait automatiquement.

Question : existe-t-il une méthode pour obtenir simplement
le même genre de comportement avec une fenêtre principale
qui n'est pas une DialogBox, où faut-il tout se programmer
à la main ?

Question annexe : quelqu'un connaît-il un document présentant
ces divers concepts de gestion de focus dans le moteur de
fenêtrage Win32 ?

--
Minitel : 36 15 Boulet
Police/pompier : 18
7+14 : 21
--ackboo

3 réponses

Avatar
Christian ASTOR
Manuel Leclerc a écrit:

Question : existe-t-il une méthode pour obtenir simplement
le même genre de comportement avec une fenêtre principale
qui n'est pas une DialogBox, où faut-il tout se programmer
à la main ?



Ce n'est pas comme ça que fait le Dialog Manager, mais ça simplifie
(WM_USER pour l'exemple)

static HWND hWndFocus;

case WM_ACTIVATEAPP:
{
if (!wParam)
hWndFocus = GetFocus();
else
PostMessage(hWnd, WM_USER, 0, 0);
}
break;
case WM_USER:
SetFocus(hWndFocus);
break;
Avatar
Manuel Leclerc
Christian ASTOR a écrit :

Manuel Leclerc a écrit:

> Question : existe-t-il une méthode pour obtenir simplement
> le même genre de comportement avec une fenêtre principale
> qui n'est pas une DialogBox, où faut-il tout se programmer
> à la main ?

Ce n'est pas comme ça que fait le Dialog Manager, mais ça
simplifie (WM_USER pour l'exemple)

static HWND hWndFocus;

case WM_ACTIVATEAPP:
{
if (!wParam)
hWndFocus = GetFocus();
else
PostMessage(hWnd, WM_USER, 0, 0);
}
break;
case WM_USER:
SetFocus(hWndFocus);
break;



Mince, alors. Figure toi que je ne connaissais pas
l'API GetFocus. Effectivement, ça va m'aider. Merci.

<ma vie>
Ceci dit, je vais devoir faire plus compliqué, notamment
à cause de ma barre de séparation entre les deux panels, qui
doit avoir le focus pendant le tracking, focus qu'elle peut
perdre sur un [Alt]+[Tab], mais qu'elle peut reprendre sur
un nouveau clik souris, mais alors quand le tracking sera fini
le focus devra aller là où il était au début. Tu vois le
BORDEL.
</ma vie>
Avatar
Vincent Burel
"Manuel Leclerc" wrote in message
news:4073ef06$
Programme en C/Win32. Je crée une fenêtre primaire avec
CreateWindow et WS_OVERLAPPEDWINDOW, puis je crée des
fenêtres filles avec CreateWindow et WS_CHILD. En gros,
j'ai une fenêtre principale, une barre d'icône, un
panel à gauche, une barre de séparation, et un panel à
droite.

Problème : à l'initialisation j'utilise SetFocus sur une
de mes fenêtre filles (le panel de gauche). Quand j'utilise
[Alt]+[Tab] pour changer d'application (ou la souris) et
que je reviens sur ma fenêtre principale avec la même technique,
le focus n'est pas automatiquement remis sur la fille qui
l'avait. Si la fenêtre principale était une DialogBox, tout
serait automatique et la fenêtre "fille" (un contrôle) qui avait
le focus le récupérerait automatiquement.

Question : existe-t-il une méthode pour obtenir simplement
le même genre de comportement avec une fenêtre principale
qui n'est pas une DialogBox, où faut-il tout se programmer
à la main ?



j'avais fait ca ci-dessous pour avoir une gestion des touche TAB et
SHIFT+TAB sur tout type de fénêtres... ca peux peut-être aider pour gérer le
Focus de manière générale...

int xxxx_WindowProcessFocus(HWND hparent,UINT uMsg,WPARAM wParam,LPARAM
lParam)
{
short b_shift;
HWND hwf,hwfirst,hwnext;
hwf=GetFocus();
b_shift= GetKeyState(VK_LSHIFT) & 0x8000;
b_shift = b_shift | (GetKeyState(VK_SHIFT) & 0x8000);

if (((int)wParam == VK_TAB) && (b_shift ==0))
{
if ((hwf==NULL) || (hwf == hparent))
{
hwf=GetWindow(hparent,GW_CHILD);
hwfirst=hwf;
if (IsWindowEnabled(hwf)==0L)
{
hwnext=GetNextWindow(hwf,GW_HWNDNEXT);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
while ((hwnext != hwfirst) && (IsWindowEnabled(hwnext)==0L))
{
hwnext=GetNextWindow(hwnext,GW_HWNDNEXT);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
}
SetFocus(hwnext);
}
else SetFocus(hwf);
}
else
{
hwfirst=hwf;
hwnext=GetNextWindow(hwf,GW_HWNDNEXT);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
while ((hwnext != hwfirst) && (IsWindowEnabled(hwnext)==0L))
{
hwnext=GetNextWindow(hwnext,GW_HWNDNEXT);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
}
SetFocus(hwnext);
}
return 0;
}
//Back
if (((int)wParam == VK_TAB) && (b_shift !=0))
{
if ((hwf==NULL) || (hwf == hparent))
{
hwf=GetWindow(hparent,GW_CHILD);
hwfirst=hwf;
if (IsWindowEnabled(hwf)==0L)
{
hwnext=GetNextWindow(hwf,GW_HWNDPREV);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
while ((hwnext != hwfirst) && (IsWindowEnabled(hwnext)==0L))
{
hwnext=GetNextWindow(hwnext,GW_HWNDPREV);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
}
SetFocus(hwnext);
}
else SetFocus(hwf);
}
else
{
hwfirst=hwf;
hwnext=GetNextWindow(hwf,GW_HWNDPREV);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
while ((hwnext != hwfirst) && (IsWindowEnabled(hwnext)==0L))
{
hwnext=GetNextWindow(hwnext,GW_HWNDPREV);
if ((hwnext==NULL) || (hwnext==hparent))
{
hwnext=GetWindow(hparent,GW_CHILD);
}
}
SetFocus(hwnext);
}
return 0;
}
return 1;
}


VB