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
|
LRESULT CALLBACK TrappeCtrlNewWndProc(HWND hWnd,UINT Message, WPARAM wParam, LPARAM lParam);
LONG TrappeOldWndProc;
BOOL CSommaire2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_SommaireTrappeCtrl.Create( NULL, _T("STATIC"), WS_VISIBLE, CRect(10, 10, 0, 0), this, 1 );
TrappeOldWndProc = SetWindowLong(m_SommaireTrappeCtrl, GWL_WNDPROC, (long)TrappeCtrlNewWndProc);
return TRUE;
}
LRESULT CALLBACK TrappeCtrlNewWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_SIZE :
LRESULT result = CallWindowProc( (WNDPROC)TrappeOldWndProc, hWnd, NULL, wParam, lParam);
// Get parent
HWND hWndParent = GetParent(hWnd);
// Get parent rect
RECT rcParent;
GetClientRect(hWndParent, &rcParent);
// Get parent rect
RECT rcTrappeCtrl;
GetWindowRect(hWnd, &rcTrappeCtrl);
// Get new size of trappe control
int w = LOWORD(lParam);
int h = HIWORD(lParam);
// Set trappe control in the middle (horizontally)
SetWindowPos(hWnd, hWndParent,
((rcParent.right - rcParent.left) - w) / 2, rcTrappeCrl.top,
0, 0, SWP_NOSIZE | SWP_SHOWWINDOW );
return result;
break;
}
// Call default function
return CallWindowProc((WNDPROC) TrappeOldWndProc,hWnd,Message,wParam,lParam);
}
void CSommaire2Dlg::OnClose()
{
// Reset winproc function
SetWindowLong(m_SommaireTrappeCtrl, GWL_WNDPROC, (long)TrappeOldWndProc);
// Destroy trappe control
m_SommaireTrappeCtrl.DestroyWindow();
CDialog::OnClose();
} |