Salut,
est ce que c'est possible d'avoir une toolbar (flottante si possible) avec le mod�le Dialog Based ?
Si oui comment faire ?
Merci.
Version imprimable
Salut,
est ce que c'est possible d'avoir une toolbar (flottante si possible) avec le mod�le Dialog Based ?
Si oui comment faire ?
Merci.
Oui, c'est possible. Je mets le code ci-dessous en pr�cisant bien que ce n'est pas moi qui l'ai �crit mais que je l'ai trouv� sur le net et je me souviens plus o�..
en gros, tu cr�es des CToolBar dans ta CDialog, et dans le OnInitDialog de ta boite tu appelles une fonction style CreateToolBar qui fait � peu pr�s :Code:
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 BOOL CMyDialog::CreateToolbar(CToolBar *wndToolBar, int ID) { // ID est l'ID de la Toolbar dessinée dans les ressources... if(!wndToolBar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC ) || !wndToolBar->LoadToolBar(ID)) { TRACE0("Failed to Create Dialog Toolbar\n"); EndDialog(IDCANCEL); } CRect rcClientOld; // Old Client Rect CRect rcClientNew; // New Client Rect with Tollbar Added GetClientRect(rcClientOld); // Retrive the Old Client WindowSize // Called to reposition and resize control bars in the client // area of a window. The reposQuery FLAG does not really traw the // Toolbar. It only does the calculations. And puts the new // ClientRect values in rcClientNew so we can do the rest of the // Math. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, _CONTROLBAR_LAST,0,reposQuery,rcClientNew); // All of the Child Windows (Controls) now need to be moved so // the Tollbar does not cover them up. Offest to move all child // controls after adding Tollbar CPoint ptOffset(rcClientNew.left-rcClientOld.left, rcClientNew.top-rcClientOld.top); CRect rcChild; // Handle to the Dialog Controls CWnd* pwndChild = GetWindow(GW_CHILD); while(pwndChild) // Cycle through all child controls { pwndChild->GetWindowRect(rcChild); // Get the child control RECT ScreenToClient(rcChild); // Changes the Child Rect by the values of the claculated offset rcChild.OffsetRect(ptOffset); pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control pwndChild = pwndChild->GetNextWindow(); } CRect rcWindow; GetWindowRect(rcWindow); // Get the RECT of the Dialog // Increase width to new Client Width rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // Increase height to new Client Height rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); MoveWindow(rcWindow,FALSE); // Redraw Window // Now we REALLY Redraw the Toolbar RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0); return TRUE; // return TRUE unless you set the focus to a control }
:king: