Comment utiliser Buddy Windows
En définissant d’autres contrôles en tant que fenêtres d’amis pour une barre de suivi, vous pouvez positionner automatiquement ces contrôles aux extrémités de la barre de suivi en tant qu’étiquettes.
L’illustration suivante montre une barre de suivi horizontale et verticale, toutes deux avec des contrôles statiques en tant que fenêtres d’amis.
Bon à savoir
Technologies
Prérequis
- C/C++
- Programmation de l’interface utilisateur Windows
Instructions
Utiliser Buddy Windows
L’exemple de code suivant crée les fenêtres d’amis affichées dans l’illustration.
void LabelTrackbarsWithBuddies(HWND hDlg)
{
HWND hwndTrackbar;
HWND hwndBuddy;
const int staticWidth = 50;
const int staticHeight = 20;
//======================================================
// For horizontal Trackbar.
hwndTrackbar = GetDlgItem(hDlg, IDC_SLIDER1);
hwndBuddy = CreateWindowEx(0, L"STATIC", L"Left", SS_RIGHT | WS_CHILD | WS_VISIBLE,
0, 0, staticWidth, staticHeight, hDlg, NULL, g_hInst, NULL);
SendMessage(hwndTrackbar, TBM_SETBUDDY, (WPARAM)TRUE, (LPARAM)hwndBuddy);
//-------------------------------------------------
hwndBuddy = CreateWindowEx(0, L"STATIC", L"Right", SS_LEFT | WS_CHILD | WS_VISIBLE,
0, 0, staticWidth, staticHeight, hDlg, NULL, g_hInst, NULL);
SendMessage(hwndTrackbar, TBM_SETBUDDY, (WPARAM)FALSE, (LPARAM)hwndBuddy);
//======================================================
// For vertical Trackbar.
hwndTrackbar = GetDlgItem(hDlg, IDC_SLIDER2);
hwndBuddy = CreateWindowEx(0, L"STATIC", L"Top", SS_CENTER | WS_CHILD | WS_VISIBLE,
0, 0, staticWidth, staticHeight, hDlg, NULL, g_hInst, NULL);
SendMessage(hwndTrackbar, TBM_SETBUDDY, (WPARAM)TRUE, (LPARAM)hwndBuddy);
//-------------------------------------------------
hwndBuddy = CreateWindowEx(0, L"STATIC", L"Bottom", SS_CENTER | WS_CHILD | WS_VISIBLE,
0, 0, staticWidth, staticHeight, hDlg, NULL, g_hInst, NULL);
SendMessage(hwndTrackbar, TBM_SETBUDDY, (WPARAM)FALSE, (LPARAM)hwndBuddy);
}
Notes
IDC_SLIDER1 et IDC_SLIDER2 sont des barres de suivi créées dans l’éditeur de ressources.
Rubriques connexes