delphi - Why does BringWindowToTop combined with the VCL Ribbon not work correctly? -


i have following (simplified) procedure bring desired window atop other normal windows:

function focuswindow(): boolean; var   h: hwnd; begin   result := true;   h := findwindow('notepad', 'unbenannt - editor');   if h <> 0     bringwindowtotop(h); end; 

i use in following example application:

starting situation

on top, can see example application. there explorer window behind , empty notepad in background. seen in code above, move notepad window front.

if call function button event handler

procedure tform4.btnfocusclick(sender: tobject); begin   focuswindow(); end; 

everything works expected. empty notepad window moves front, behind example application , explorer behind other 2 windows.

but if use vcl ribbon control action assigned command button, works partly.

procedure tform4.actdemoexecute(sender: tobject); begin   focuswindow(); end; 

the notepad window moves leaving explorer window in back. procedure stops -- notepad window keeps hidden behind own application. happening here?

final situation

i've had contexts call bring top fires , (perhaps mouseup on controls, i'm not sure) refocuses control button , puts in front. in these cases need quick workaround, adding timer fires in 10 or 20 ms bringtofront call seems work. button starts timer, finishes it's own processing, , timer executes bringtofront , turns off; makes bringtofront happen after interaction button. don't find elegant, has worked me more once.


Comments