Is it posible to draw a colored square on the drag bar ?
Like this: The yellow square
(http://www.plop.gr/d1.jpg)
Hi splakidas!
Custom captions are not easy to do.
Basically you have two approaches:
1. Using Win APIs (regions etc.) http://ourworld.compuserve.com/homepages/ernies_world/cc.htm (http://ourworld.compuserve.com/homepages/ernies_world/cc.htm)
2. Using C++ MDI classes http://www.codeproject.com/KB/GDI/customcaption.aspx (http://www.codeproject.com/KB/GDI/customcaption.aspx)
Thank you. I take a look
This is a mini example how it can be done:
$include "windowssdk.inc"
CONST IDC_DRAWCAPTION = 10000
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80CB0080|@SIZE,0,"Caption with square",&d1_handler
domodal d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
case WM_NCPAINT
case& WM_NCACTIVATE
' execute first the default handler, then draw custom
PostMessage(d1.hwnd, WM_COMMAND, IDC_DRAWCAPTION, 0)
case @IDMENUPICK
if (@MENUNUM = IDC_DRAWCAPTION)
HDC dc = GetWindowDC(d1.hwnd)
WINRECT rc
DWORD style = GetWindowLong(d1.hwnd, GWL_STYLE)
int CXBORDER
int CYBORDER
int CYCAPTION = GetSystemMetrics(SM_CYCAPTION)
int CXICON = 0
if (!(style & WS_DLGFRAME))
CXICON = GetSystemMetrics(SM_CXICON)
endif
if (style & WS_SIZEBOX)
CXBORDER = GetSystemMetrics(SM_CXSIZEFRAME)
CYBORDER = GetSystemMetrics(SM_CYSIZEFRAME)
else
CXBORDER = GetSystemMetrics(SM_CXFIXEDFRAME)
CYBORDER = GetSystemMetrics(SM_CYFIXEDFRAME)
endif
rc.left = CXBORDER + CXICON
rc.top = CYBORDER
string caption = GetCaption(d1)
if (caption[0] <> 0)
' create caption font
NONCLIENTMETRICS ncm
ncm.cbSize = len(ncm)
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, FALSE)
HFONT font = SelectObject(dc, CreateFontIndirect(&ncm.lfCaptionFont))
SIZE s
' compute caption text width
GetTextExtentPoint32(dc, caption, len(caption), &s)
DeleteObject(SelectObject(dc, font))
' update square position
rc.left += (s.cx + 4)
endif
int squareHeight = 8
' center the square
rc.top = rc.top + (CYCAPTION - squareHeight)/2
' square size
rc.right = rc.left + 32 ' width
rc.bottom = rc.top + squareHeight
' draw it
HBRUSH brush = CreateSolidBrush(RGB(255,0,0))
FillRect(dc, &rc, brush)
DeleteObject(brush)
ReleaseDC(d1.hwnd, dc)
endif
ENDSELECT
RETURN
ENDSUB
Here's a bit of code from many years ago by Allden .. :)
'/* Allden's guide to tearing apart windows */
'/* RECT STRUCT */
Type tangle
Def left:int
Def top:int
Def right:int
Def bottom:int
EndType
Def rcfill:tangle
'/* POINTS STRUCT */
Type tagPOINT
Def x:int
Def y:int
Endtype
Def pt:tagPOINT
Declare "user32",GetWindowDC(hwnd:int),int
Declare "user32",ReleaseDC(hwnd:int,hdc:int),int
Declare "user32",FillRect(hdc:int, lpRect:rect, hBrush:int),int
Declare "user32",SetRect(pRect:rect, X1:int, Y1:int, X2:int, Y2:int),int
Declare "user32",GetCursorPos(pt:tagPOINT),int
Declare "user32",SetCursorPos(x:int,y:int),int
DECLARE "user32",mouse_event(dwFlags:int,dx:int,dy:int, cButtons:int,Info:int)
Declare "gdi32",CreateSolidBrush(crColor:int),int
Declare "gdi32",DeleteObject(hObject:int),int
Def hwnd:window:' //Window handle
Def hdc:int:' //HDC
Def hbrush:int:' //HBRUSH
Def Tempx,Tempy:int:' //Used with GetCursorPos/SetCursorPos/etc..
Def L,T,W,H:int:' //Window coords rect also SetCursorPos/etc...
Window hwnd,0,0,400,300,@SYSMENU|@NOAUTODRAW,0,"",WndProc
Waituntil hwnd=0
End
Sub WndProc
Select @Class
Case @IDCreate:CenterWindow hwnd
Case @IDPaint
gosub CreateTitle:' //Sub to do the drawing etc..
Case @IDCloseWindow
CloseWindow hwnd
Endselect
Return
Sub CreateTitle
hdc=GetWindowDC(hwnd):' //This returns the handel for the entire window,
' //instead of just the client area.
gosub DrawGradient:' //The sub to create the fill
ReleaseDC(hwnd,hdc):' //Frees the Direct Context
DeleteObject(hbrush):' //Removes the long from memory
'/* When you draw on the window title you erase the buttons */
'/* This is just a work around , it presses the close window button , */
'/* then returns to where it was*/
GetCursorPos(pt)
tempx=pt.x:tempy=pt.y:' //Holds the pt.x & pt.y varibles for later
pt.y=T+5:pt.x=W+L-15
SetCurSorPos(pt.x,pt.y):'//move to the [x]
wait 1
mouse_event(2,0,0,0,0):' //presses the [x]
wait 1
SetCursorPos(0,0):' //0,0 for safe release
mouse_event(4,0,0,0,0):' //Releases mouse , (other wise it sticks)
pt.x=tempx:pt.y=tempy:' //Original coords
SetCursorPos(pt.x,pt.y):'//Set coords
'/* End Main Sub */
Return
Sub DrawGradient
GetSize hwnd,L,T,W,H:' //GetWindow size
Def band:int
Def pstep:float
pstep=W/256.00:' //Get each rect width
For band=0 to 255:'//Number of bands (standard)
' //On a slow machine this could be alterd to half
' //& the band length is the multiplied by 2
SetRect(rcfill,int(band*pstep),0,int((Band+1)*pstep),30):'// Where to draw
hbrush=CreateSolidBrush(rgb(0,0,(255 - Band))):' //Blue to black
'hbrush=CreateSolidBrush(rgb(0,(255 - Band),0)):' //Green to black
'hbrush=CreateSolidBrush(rgb((255 - Band),0,0)):' //Red to black
FillRect(hdc,rcfill,hbrush):' //Do the Deed!
Next band
SetRect(rcfill,0,30,W,H):' //Take off the xp borders (yuck!)
hbrush=CreateSolidBrush(rgb(0,0,0)):' //Black Brush
FillRect(hdc,rcfill,hbrush):' //Black BG!
Return
It might give you some idea of how to proceed .. although it's in CBasic, it can presumably be ported OK.
best wishes, :)
Graham