对于桌面上的某个窗口(已知句柄),如何编程隐藏它的边框并重新显示边框(不改变窗口其他特性)???(50分)

  • 主题发起人 主题发起人 happymanfreeman
  • 开始时间 开始时间
H

happymanfreeman

Unregistered / Unconfirmed
GUEST, unregistred user!
各位: <br><br> &nbsp; 我有一个小小问题: &nbsp;对于桌面上的某个窗口(已知句柄),如何编程隐藏它的边框并重新显示边框(不改变窗口其他特性)?? &nbsp;这个小问题居然搜索不到!! 请教高手们.
 
该用哪个windowsAPI啊 ?? &nbsp;可叹! 可叹啊 ----
 
呵呵 何必啊 有改属性的 还不知足啊呵呵<br> 那这样啊 你看看他的属性的原代码,属性的原代码调用的是什么winapi不就出来了呵呵
 
有个示范,不是我写的.<br>你看看就知道了很简单<br>unit Unit1;<br>interface <br>uses <br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br>type <br> &nbsp;TForm1 = class(TForm) <br> &nbsp;private <br> &nbsp; &nbsp;procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT; <br> &nbsp; &nbsp;{ Private declarations } <br> &nbsp;public <br> &nbsp; &nbsp;{ Public declarations } <br> &nbsp;end; <br>var <br> &nbsp;Form1: TForm1; <br>implementation <br>{$R *.DFM} <br>{ TForm1 } <br>procedure TForm1.WMNCPaint(var Msg: TWMNCPaint); <br>var <br> &nbsp;dc : hDc; <br> &nbsp;Pen : hPen; <br> &nbsp;OldPen : hPen; <br> &nbsp;OldBrush : hBrush; <br>begin <br> &nbsp;inherited; <br> &nbsp;dc := GetWindowDC(Handle);<br> &nbsp;msg.Result := 1; <br> &nbsp;Pen := CreatePen(PS_SOLID, 5, RGB(255, 0, 0));<br> &nbsp;OldPen := SelectObject(dc, Pen); <br> &nbsp;OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH)); <br> &nbsp;Rectangle(dc, 0,0, Form1.Width, Form1.Height); <br> &nbsp;SelectObject(dc, OldBrush); <br> &nbsp;SelectObject(dc, OldPen);<br> &nbsp;DeleteObject(Pen);<br> &nbsp;ReleaseDC(Handle, Canvas.Handle); <br>end; <br>end.
 
看看下面这段代码:<br> &nbsp; &nbsp; &nbsp;CreateStyle := FBorderStyle;<br> &nbsp; &nbsp; &nbsp;if (FormStyle = fsMDIChild) and (CreateStyle in [bsNone, bsDialog]) then<br> &nbsp; &nbsp; &nbsp; &nbsp;CreateStyle := bsSizeable;<br> &nbsp; &nbsp; &nbsp;case CreateStyle of<br> &nbsp; &nbsp; &nbsp; &nbsp;bsNone:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (Parent = nil) and (ParentWindow = 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Style := Style or WS_POPUP;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Icons := [];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;bsSingle, bsToolWindow:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Style := Style or (WS_CAPTION or WS_BORDER);<br> &nbsp; &nbsp; &nbsp; &nbsp;bsSizeable, bsSizeToolWin:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Style := Style or (WS_CAPTION or WS_THICKFRAME);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FPosition in [poDefault, poDefaultSizeOnly] then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Width := Integer(CW_USEDEFAULT);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Height := Integer(CW_USEDEFAULT);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;bsDialog:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Style := Style or WS_POPUP or WS_CAPTION;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExStyle := WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AddBiDiModeExStyle(ExStyle);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not NewStyleControls then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Style := Style or WS_DLGFRAME or DS_MODALFRAME;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Icons := Icons * [biSystemMenu, biHelp];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WindowClass.style := CS_DBLCLKS or CS_SAVEBITS or<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CS_BYTEALIGNWINDOW;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if CreateStyle in [bsToolWindow, bsSizeToolWin] then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ExStyle := WS_EX_TOOLWINDOW;<br> &nbsp; &nbsp; &nbsp; &nbsp;AddBiDiModeExStyle(ExStyle);<br> &nbsp; &nbsp; &nbsp; &nbsp;Icons := Icons * [biSystemMenu];<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if CreateStyle in [bsSingle, bsSizeable, bsNone] then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if (FormStyle &lt;&gt; fsMDIChild) or (biSystemMenu in Icons) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if biMinimize in Icons then Style := Style or WS_MINIMIZEBOX;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if biMaximize in Icons then Style := Style or WS_MAXIMIZEBOX;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;if FWindowState = wsMinimized then Style := Style or WS_MINIMIZE else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FWindowState = wsMaximized then Style := Style or WS_MAXIMIZE;<br> &nbsp; &nbsp; &nbsp;end else FWindowState := wsNormal;<br> &nbsp; &nbsp; &nbsp;if biSystemMenu in Icons then Style := Style or WS_SYSMENU;<br> &nbsp; &nbsp; &nbsp;if (biHelp in Icons) then ExStyle := ExStyle or WS_EX_CONTEXTHELP;<br> &nbsp; &nbsp; &nbsp;if csInline in ComponentState then<br> &nbsp; &nbsp; &nbsp; &nbsp;Style := Style and not WS_CAPTION;<br> &nbsp; &nbsp; &nbsp;if FormStyle = fsMDIChild then WindowClass.lpfnWndProc := @DefMDIChildProc;<br> &nbsp; &nbsp;end;<br><br>其实Form改变这个外诓,是需要设置Style后,创建窗体形状。不是消息,而是参数
 
zhangsolomon &nbsp;bmsr 和 xiammy: 你们好!<br> &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp;你们都误解了我的意思, 我说的是桌面上一个别人的窗体(我们很容易知道它的句柄), 不是自己建立的窗体, &nbsp;现在要动态隐藏它的边框并重新显示边框(不改变窗口其他特性), 如何编程啊实现 ??
 
如此简单的问题竟然无人知道!!!?????
 
我给你代码 布线于自己的窗口呀?<br> &nbsp;dc := GetWindowDC(Handle);//这里是你已知的窗口句柄<br> &nbsp;msg.Result := 1; <br> &nbsp;Pen := CreatePen(PS_SOLID, 5, RGB(255, 0, 0));<br> &nbsp;OldPen := SelectObject(dc, Pen); <br> &nbsp;OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH)); <br> &nbsp;Rectangle(dc, 0,0, Form1.Width, Form1.Height); //这里要用你已知的窗体的大小代替,即知道句柄,那不是问题<br> &nbsp;SelectObject(dc, OldBrush); <br> &nbsp;SelectObject(dc, OldPen);<br> &nbsp;DeleteObject(Pen);<br> &nbsp;ReleaseDC(Handle, Canvas.Handle); <br>end;
 
bmsr的应该可行的。不过回答问题的富翁可以在关键处标明,那就更好了。
 
bmsr cqwty: 你们好!<br> &nbsp; 你们的代码是正确的, 可是并没有针对我的问题, 你们曲解了我的意思, 看来人与人的交流真的不容易. 我的意思不是说要在窗口四周加上某种颜色的边框, 而是, 原来窗口是标准的windows窗口, 是有边框的, 现在要隐藏它的边框, 使它变成无边框窗口, 如何编程 , 重新显示原来的边框(不改变窗口其他特性), 如何编程 .
 
不用麻烦大家了, 我已经查阅了MSDN, 这种情况是不能实现的, 被windows规则所限制, 大家可去查阅了MSDN.
 
呵呵 晕哦 &nbsp;实现不了 ? 也是
 
后退
顶部