Автор: ShIvADeSt
Дата сообщения: 08.09.2008 02:31
Maks150988
Написано, что хук на окно можно не ставить, один фиг не работает. Вверху есть упоминание джедайских контролов, там можно взять сорсы кнопки для заголовка. Я в свое время делал так же, проверял нажатие на попадание в RECT кнопки и отрисовывал то, что надо.
Добавлено:
Maks150988
[more]
Код:
program sample;
uses
Windows, Messages, Classes, UxTheme, TmSchema;
{$R dialog.res}
var
BtnRect : TRect; // Êîîðäèíàòû êíîïêè ñâåðòûâàíèÿ îêíà
WndRect : TRect; // Êîîðäèíàòû îêíà ïðèëîæåíèÿ
ShlTheme : hTheme; // Óêàçàòåëü íà èñïîëüçóåìóþ òåìó îáîëî÷êè
hWndApp : THandle; // Óêàçàòåëü íà ãëàâíîå îêíî ïðèëîæåíèÿ
Pressed, Focused : Boolean; // Ñîñòîÿíèå íàæàòèÿ êíîïêè ñâåðòûâàíèÿ
Actived : Boolean; // Ñîñòîÿíèå àêòèâíîñòè êíîïêè èç-çà îêíà
CursorPt : TPoint; // Êîîðäèíàòû óêàçàòåëÿ äëÿ êíîïêè
procedure PaintMinimizeToolButton(hWnd : THandle);
var
WinDC : HDC;
SizeX : Integer;
SizeY : Integer;
Xframe : Integer;
Yframe : Integer;
begin
GetWindowRect(hWnd, WndRect);
WinDC := GetWindowDc(hWnd);
SizeX := GetSystemMetrics(SM_CXSIZE);
SizeY := GetSystemMetrics(SM_CYSIZE);
xFrame := GetSystemMetrics(SM_CXFRAME);
yFrame := GetSystemMetrics(SM_CYFRAME);
BtnRect := Bounds(WndRect.Right - WndRect.Left - xFrame - SizeX - 6, yFrame + 2, SizeX - 12, SizeY - 12);
if (Pressed and Focused) then
begin
if InitThemeLibrary and UseThemes then
DrawThemeBackground(ShlTheme, WinDC, WP_MINBUTTON, MINBS_PUSHED, BtnRect, nil)
else
DrawFrameControl(WinDC, BtnRect, DFC_CAPTION, DFCS_CAPTIONMIN or DFCS_PUSHED);
end
else
begin
if InitThemeLibrary and UseThemes then
DrawThemeBackground(ShlTheme, WinDC, WP_MINBUTTON, MINBS_NORMAL, BtnRect, nil)
else
DrawFrameControl(WinDC, BtnRect, DFC_CAPTION, DFCS_CAPTIONMIN);
end;
if NOT Actived then
begin
if InitThemeLibrary and UseThemes then
DrawThemeBackground(ShlTheme, WinDC, WP_MINBUTTON, 5, BtnRect, nil)
else
DrawFrameControl(WinDC, BtnRect, DFC_CAPTION, DFCS_CAPTIONMIN);
end;
ReleaseDC(hWnd, WinDC);
end;
function DlgProc(hWin: HWND; uMsg: UINT; wp: WPARAM; lp: LPARAM): bool; stdcall;
begin
Result := False;
case uMsg of
// Èíèöèàëèçàöèÿ äèàëîãîâîãî îêíà ïðèëîæåíèÿ
WM_INITDIALOG :
begin
hWndApp := hWin;
if InitThemeLibrary and UseThemes then
ShlTheme := OpenThemeData(hWndApp, 'Window');
end;
// Ðåàãèðîâàíèå íà èçìåíåíèå öâåòîâîé òåìû Windows
WM_THEMECHANGED :
begin
if InitThemeLibrary and UseThemes then
begin
CloseThemeData(ShlTheme);
ShlTheme := OpenThemeData(hWndApp, 'Window');
end;
end;
// Ïðîðèñîâêà êíîêè ñâåðòûâàíèÿ ïðè àêòèâíîñòè îêíà
WM_PAINT, WM_NCPAINT, WM_NCACTIVATE :
begin
// Actived := TRUE;
PaintMinimizeToolButton(hWndApp);
end;
// Ïðîðèñîâêà êíîêè ñâåðòûâàíèÿ ïðè íåàêòèâíîñòè îêíà
WM_ACTIVATE :
begin
if LOWORD(wP)=WA_INACTIVE then
Actived := False
else
Actived := True;
PaintMinimizeToolButton(hWndApp);
end;
// Îáðàáîòêà ñîîáùåíèÿ íàæàòèÿ ëåâîé êíîïêîé óêàçàòåëÿ
WM_NCLBUTTONDOWN :
begin
GetCursorPos(CursorPt);
GetWindowRect(hWndApp, WndRect);
CursorPt := Point(CursorPt.X - WndRect.Left, CursorPt.Y - WndRect.Top);
if PtInRect(BtnRect, CursorPt) then begin
Pressed:=True;
Focused:=True;
PaintMinimizeToolButton(hWndApp);
Result:=True;
end;
end;
WM_LBUTTONUP: begin
Pressed:=False;
Focused:=False;
end;
WM_NCMOUSEMOVE :begin
if HiWord(GetAsyncKeyState(VK_LBUTTON))=0 then begin
Focused:=False;
Pressed:=False;
end;
GetCursorPos(CursorPt);
GetWindowRect(hWndApp, WndRect);
if Focused then begin
Focused:=False;
PaintMinimizeToolButton(hWndApp);
end;
CursorPt := Point(CursorPt.X - WndRect.Left, CursorPt.Y - WndRect.Top);
if PtInRect(BtnRect, CursorPt) then begin
// Pressed:=True;
Focused:=True;
PaintMinimizeToolButton(hWndApp);
end;
end;
WM_NCLBUTTONUP :
begin
if Pressed then begin
Pressed:=False;
PaintMinimizeToolButton(hWndApp);
end;
end;
// Íàæàòèå ïðàâîé êíîïêîé óêàçàòåëÿ íà çàãîëîâîê
WM_NCRBUTTONDOWN:
begin
// Áëîêèðóåì ïîÿâëåíèå êîíòåêñòíîãî ìåíþ íà êíîïêå ñâåðòûâàíèÿ îêíà
GetCursorPos(CursorPt);
GetWindowRect(hWndApp, WndRect);
CursorPt := Point(CursorPt.X - WndRect.Left, CursorPt.Y - WndRect.Top);
if PtInRect(BtnRect, CursorPt) then
Result := TRUE;
end;
// Ïåðåðèñîâêà êíîïêè ñâåðòûâàíèÿ ïðè èçìåíåíèè ðàçìåðîâ
WM_SIZE :
begin
RedrawWindow(hWndApp, PRect(0), 0, RDW_INVALIDATE);
end;
// Çàâåðøåíèå ðàáîòû ïðèëîæåíèÿ ñ îñâîáîæäåíèåì ðåñóðñîâ
WM_DESTROY, WM_CLOSE :
begin
if InitThemeLibrary and UseThemes then
CloseThemeData(ShlTheme);
RedrawWindow(hWndApp, PRect(0), 0, RDW_INVALIDATE);
PostQuitMessage(0);
end;
end;
end;
begin
DialogBox(hInstance, MAKEINTRESOURCE(101), 0, @DlgProc);
end.