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
|
void SetStatic(HWND hWin,HFONT hFont)
{
SendMessage(hWin,WM_SETFONT,(UINT)hFont,TRUE);
HDC hDC=GetDC(hWin);
hGdiOld = SelectObject(hDC,hFont);
SIZE size;
char szName[255];
GetWindowText(hWnd, szName,sizeof(szName));
GetTextExtentPoint32(hDC,szName,strlen(szName),&size);
SetWindowPos(hWin,NULL,0,0,size.cx,size.cy,SWP_NOMOVE|SWP_NOZORDER);
SelectObject(hDC,hGdiOld);
ReleaseDC(hWin,hDC);
}
HFONT MaFont1 = CreateFont(50,0,0,0,FALSE,TRUE,TRUE,FALSE,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_DONTCARE|DEFAULT_PITCH,"Arial");
HWND hWin = CreateWindowEx(ExFlags, pClass, pName, WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | Flags,x, y, w, h, hDlg, NULL, WINMAIN_hInst, NULL);
SetStatic(hWin,MaFont1);
HFONT MaFont2= CreateFont(15,0,0,0,TRUE,TRUE,TRUE,FALSE,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_DONTCARE|DEFAULT_PITCH,"Arial");
HWND hWin1 = CreateWindowEx(ExFlags, pClass, pName, WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | Flags,x, y, w, h, hDlg, NULL, WINMAIN_hInst, NULL);
SetStatic(hWin1,MaFont2);
RECT Rect;
::GetClientRect(hWin,&Rect); // 1 static coord screen
POINT pt;
pt.x=Rect.left;
pt.y=Rect.top;
::ScreenToClient(hDlg,&pt); // conversion en coord cliente
pt.x+=(Rect.right-Rect.left); // x= fin du premier static. position x += largeur du static.
::GetClientRect(hWin1,&Rect); //2 static coord screen
POINT pt2;
pt2.x=Rect.left;
pt2.y=Rect.top; // y = hauteur actuelle du static.
::ScreenToClient(hDlg,&pt2); // conversion en coord cliente
SetWindowPos(hWin1,NULL,pt.x,pt2.y,0,0,SWP_NOSIZE|SWP_NOZORDER); // deplacement uniquement pas la taille. |