Detect height of a window's title bar - titlebar

I am using ClipCursor to lock a mouse in a window. How do I detect the height of the window's title bar and border of the window (so the only place the mouse can't click the title bar and the minimize, restore and maximize button)?
The height of the title bar depends on OS (I can't give a definite value for this).
I'm not sure if the borders have different widths with different operating systems.
I'm using windows XP on classic mode.
When I change to themed mode the height of the title bar changes so it won't work.
No specific language used.

You can use AutoIt.
You don't have to deal with that specific titlebar height and border width. Instead try to set the MouseCoordMode to relative client position, move the mouse to the top/left position and get the window client size. This is the exact area you want your mouse to be trapped into.
These values can then be used in the _MouseTrap function. It should be similar to your ClipCursor().
The old mouse Position could be saved and restored but it won't make sense as your mouse might be repositioned into the trap field anyways so I commented this out.
#include <GuiConstantsEx.au3>
#include <Misc.au3>
Opt("MustDeclareVars", 1)
_Main()
Func _Main()
Local $GUI, $oldMouseCoordMode, $topLeft, $size ;,$oldMousePos
$GUI = GUICreate("Example MouseTrap", 392, 323)
GUISetBkColor( 0xff0000, $GUI)
GUISetState()
;~ $oldMousePos = MouseGetPos()
$oldMouseCoordMode = Opt("MouseCoordMode", 2)
MouseMove(0, 0, 0)
Opt("MouseCoordMode", 1)
$topLeft = MouseGetPos()
;~ MouseMove($oldMousePos[0], $oldMousePos[1], 0)
$size = WinGetClientSize($GUI)
Opt("MouseCoordMode", $oldMouseCoordMode)
_MouseTrap($topLeft[0], $topLeft[1], $topLeft[0] + $size[0], $topLeft[1] + $size[1])
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case Else
;;;
EndSwitch
WEnd
_MouseTrap()
Exit
EndFunc ;==>_Main

Would it work to get the window's client rect, rather than its full rect? I believe that will return the client area of the window, which is the window's rect minus the border and title bar.
If you go this route, you will need to convert the rect into screen coordinates before calling ClipCursor(), though.

I just found out a more specific answer to your problem while browsing the AutoIt help. In the description of the function _WinAPI_CreateRectRgn() there is the following way to get the wished sizes:
#include <WinAPI.au3>
; get height of window title and width of window frame - may be different when
; XP theme is ON/OFF
Global $htit = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $frame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)

looks like
GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYSIZEFRAME)
is the correct height of title bar

One solution in AutoHotKey is to simply remove the bar! That will still allow people to use short cuts to manipulate the window though...
^F11:: ; Ctrl+F11 = Toggle show Window title bar
WinSet, Style, ^0xC00000, A ; Toggle the active window's title bar (WS_CAPTION).
If (TopbarHide := !TopbarHide) ;
ToolTip Topbar Ctrl F11,A_ScreenWidth/2-50,0
else
Tooltip
Return

Related

Slack style title bar

Slack on the Mac at least removed the title bar but still has the control buttons. How do I duplicate this effect? Is there an electron option I missing or did slack rollout there own control buttons?
You can do this with Electron by setting the titleBarStyle option.
To use it:
var winObj = new BrowserWindow({
titleBarStyle: 'hidden',
});
This will hide the title bar but still keep the traffic lights in the corner.
Here are different values for the titleBarStyle option:
default
Results in the standard gray opaque Mac title bar.
hidden (Used in the example).
Results in a hidden title bar and a full size content window, yet the title bar still has the standard window controls ("traffic lights") in the top left.
hiddenInset
Results in a hidden title bar with an alternative look where the traffic light buttons are slightly more inset from the window edge.
See the docs for the BrowserWindow options (search for titleBarStyle).

Hammerspoon: drawing a line in the title bar of a window

I am trying to draw a red line in the title bar of a focused window. For this, I created code similar to the following (it is meant to be a minimal example):
function foo()
f = hs.window.focusedWindow():frame()
line = hs.drawing.line(hs.geometry.point(f.x, f.y),hs.geometry.point(f.w,f.y))
line:setStrokeWidth(10)
line:setStrokeColor(hs.drawing.color.red)
line:show()
end
If I enter this into the Hammerspoon Console, followed by
foo()
it draws a line outside the window, not on the title bar, if the Console is placed in the right half of the display. Please see the attached screenshot. In fact, the position and length of the red line change, depending on the location of the Console window, and the desired red line can be drawn on the title bar, if the Console is in the left half of the display. I totally got confused. What is wrong with the code?
Can anyone help?
EDIT
More photos are added. Note that setStrokeWith(30) is used.
As is, the code will place the bar windows width away from the left side of the screen. The seemingly fixed position is because the window width is the same. Use:
hs.geometry.point(f.x + f.w, f.y)
To place the second point as on offset from the first.

Set prompt text to the center of TextArea control in JavaFX

I was wondering if there is a way to set prompt text location in TextArea.
Basically I am trying to create the similar effect as ListView Placeholder does. It is just to keep consistency in UI, so that everything mostly would look similar.
Any suggestions with this.
I think you can only do this by a dirty hack:
Set alignment to center.
Depending on your desired behavior either add a focus listener which sets the alignment to left again when focused and back to center when focus left.
text.focusedProperty().addListener((p,o,n)->{
if(n){
text.setAlignment(Pos.CENTER_LEFT);
}else {
text.setAlignment(Pos.CENTER);
}
});
Or add a keylistener to get the left aligned text while typing(and a focus-left listener to reset it if needed, eg. empty)
setOnKeyPressed(e->text.setAlignment(Pos.CENTER_LEFT));

Dart: onContextMenu position misplaced

I have a problem with mouse right click menu. My web app has left navigation div, toolbar div, and contentView div. contentView div shows all of my contents /works kind of like web within web/. So here the problem begins. I created onContextMenu on my table like this:
tr.onContextMenu.listen((e) {
contextMenu.style.display = 'block';
contextMenu.style.left = "${e.page.x}px";
contextMenu.style.top = "${e.page.y}px";
selectedRow.clear();
selectedRow.add(tr);
});
When i click right button it takes the position from whole window but when it shows the context menu, the position is based on contentView div. For example if my mouse position is (200,200) it's like (wholepage.0+200,wholepage.0+300) and context menu position would be around (400,500) which is like (contentView div.0+200,contentView div.0+300).
So how can i show my context menu at where mouse is clicked?
Try
contextMenu.style.left = "${e.client.x}px";
contextMenu.style.top = "${e.client.y}px";
and dont forget absolute positioning.
Regards Robert
Well i just changed
${e.page.x}px;
${e.page.y}px;
to
${e.layer.x}px;
${e.layer.y}px;
and now it works.

Creating a ComboBox with one or more separator items?

I'm using Delphi7 and I'd like to have a ComboBox with separator items (Just like in popup menus).
I've seen this beautifully implemented in Mozilla Sunbird (I know, it's not Delphi...) the following way:
The separator item is a simple gray line
drawn in the center of the item
If you hover over the separator with
the mouse, the selection doesn't
appear
If the user clicks the separator,
it's not selected either AND the
combobox doesn't closeup.
No. 1 could be implemented using DrawItem. I could live without No. 2 because I have no idea about that.
For No. 3 I'm asking for your help. I've figured out that straight after closing up a CBN_CLOSEUP message is sent to the combobox.
I thought about hooking the window proc and if CBN_CLOSEUP is sent to a certain combobox then countering it. But I'm unsure if this is the best solution, or maybe there are other, more elegant ways?
Whatever the solution is, I'd like to have a standard ComboBox which supports WinXP/Vista/7 theming properly.
Thanks!
Edit: For a working component please see this thread:
Can you help translating this very small C++ component to Delphi?
I played around with making unclickable separator items (as described in this answer) and ran into several UI glitches. The problem is that combo boxes have several aspects to their behavior that can be hard to get exactly right:
Pressing the up and down arrow keys navigates the list while the list is dropped down.
Pressing Enter closes the dropped down list, selecting the current item.
Pressing Escape closes the dropped down list, selecting the current item (if the current item was chosen with the up and down arrow keys) or the last selected item.
If the combo box has the focus, then pressing the up and down arrow keys to changes the current selection without displaying the list.
If the combo box has the focus, then typing anything selects the combo box item matching whatever is typing.
If the combo box has the focus, then pressing F4 drops down the combo box list, which can then be controlled by keyboard or mouse.
Ensuring that disabled separator items don't respond to any of these events (plus any other events which I may be missing, e.g., screen readers?) seems fraught with error.
Instead, the approach I'm using is to draw the separator as part of the item:
Use a variable height owner draw combo box.
Add 3 pixels to the height for any items that need separators.
Draw a horizontal line at the top of each item needing a separator.
Here's some C++Builder code to accomplish this; translating it to Delphi should be easy enough.
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{
bool draw_separator = NeedsSeparator(Index) &&
!State.Contains(odComboBoxEdit);
TCanvas *canvas = dynamic_cast<TCustomCombo*>(Control)->Canvas;
canvas->FillRect(Rect);
TRect text_rect = Rect;
// Add space for separator if needed.
if (draw_separator) {
text_rect.Top += 3;
}
canvas->TextOut(text_rect.Left + 3,
(text_rect.Top + text_rect.Bottom) / 2 -
canvas->TextHeight(ComboBox1->Items->Strings[Index]) / 2),
ComboBox1->Items->Strings[Index]);
// Draw a separator line above the item if needed.
if (draw_separator) {
canvas->Pen->Color = canvas->Font->Color;
canvas->MoveTo(Rect.Left, Rect.Top + 1);
canvas->LineTo(Rect.Right, Rect.Top + 1);
}
}
void __fastcall TForm1::ComboBox1MeasureItem(
TWinControl * /* Control */, int Index, int &Height)
{
Height = ComboBox1->ItemHeight;
// Add space for the separator if needed.
if (Index != -1 && NeedsSeparator(Index)) {
Height += 3;
}
}
What you want is an owner-drawn combobox. See this: http://delphi.about.com/od/vclusing/a/drawincombobox.htm
Also, this seems to solve making the item unclicable:
http://borland.newsgroups.archived.at/public.delphi.vcl.components.using.win32/200708/0708225320.html
As far as I know there is no VCL way of doing that, so you'll have to subclass the combobox. It would be nice to create component encapsulating those functionalities so you can reuse them easily.
God bless
If you want your controls to look good use the free SpTBXLib. It supports combo style components which popup a popup menu with lines.

Resources