private void WndCreated(object sender, CbtEventArgs e) { if (e.IsDialogWindow) { m_bInit = false; m_hwnd = e.Handle; } }
private void WndDestroyed(object sender, CbtEventArgs e) { if (e.Handle == m_hwnd) { m_bInit = false; m_hwnd = IntPtr.Zero; if(BST_CHECKED == (int)SendMessage(m_hwndBtn,BM_GETCHECK,IntPtr.Zero,IntPtr.Zero)) m_bCheck = true; } }
private void WndActivated(object sender, CbtEventArgs e) { if (m_hwnd != e.Handle) return; // Not the first time if (m_bInit) return; else m_bInit = true; // Get the current font, either from the static text window // or the message box itself IntPtr hFont; IntPtr hwndText = GetDlgItem(m_hwnd, 0xFFFF); if(hwndText != IntPtr.Zero) hFont = SendMessage(hwndText, WM_GETFONT, IntPtr.Zero, IntPtr.Zero); else hFont = SendMessage(m_hwnd, WM_GETFONT, IntPtr.Zero, IntPtr.Zero); Font fCur = Font.FromHfont(hFont); // Get the x coordinate for the check box. Align it with the icon if possible, // or one character height in int x = 0; IntPtr hwndIcon = GetDlgItem(m_hwnd, 0x0014); if(hwndIcon != IntPtr.Zero) { RECT rcIcon = new RECT(); GetWindowRect(hwndIcon, rcIcon); POINT pt = new POINT(); pt.x = rcIcon.left; pt.y = rcIcon.top; ScreenToClient(m_hwnd, pt); x = pt.x; } else x = (int)fCur.GetHeight(); // Get the y coordinate for the check box, which is the bottom of the // current message box client area RECT rc = new RECT(); GetClientRect(m_hwnd, rc); int y = rc.bottom - rc.top; // Resize the message box with room for the check box GetWindowRect(m_hwnd, rc); MoveWindow(m_hwnd,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top + (int)fCur.GetHeight()*2,true); m_hwndBtn = CreateWindowEx(0, "button", m_strCheck, BS_AUTOCHECKBOX|WS_CHILD|WS_VISIBLE|WS_TABSTOP, x, y , rc.right-rc.left-x, (int)fCur.GetHeight(), m_hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); SendMessage(m_hwndBtn, WM_SETFONT, hFont, new IntPtr(1)); }