Set focus to the OK button in the TPrintDialog - c++builder

Is it possible to set focus to the OK button in the TPrintDialog when it opens?

In the TPrintDialog::OnShow event, you can manually set focus to the OK button like this:
void __fastcall TMyForm::PrintDialogShow(TObject *Sender)
{
HWND btnOK = GetDlgItem(PrintDialog->Handle, IDOK);
::SetFocus(btnOK);
}

Related

CBuilder TMenu showing in wrong place

I have a Form that needs to be embedded in another Form. I'm placing on TCard:
EmbeddedForm->Parent = ACard;
EmbeddedForm->BorderStyle = bsNone;
EmbeddedForm->Align = alClient;
EmbeddedForm->Show();
All is working well, except that menus on the EmbeddedForm are offset to where they would be if the form were located in top left of the screen. To be clear, the menu shows up in the proper place on the EmbeddedForm, but when clicked, the sub-menu is in the wrong place.
I've tried modifying the DrawItem event, but so far I can't call the base class DrawItem() as it's protected:
void __fastcall TEmbeddedForm::File1DrawItem(TObject *Sender, TCanvas *ACanvas, TRect &ARect, bool Selected)
{
ARect.Left = MainMenu1.Left; // or some other calculation, not important yet
ARect.Top = MainMenu1.Top;
// ??? how to do normal drawItem from here?
}
I'm thinking, either I have to draw it myself (I don't want to) or somehow explain to TMainMenu where it's actually located (preferred solution).

Disable mouse scroll wheel for TStringGrid components, enable for outer frame (VCL, C++ Builder)

I have several TStringGrid components in a frame. I would like to disable the mouse scroll wheel for a TStringGrid component, but enable it for the frame, so that when the mouse wheel is moved, the frame scrolls up or down, instead of changing the cell selection in the grid.
I tried setting adding empty methods for OnMouseWheelDown and OnMouseWheelUp for each of the TStringGrid components (this didn't work).
Modify the OnMouseWheel event handler on the frame:
void __fastcall TFrameNameOfFrame::FrameMouseWheel(TObject *Sender, TShiftState Shift,
int WheelDelta, TPoint &MousePos, bool &Handled)
{
this->VertScrollBar->Position += WheelDelta;
}

How can I cancel MouseWheel Windows Message in TRichEdit control to fix scrolling?

In the application I'm working on, there is a TListView and a TRichEdit in a form.
When the user click an item in the TListView, it loads TRichEdit text. My problem occurs when the text is longer then the height of the TRichEdit.
If I scroll with the Mouse Wheel really quickly and I continue scrolling even when the scrolling bar is at bottom, then I click another item in the TListview (which make TRichEdit->Text change), the scrolling sometimes continues on the newly loaded text.
My hypothesis is that there is some kind of Windows Message not yet processed and when I click another item, the scroll message is read and the scrolling continue?!
I already tried to disable then enable the TRichEdit on the TRichEdit MouseLeave without success (scrolling continue when I change selected item of TListView).
I was wondering if anybody have any ideas?
[edit]
Ok so I'm trying the solution from Remy but PeekMessage() doesn't catch any WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL. I tried to catch it before and after the function DescriptionChanged(); but neither of them catch the scroll message.
void __fastcall TfrmJob::lvDescriptionSelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
//Function where ListView load item into RichEdit->Text
DescriptionChanged();
MSG msg;
//Loop while there is messages ("If no messages are available, the return value is zero")
while (PeekMessage(&msg, NULL /*reDocDetail->Handle*/ /*lvDescription->Handle*/, 0, 0, PM_REMOVE | PM_QS_INPUT) > 0)
{
//Trying to catch Scroll message
if(msg.message == WM_VSCROLL || msg.message == WM_HSCROLL || msg.message == WM_MOUSEWHEEL)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
}

Why can't I access the width of a THeaderSection

I'm trying to use the width of a headersection in a THeaderControl in C++ Builder XE.
The THeaderControl is called "Header"
The TStringGrid I'm trying to align the widths with is called "Grid".
In the OnResize event handler for the Header, I've got the following code :
void __fastcall TMainForm::HeaderResize(TObject *Sender)
{
for (int col=0; col<Header->Sections->Count; col++)
{
Grid->ColWidths[col]=Header->Sections[0].Width;
}
}
which I thought would be OK, but it won't compile.
Can't seem to find out how to access the widths of the header.
Also, when i stuff something in here just to get it to compile (e.g. Grid->ColWidths[col]=100), the HeaderResize event handler doesn't get called (i.e. if I put a breakpoint in this loop, run the program and resize the header, it doesn't get to the breakpoint).
You are not accessing the individual headers sections correctly. You need to do it like this instead:
void __fastcall TMainForm::HeaderResize(TObject *Sender)
{
for (int col=0; col<Header->Sections->Count; col++)
{
Grid->ColWidths[col] = Header->Sections->Items[col]->Width;
}
}
Notice that Sections[col] is replaced with Sections->Items[col], and that .Width is replaced with ->Width.
As for the OnResize event not being triggered, OnResize is only triggered when the entire THeaderControl is resized. When resizing individual sections, the OnSectionResize event is triggered instead. That event tells you which section was resized, eg:
void __fastcall TMainForm::HeaderSectionResize(TCustomHeaderControl *HeaderControl, THeaderSection *Section)
{
Grid->ColWidths[Section->Index] = Section->Width;
}

Modify the "arrow" with of a split button in TActionToolBar

I have a toolbar using TActionToolBar and TActionManager. A button has sub-buttons that are available clicking the small down arrow placed in the right of the button.
The width of the "arrow down" button is very thin and requires precise mouse control. How can I customize it?
Thank you
A solution is using the OnGetControlClass event of TActionToolBar.
Before, it is necessary to derive a class from TThemedDropDownButton and override the GetDropDownButtonWidth function:
function TThemedDropDownButtonEx.GetDropDownButtonWidth: Integer;
begin
Result := 14; // default drop down button width
end;
Then, in OnGetControlClass function:
void __fastcall TWorkAreaToolBarFrame::ActionToolBarLeftGetControlClass(TCustomActionBar *Sender,
TActionClient *AnItem, TCustomActionControlClass &ControlClass)
{
if(ControlClass == __classid(TThemedDropDownButton))
ControlClass = __classid(TThemedDropDownButtonEx);
}
In few words, in GetControlClass event, the toolbar allows you to define which button class you want to use. We use a custom class with the default width changed.

Resources