QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2480|回复: 0
打印 上一主题 下一主题

Create a captionless form

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 01:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta

) Y, Q# @7 l$ `: f8 r8 EAnswer: , x0 L$ p/ i3 e) o" t8 F( Z You can remove a form's caption by setting BorderStyle to bsDialog and overriding the CreateParams function of the form. Inside CreateParams, you clear the WS_CAPTION bits from Params.Style.

) k' |. o" a' [2 b; L

Step 1: Add the CreateParams prototype to the form class.

( M; C* U/ A7 T {2 n0 A

private:/ W( ?+ V- q& v* X$ t/ _) C void __fastcall CreateParams(TCreateParams &arams);

: y! F; B2 O) M

Step 2: Code the function.

8 L9 ~0 n: ^* ^% N

void __fastcall TForm1::CreateParams(TCreateParams &arams)% q) h2 g8 n1 V3 t { p3 M7 [' S5 L5 V TForm::CreateParams(Params); // call base class first" V S# V/ E/ j5 ^- w5 H" `2 T2 I Params.Style &= ~WS_CAPTION; // then clear caption bit$ J4 w! z3 P' n) E& Y3 |/ Q }

/ W" u& n ~" C8 R& p/ K* e4 e: [+ j2 L2 m% D+ w) b

Note: WS_CAPTION is defined in \INCLUDE\WINRESRC.H as

R6 c3 W* ~" ?, v9 _

#define WS_CAPTION 0x00C00000L /* WS_BORDER | WS_DLGFRAME */

0 t. [6 S3 O( e( j: n( E' p3 G9 p

In Windows 3.X, using WS_CAPTION got you a border and a title bar, but not a dialog frame. This meant that having a border and a dialog frame were mutually exclusive. Clearing WS_CAPTION would remove both the title and the border in a Windows 3 application. In these apps, you would remove the title bar by clearing only the WS_DLGFRAME portion in conjunction with utilizing the WS_POPUP style. Win32 offers a new set of extended windows styles. You can use extended window styles to create a window with a dialog frame, a border, and no title bar.

3 h& {4 B' V r- M9 X! X- D

TForm::CreateParams contains these statements:

2 b9 M. D( @2 J3 d

case bsDialog:2 p w! P' {9 K. e% N Params.Style |= WS_POPUP | WS_CAPTION;5 l6 k. \9 n' W9 m" a6 A" i& a Params.ExStyle |= WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE;

( ^: K( j& K9 c3 u5 g- L

This combination produces a window with a border and a dialog frame whenever you specify bsDialog as the BorderStyle. We clear WS_CAPTION when we override CreateParams, but the form retains its border because of the assignment to the ExStyle. The assignment to ExStyle does not happen when you set BorderStyle to something other than bsDialog, which means you should stick with the bsDialog style when utilizing the code from this FAQ.

& L4 J4 u, @9 \9 r% S8 h4 Y

Note: If you need a resizable, captionless form, change CreateParams like this:

@* x2 \8 d: S$ p, w+ B9 b( _

void __fastcall TForm1::CreateParams(TCreateParams &arams), K" K. E" B _+ y { % o9 P! K* K" M* ~( A+ J TForm::CreateParams(Params); // call base class first$ `; Z {/ e' H' W7 Y Params.Style &= ~WS_DLGFRAME; ' Q7 s. p: t0 K% J% u Params.Style |= WS_POPUP; 3 Z9 n6 h0 s/ s7 t N }

" ~9 `. p: A% ^4 s

This code always works, without regard to the BorderStyle property of the form. However, it is less intuitive than clearing the WS_CAPTION bits. 6 s1 H/ S! k. i, \7 `5 k& D

zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-18 17:49 , Processed in 0.281560 second(s), 52 queries .

回顶部