2、不用生成多个工程,滚漏就可以实际多个窗体分别显示在任务栏上,像Word一样:
标题 : 在任务栏上实现像WORD XP一样的多窗口
关键字: 多窗口,任务栏
分类 : 开发技巧
密级 : 公开
(评分: , 回复: 1, 阅读: 301) »»
我们有时候要让每一个窗口在任务栏上有一个按钮,但不方便的孝备薯是,DELPHI为我们做得太多,
甚至有些过份了点,呵,还好有办法解决.
首先,看VCL源码
procedure TCustomForm.WMSysCommand(var Message: TWMSysCommand)
begin
with Message do
begin
if (CmdType and $FFF0 = SC_MINIMIZE) and (Application.MainForm = Self) then
Application.WndProc(TMessage(Message))
else if (CmdType and $FFF0 <> SC_MOVE) or (csDesigning in ComponentState) or
(Align = alNone) or (WindowState = wsMinimized) then
inherited
if ((CmdType and $FFF0 = SC_MINIMIZE) or (CmdType and $FFF0 = SC_RESTORE)) and
not (csDesigning in ComponentState) and (Align <> alNone) then
RequestAlign
end
end
可以得知,MainForm的一些消息被传给了应用程序对象Application,我们要做的巧者就是截取这
些消息,干我们自己想干的.
1.在主窗体unit中
声明
procedure WMSysCommand(var Message: TWMSysCommand) message WM_SYSCOMMAND
procedure CreateParams(var Params:TCreateParams) override
实现
procedure TForm1.WMSysCommand(var Message: TWMSysCommand)
begin
case message.CmdType of
SC_MAXIMIZE,SC_MINIMIZE,SC_RESTORE: //这几个消息自己处理
DefWindowProc(Self.Handle,message.Msg,message.CmdType,0)
else
inherited//交给DELPHI
end
end
procedure TForm1.CreateParams(var Params:TCreateParams)
begin
inherited CreateParams(Params)
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW //让主窗体出现在任务栏上
end
好了,这样主窗体就会出现在任务栏上,而且最小化也不会消失,现在要做的就是
让Application在任务栏上的按钮消失,用以下代码
procedure TForm1.FormShow(Sender: TObject)
begin
showwindow(Application.Handle ,sw_hide)
end
其它的窗体想出现在任务栏,只要像主窗体一样重载CreateParams方法,并用相同的代码,
因为是非MainForm,所以不用截取那几个消息.
这样就实现了一个应用程序有多个任务栏按钮,而且不会相互影响
delphi 编团氏枯译的塌洞软件,其窗口显核和示在任务栏的标题,通常可以通过以下方法修改:
在 IDE 菜单里,Project ->Options ->Application ->Title
分类: 电脑/网络 >>程序设计 >>其他编程语言问题描述此燃逗:
用delphi 如何修改其他程序的窗口标题,请大侠们指点下。谢谢
分不过,就25分了,望段晌见谅
解析:
使用API函数 setWIndowtext
The SetWindowText function changes the text of the specified window'森卖s title bar (if it has one). If the specified window is a control, the text of the control is changed. However, SetWindowText cannot change the text of a control in another application.
Syntax
BOOL SetWindowText( HWND hWnd,
LPCTSTR lpString
)
Parameters
hWnd
[in] Handle to the window or control whose text is to be changed.
lpString
[in] Pointer to a null-terminated string to be used as the new title or control text.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
If the target window is owned by the current process, SetWindowText causes a WM_SETTEXT message to be sent to the specified window or control. If the control is a list box control created with the WS_CAPTION style, however, SetWindowText sets the text for the control, not for the list box entries.
To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText.
The SetWindowText function does not expand tab characters (ASCII code 0x09). Tab characters are displayed as vertical bar (|) characters.
Windows 95/98/Me: SetWindowTextW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Example:
HWND hwndCombo
int cTxtLen
PSTR pszMem
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDD_ADDCBITEM:
Get the handle of the bo box and the
length of the string in the edit control
of the bo box.
hwndCombo = GetDlgItem(hwndDlg, IDD_COMBO)
cTxtLen = GetWindowTextLength(hwndCombo)
Allocate memory for the string and copy
the string into the memory.
pszMem = (PSTR) VirtualAlloc((LPVOID) NULL,
(DWORD) (cTxtLen + 1), MEM_COMMIT,
PAGE_READWRITE)
GetWindowText(hwndCombo, pszMem,
cTxtLen + 1)
Add the string to the list box of the
bo box and remove the string from the
edit control of the bo box.
if (pszMem != NULL)
{
SendDlgItemMessage(hwndDlg, IDD_COMBO,
CB_ADDSTRING, 0,
(DWORD) ((LPSTR) pszMem))
SetWindowText(hwndCombo, (LPSTR) NULL)
}
Free the memory and return.
VirtualFree(pszMem, 0, MEM_RELEASE)
return TRUE
Process other dialog box mands.
}
Process other dialog box messages.
}
Function Information
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)