Bonjour
je cherche à développer un hook qui me permettrait de controler la taille et la position des fenetres sur le desktop.
j'ai fait un hook cbt et je joue un peu avec les differents evenements mais pour l'instant je me casse les dents sur la taille et la position initiales d'une fenetre. La doc MSDN dit que c'est possible de réagir à l'évènement HCBT_CREATEWND pour modifier la struct CREATEWND et donc controler la taille et la position des fenêtres mais je n'y parviens pas (à part pour ce qui est des boutons, gadgets et autre, c'est pour ça que j'essaie de mettre un filtrage sur la classe de la fenetre). Quelqu'un a déjà réussi à faire un truc comme ça?



Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
LRESULT __declspec(dllexport)__stdcall CALLBACK CBTProc(      
    int nCode,
    WPARAM wParam,
    LPARAM lParam
)
{
       //Move or resize about to occur.
	if ( nCode == HCBT_MOVESIZE)
	{
		RECT *r = reinterpret_cast<RECT *>(lParam);
		r->top=10;
		r->left=10;
        
    } 
	
	if ( nCode == HCBT_CREATEWND)
	{
		CBT_CREATEWND *crt = reinterpret_cast<CBT_CREATEWND*>(lParam);

        char classname[256] ;
	GetClassName(      
			(HWND) wParam,
			classname,
			256);

			
	f1=fopen("h:\\report.txt","a+");
	fprintf(f1,classname);
	fprintf(f1,"\n");

	if (!strcmp(classname,"Notepad"))//only for MSIE
		{
			crt->lpcs->x=10;
			crt->lpcs->y=10;
			crt->lpcs->cx=500;
			crt->lpcs->cy=500;

		}

       fclose(f1);  
    } 
	
	if (nCode == HCBT_MINMAX)

	{
		if (LOWORD(lParam) == SW_MAXIMIZE)
		{
	/* not working...
			WINDOWPLACEMENT wimp;
			wimp.length = sizeof(WINDOWPLACEMENT);
			wimp.showCmd = SW_SHOWMAXIMIZED;
			wimp.ptMaxPosition.x = 10;
			wimp.ptMaxPosition.y = 10;
			wimp.rcNormalPosition.left = 10;
			wimp.rcNormalPosition.top = 10;
			wimp.rcNormalPosition.bottom = 600;
			wimp.rcNormalPosition.right = 800;

			SetWindowPlacement((HWND) wParam,&wimp);
	///not working neither
	  SetWindowPos(      
			(HWND) wParam,
			HWND_TOP,
			10,
			10,
			800,
			600,
			SWP_ASYNCWINDOWPOS|SWP_FRAMECHANGED);
		//return 1;*/
		}


		
	
	}


LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );	

return  RetVal;
}