对话框的属性在代码中设置

合集下载

qtquick messagedialog 示例

qtquick messagedialog 示例

qtquick messagedialog 示例下面是一个使用 `QtQuick` 的 `MessageDialog` 的简单示例:首先,确保你已经安装了 `QtQuick` 和相关的库。

然后,创建一个 `QML` 文件,例如`MessageDialog.qml`,并在其中添加以下代码:```qmlimport QtQuick 2.12import QtQuick.Controls 2.12// 创建 MessageDialog 组件MessageDialog {title: "提示"text: "这是一个示例消息对话框。

"// 显示确定按钮standardButtons: StandardButtons.Ok// 点击确定按钮后的回调函数onAccepted: {console.log("用户点击了确定按钮。

")}}```在上述代码中,我们创建了一个 `MessageDialog` 组件。

通过设置 `title` 属性来指定对话框的标题,`text` 属性来设置对话框的文本内容。

我们还使用 `standardButtons` 属性显示了一个确定按钮,并在 `onAccepted` 回调函数中处理按钮点击事件。

要在应用中使用这个 `MessageDialog`,可以将 `MessageDialog.qml` 文件添加到你的项目中,并在需要显示消息对话框的地方引用它。

例如,在其他 `QML` 文件中,可以这样使用:```qmlimport QtQuick.Controls 2.12Button {text: "显示消息对话框"onClicked: {// 显示 MessageDialogQt.createComponent("MessageDialog.qml").createObject(parent)}}```在上述代码中,我们创建了一个按钮,当点击按钮时,会通过 `Qt.createComponent` 方法加载 `MessageDialog.qml` 文件,并创建 `MessageDialog` 对象显示出来。

fxml dialogpane用法

fxml dialogpane用法

fxml dialogpane用法FXML DialogPane是JavaFX中的一个界面组件,用于创建弹窗对话框。

它可以用于显示用户交互或显示重要的信息。

下面将介绍如何使用FXML DialogPane 来创建自定义的弹窗对话框。

首先,在JavaFX应用程序中创建一个FXML文件,用于定义DialogPane的布局和样式。

可以使用JavaFX Scene Builder来创建FXML文件,或者手动编写FXML代码。

在FXML文件中,可以使用各种JavaFX控件来构建对话框的布局。

例如,可以添加Label、TextField、Button等控件,并通过CSS样式来设置它们的外观。

接下来,在Java代码中,加载FXML文件并创建DialogPane对象。

可以使用FXMLLoader类来加载FXML文件,并通过load()方法将其转换为Node对象。

然后,创建一个Dialog对象,并将刚才创建的DialogPane设置为其内容。

可以使用Dialog类的构造函数来创建Dialog对象,然后使用setDialogPane()方法将前面创建的DialogPane对象设置为其内容。

接着,可以设置Dialog的标题、按钮等属性。

可以使用setTitle()方法设置对话框的标题,使用setHeaderText()方法设置对话框的头部文本,使用setContentText()方法设置对话框的内容文本。

最后,显示对话框并等待用户的交互。

可以使用show()方法显示对话框,并使用showAndWait()方法等待用户对对话框的响应。

根据用户的操作,可以通过对话框的getDialogPane().getButtonData()方法获取到用户点击的按钮类型。

总结一下,对于FXML DialogPane的用法,首先需要创建一个FXML文件用于定义对话框的布局和样式。

然后,在Java代码中,加载FXML文件并创建DialogPane对象。

js中dialog的用法

js中dialog的用法

js中dialog的用法在Web开发中,JS作为一种客户端脚本语言,在页面交互中扮演着重要的角色。

其中,Dialog对话框作为JS中的一种组件,起到了与用户进行互动的作用。

本文将借助于jQuery,探讨JS中Dialog的使用方法。

一、弹窗的创建在使用Dialog的过程中,首先需要对其进行定义。

在jQuery UI中,Dialog的创建是通过 $("#dialog").dialog() 一行来实现的,其中dialog()函数中携带的参数可以根据需要进行设置。

例如:$('#dialog').dialog({autoOpen: false,modal: true,open: function() {// ...},close: function() {// ...}});我们通过这段代码,定义了一个id为“dialog”的Dialog组件。

其中,autoOpen 参数表示是否自动打开;modal参数表示是否为模态对话框;open和close参数表示在Dialog打开和关闭时需要执行的回调函数。

二、弹窗的打开当我们需要调用Dialog的时候,只需要调用dialog("open")函数即可。

例如: $('#dialog').dialog("open");也可以给触发打开Dialog的元素绑定事件,例如:$('button').click(function(){$('#dialog').dialog("open");});当然,为了更好的用户体验,我们可以通过修改autoOpen参数来实现Dialog 的自动打开。

例如:$('#dialog').dialog({autoOpen: true});三、弹窗的关闭Dialog的关闭方式可以通过close()函数来实现。

cfolderpickerdialog 用法 -回复

cfolderpickerdialog 用法 -回复

cfolderpickerdialog 用法-回复标题:cfolderpickerdialog 用法指南:一步一步解析如何使用介绍:cfolderpickerdialog 是一个流行的用于文件夹选择的对话框控件,应用广泛于Windows开发。

本文将为读者提供详细的使用指南,一步一步教你如何使用cfolderpickerdialog 控件。

第一步:引入头文件和命名空间cfolderpickerdialog 是由MFC(Microsoft Foundation Classes)提供的一个控件,因此你需要在你的代码中引入MFC 的头文件。

在你的源代码文件的顶部,添加以下几行代码:#include <afxdlgs.h>using namespace std;第二步:创建cfolderpickerdialog 对象要使用cfolderpickerdialog 控件,首先需要在你的代码中实例化一个cfolderpickerdialog 的对象。

在你的代码中声明一个cfolderpickerdialog 对象,例如:Cfolderpickerdialog folderPicker;第三步:设置对话框的属性在使用cfolderpickerdialog 控件之前,你需要设置对话框的属性,例如对话框的标题、初始化目录等。

你可以使用下面的代码来设置这些属性:folderPicker.m_ofn.lpstrTitle = TEXT("请选择文件夹"); folderPicker.m_ofn.Flags = OFN_EXPLORER;在这个例子中,我们设置了对话框的标题为"请选择文件夹",并启用了OFN_EXPLORER 标志,使得对话框使用资源管理器的风格。

第四步:显示文件夹选择对话框设置好对话框的属性后,你可以使用cfolderpickerdialog 对象的DoModal 函数来显示文件夹选择对话框:if(folderPicker.DoModal() == IDOK){CString selectedFolder = folderPicker.GetPathName();对所选文件夹进行处理}在这个例子中,我们使用DoModal 函数来显示文件夹选择对话框,并通过GetPathName 函数获取用户所选择的文件夹路径。

VBA 中的自定义对话框设计与使用指南

VBA 中的自定义对话框设计与使用指南

VBA 中的自定义对话框设计与使用指南自定义对话框在VBA编程中经常被用于与用户进行交互,以便获取输入、显示消息或提供选项。

本文将介绍VBA中的自定义对话框的设计和使用指南,以帮助您更好地在VBA编程中使用自定义对话框。

1. 了解VBA中的常见对话框类型VBA中有多种类型的对话框可供选择,例如输入框、提示框、确认框、文件选择框等。

您需要了解每种对话框的特点和使用方法,以便正确选择适合您的需要的对话框类型。

2. 创建自定义对话框在VBA编程中,您可以使用用户窗体(UserForm)来创建自定义对话框。

用户窗体类似于界面设计工具,可以帮助您创建自定义的界面元素,如文本框、标签、按钮等。

通过在用户窗体上添加这些界面元素,您可以实现自定义对话框的功能。

3. 设计自定义对话框界面在设计自定义对话框界面时,您需要注意以下几点:- 界面元素的布局和位置应该合理,以便用户能够直观地理解其功能。

- 文本框、标签等界面元素的命名要具有描述性,方便代码编写和理解。

- 按钮的事件处理过程需要与相应的功能相匹配,确保用户操作的准确性和便捷性。

4. 处理用户输入在自定义对话框中,您经常需要从用户那里获取输入,并对输入进行处理。

VBA提供了各种方法来处理用户输入。

- 获取文本框中的文本:可以使用文本框的Value属性来获取用户输入的文本。

- 获取选择框的选项:可以使用选择框的Value属性来获取用户选择的选项。

- 检查输入的有效性:您可以在代码中对用户输入进行验证,并根据需要显示提示信息或进行警告。

5. 显示消息和提示除了从用户那里获取输入,您可能还需要向用户显示消息和提示。

在自定义对话框中,您可以使用标签或消息框来显示消息和提示。

根据需要,您可以在自定义对话框中添加相关的元素,并在用户执行某些操作时显示消息或提示。

6. 调用和显示自定义对话框在VBA编程中,您可以使用调用对话框的方法来显示自定义对话框。

您可以在代码中使用调用方法,并传递相关的参数,以便显示自定义对话框。

filedialog用法

filedialog用法

filedialog用法一、什么是filedialogfiledialog是Python标准库中的一个模块,用于创建一个图形用户界面(GUI)来进行文件和目录的选择。

它提供了一种简单而直观的方法来与计算机的文件系统进行交互,让用户能够方便地选择需要的文件和目录。

本文将详细介绍filedialog的使用方法及常见功能。

二、filedialog的基本用法filedialog模块提供了几个主要的函数,用于创建文件和目录选择的对话框:1.askopenfilename:用于选择单个文件。

2.askopenfilenames:用于选择多个文件。

3.asksaveasfilename:用于选择文件保存路径。

4.askdirectory:用于选择目录。

下面将逐一介绍每个函数的用法和参数。

2.1 askopenfilenameaskopenfilename函数是用于选择单个文件的对话框。

它的基本用法如下:from tkinter import filedialogfilename = filedialog.askopenfilename()调用askopenfilename函数后,会弹出一个文件选择对话框,用户可以在对话框中选择一个文件。

选择完毕后,对话框会关闭,同时filename变量会被赋值为所选择的文件的完整路径。

askopenfilename函数还可以接受一些可选参数,用于设置对话框的标题、初始目录等。

例如:filename = filedialog.askopenfilename(title='选择文件', initialdir='/tmp')上述代码会在文件选择对话框中显示标题为”选择文件”,初始目录为”/tmp”的文件列表。

2.2 askopenfilenamesaskopenfilenames函数与askopenfilename类似,用于选择多个文件。

它的基本用法如下:from tkinter import filedialogfilenames = filedialog.askopenfilenames()调用askopenfilenames函数后,会弹出一个文件选择对话框,用户可以在对话框中选择多个文件。

DialogResult三种形式

DialogResult三种形式

这三种DialogResult,只要目前的窗体符合要求,DialogResult 都可以接受他们的返回值。

并不限定只能用到那个方面。

1,Button.DialogResult如果此属性的DialogResult不是设置为None,并且父窗体是通过ShowDialog方法显示的,则不必挂钩任何事件,单击按钮也可关闭父窗体。

然后,该窗体的DialogResult属性将设置为该按钮被单击时的DialogResult。

例如,若要创建一个“是/否/取消”对话框,只需添加三个按钮并将其DialogResult属性分别设置为Yes、No和Cancel即可。

实例如下:private void InitializeMyButton(){// Create and initialize a Button.Button button1 = new Button();// Set the button to return a value of OK when clicked.button1.DialogResult = DialogResult.OK;// Add the button to the form.Controls.Add(button1);}参看项目E:\C#\projects\WindowsForms2_ChooseController\WindowsForms2_ChooseController。

2.Form.DialogResult窗体的对话框结果是当窗体显示为模式对话框时从该窗体返回的值。

如果窗体显示为对话框,用DialogResult枚举中的值设置此属性将设置该窗体的对话框结果值、隐藏模式对话框并将控制返回给调用窗体。

此属性通常由窗体上Button控件的DialogResult属性设置。

当用户单击Button控件时,分配给Button的DialogResult属性的值将分配给该窗体的DialogResult属性。

dev xtraopenfiledialog 用法 -回复

dev xtraopenfiledialog 用法 -回复

dev xtraopenfiledialog 用法-回复使用xtraOpenFileDialog的方法xtraOpenFileDialog是DevExpress控件库中提供的一个开源对话框组件,用于在应用程序中打开文件。

该控件提供了许多功能和选项,使用户能够浏览和选择文件,并对所选文件进行各种操作。

在本文中,我们将一步一步地介绍如何正确地使用xtraOpenFileDialog控件。

1. 引用控件库在开始使用xtraOpenFileDialog之前,我们首先需要将DevExpress控件库添加到我们的项目中。

我们可以通过NuGet包或手动引用DLL文件的方式添加该控件库。

2. 创建xtraOpenFileDialog控件实例一旦我们已经成功引用了DevExpress控件库,我们可以在我们的代码中创建xtraOpenFileDialog控件的实例。

我们可以通过以下方式完成这一步骤:using DevExpress.XtraEditors;...xtraOpenFileDialog openFileDialog = new xtraOpenFileDialog();3. 设置对话框的属性一旦我们成功创建了xtraOpenFileDialog的实例,我们可以通过设置其各种属性来自定义对话框的行为和样式。

以下是其中一些常用的属性:- Title: 设置对话框标题。

- InitialDirectory: 设置对话框打开的初始目录。

- Filter: 设置筛选器,用于限制用户可以选择的文件类型。

- Multiselect: 设置是否允许用户选择多个文件。

- RestoreDirectory: 设置在每次打开对话框时是否还原到上一次打开的目录。

- CheckFileExists: 设置是否检查用户选择的文件是否存在。

- CheckPathExists: 设置是否检查用户选择的路径是否存在。

这些属性的设置可以通过直接访问控件的属性或使用DialogResult枚举类型来完成,具体取决于您的应用程序的需求。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

对话框的属性在代码中设置(源文件)针对对话框的控件的属性设置代码如下,可以拿来直接使用,无须改动,直接嵌入到你的程序代码,提高编程效率。

文件BtnST.h 头文件// Class: CButtonST//// Compiler: Visual C++// Tested on: Visual C++ 5.0//// Version: See GetVersionC() or GetVersionI()//// Created: xx/xxxx/1998// Updated: 19/September/1999//// Author: Davide Calabro' davide_calabro@//#ifndef _BTNST_H#define _BTNST_H#if _MSC_VER >= 1000#pragma once#endif // _MSC_VER >= 1000// CBtnST.h : header file//// Comment this if you don't want that CButtonST hilights itself// also when the window is inactive (like happens in Internet Explorer)//#define ST_LIKEIE// Comment this if you don't want to use CMemDC class//#define ST_USE_MEMDC/////////////////////////////////////////////////////////////////////////////// CButtonST windowclass CButtonST : public CButton{// Constructionpublic:CButtonST();~CButtonST();enum {ST_ALIGN_HORIZ, ST_ALIGN_VERT, ST_ALIGN_HORIZ_RIGHT};// Attributespublic:// Operationspublic:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CButtonST)public:virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);virtual BOOL PreTranslateMessage(MSG* pMsg);protected:virtual void PreSubclassWindow();virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);//}}AFX_VIRTUAL// Implementationpublic:void DrawTransparent(BOOL bRepaint = FALSE);BOOL GetDefault();void SetTooltipText(int nId, BOOL bActivate = TRUE);void SetTooltipText(CString* spText, BOOL bActivate = TRUE);void ActivateTooltip(BOOL bEnable = TRUE);BOOL SetBtnCursor(int nCursorId = -1);void SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = FALSE);BOOL GetFlatFocus();void SetDefaultActiveFgColor(BOOL bRepaint = FALSE);void SetActiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE);const COLORREF GetActiveFgColor();void SetDefaultActiveBgColor(BOOL bRepaint = FALSE);void SetActiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE);const COLORREF GetActiveBgColor();void SetDefaultInactiveFgColor(BOOL bRepaint = FALSE);void SetInactiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE);const COLORREF GetInactiveFgColor();void SetDefaultInactiveBgColor(BOOL bRepaint = FALSE);void SetInactiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE);const COLORREF GetInactiveBgColor();void SetShowText(BOOL bShow = TRUE);BOOL GetShowText();void SetAlign(int nAlign);int GetAlign();void SetFlat(BOOL bState = TRUE);BOOL GetFlat();void DrawBorder(BOOL bEnable = TRUE);void SetIcon(int nIconInId, int nIconOutId = NULL);void SetIcon(HICON hIconIn, HICON hIconOut = NULL);static const short GetVersionI();static const char* GetVersionC();protected://{{AFX_MSG(CButtonST)afx_msg void OnCaptureChanged(CWnd *pWnd);afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);afx_msg void OnKillFocus(CWnd* pNewWnd);afx_msg void OnMouseMove(UINT nFlags, CPoint point);afx_msg void OnSysColorChange();//}}AFX_MSGafx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);DECLARE_MESSAGE_MAP()private:void DrawTheIcon(CDC* pDC, CString* title, RECT* rcItem, CRect* captionRect, BOOL IsPressed, BOOL IsDisabled);void InitToolTip();void PaintBk(CDC* pDC);int m_nAlign;BOOL m_bShowText;BOOL m_bDrawBorder;BOOL m_bIsFlat;BOOL m_MouseOnButton;BOOL m_bDrawFlatFocus;HCURSOR m_hCursor;CToolTipCtrl m_ToolTip;HICON m_hIconIn;HICON m_hIconOut;BYTE m_cyIcon;BYTE m_cxIcon;CDC m_dcBk;CBitmap m_bmpBk;CBitmap* m_pbmpOldBk;BOOL m_bDrawTransparent;BOOL m_bIsDefault;COLORREF m_crInactiveBg;COLORREF m_crInactiveFg;COLORREF m_crActiveBg;COLORREF m_crActiveFg;};#ifdef ST_USE_MEMDC//////////////////////////////////////////////////// CMemDC - memory DC//// Author: Keith Rule// Email: keithr@// Copyright 1996-1997, Keith Rule//// You may freely use or modify this code provided this // Copyright is included in all derived versions.//// History - 10/3/97 Fixed scrolling bug.// Added print support.// 25 feb 98 - fixed minor assertion bug//// This class implements a memory Device Contextclass CMemDC : public CDC{// constructor sets up the memory DCCMemDC(CDC* pDC) : CDC(){ASSERT(pDC != NULL);m_pDC = pDC;m_pOldBitmap = NULL;m_bMemDC = !pDC->IsPrinting();if (m_bMemDC) // Create a Memory DC{pDC->GetClipBox(&m_rect);CreateCompatibleDC(pDC);m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());m_pOldBitmap = SelectObject(&m_bitmap);SetWindowOrg(m_rect.left, m_rect.top);}else // Make a copy of the relevent parts of the current DC for printing{m_bPrinting = pDC->m_bPrinting;m_hDC = pDC->m_hDC;m_hAttribDC = pDC->m_hAttribDC;}}// Destructor copies the contents of the mem DC to the original DC~CMemDC(){if (m_bMemDC){// Copy the offscreen bitmap onto the screen.m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY);//Swap back the original bitmap.SelectObject(m_pOldBitmap);} else {// All we need to do is replace the DC with an illegal value,// this keeps us from accidently deleting the handles associated with// the CDC that was passed to the constructor.m_hDC = m_hAttribDC = NULL;}// Allow usage as a pointerCMemDC* operator->() {return this;}// Allow usage as a pointeroperator CMemDC*() {return this;}private:CBitmap m_bitmap; // Offscreen bitmapCBitmap* m_pOldBitmap; // bitmap originally found in CMemDCCDC* m_pDC; // Saves CDC passed in constructorCRect m_rect; // Rectangle of drawing area.BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.};#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCA TION}}// Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif文件BtnST.cpp 源文件#include "stdafx.h"#include "BtnST.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CButtonSTCButtonST::CButtonST(){m_MouseOnButton = FALSE;m_hIconIn = NULL;m_hIconOut = NULL;m_cxIcon = 0;m_cyIcon = 0;m_hCursor = NULL;// Default type is "flat" buttonm_bIsFlat = TRUE;// By default draw border in "flat" buttonm_bDrawBorder = TRUE;// By default icon is aligned horizontallym_nAlign = ST_ALIGN_HORIZ;// By default show the text buttonm_bShowText = TRUE;// By default, for "flat" button, don't draw the focus rect m_bDrawFlatFocus = FALSE;// By default the button is not the default buttonm_bIsDefault = FALSE;SetDefaultInactiveBgColor();SetDefaultInactiveFgColor();SetDefaultActiveBgColor();SetDefaultActiveFgColor();// No tooltip createdm_ToolTip.m_hWnd = NULL;// Do not draw as a transparent buttonm_bDrawTransparent = FALSE;m_pbmpOldBk = NULL;} // End of CButtonSTCButtonST::~CButtonST(){// Restore old bitmap (if any)if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL) {m_dcBk.SelectObject(m_pbmpOldBk);}// Destroy the icons (if any)// Note: the following two lines MUST be here! even if// BoundChecker says they are unnecessary!if (m_hIconIn != NULL) ::DestroyIcon(m_hIconIn);if (m_hIconOut != NULL) ::DestroyIcon(m_hIconOut);// Destroy the cursor (if any)if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);} // End of ~CButtonSTBEGIN_MESSAGE_MAP(CButtonST, CButton)//{{AFX_MSG_MAP(CButtonST)ON_WM_CAPTURECHANGED()ON_WM_SETCURSOR()ON_WM_KILLFOCUS()ON_WM_MOUSEMOVE()ON_WM_CTLCOLOR_REFLECT()ON_WM_SYSCOLORCHANGE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()void CButtonST::SetIcon(int nIconInId, int nIconOutId){HICON hIconIn;HICON hIconOut;HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId), RT_GROUP_ICON);// Set icon when the mouse is IN the buttonhIconIn = (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);// Set icon when the mouse is OUT the buttonhIconOut = (nIconOutId == NULL) ? NULL : (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);SetIcon(hIconIn, hIconOut);/*// Note: the following two lines MUST be here! even if// BoundChecker says they are unnecessary!if (m_hIconIn != NULL) ::DestroyIcon(m_hIconIn);if (m_hIconOut != NULL) ::DestroyIcon(m_hIconOut);// Set icon when the mouse is IN the buttonm_hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);// Set icon when the mouse is OUT the buttonm_hIconOut = (nIconOutId == NULL) ? m_hIconIn : (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);ICONINFO ii;// Get icon dimensionZeroMemory(&ii, sizeof(ICONINFO));::GetIconInfo(m_hIconIn, &ii);m_cxIcon = (BYTE)(ii.xHotspot * 2);m_cyIcon = (BYTE)(ii.yHotspot * 2);::DeleteObject(ii.hbmMask);::DeleteObject(ii.hbmColor);RedrawWindow();*/} // End of SetIconvoid CButtonST::SetIcon(HICON hIconIn, HICON hIconOut){// Note: the following two lines MUST be here! even if// BoundChecker says they are unnecessary!if (m_hIconIn != NULL) ::DestroyIcon(m_hIconIn);if (m_hIconOut != NULL) ::DestroyIcon(m_hIconOut);// Set icon when the mouse is IN the buttonm_hIconIn = hIconIn;// Set icon when the mouse is OUT the buttonm_hIconOut = (hIconOut == NULL) ? m_hIconIn : hIconOut;ICONINFO ii;// Get icon dimensionZeroMemory(&ii, sizeof(ICONINFO));::GetIconInfo(m_hIconIn, &ii);m_cxIcon = (BYTE)(ii.xHotspot * 2);m_cyIcon = (BYTE)(ii.yHotspot * 2);::DeleteObject(ii.hbmMask);::DeleteObject(ii.hbmColor);RedrawWindow();} // End of SetIconBOOL CButtonST::SetBtnCursor(int nCursorId){HINSTANCE hInstResource;// Destroy any previous cursorif (m_hCursor != NULL) ::DestroyCursor(m_hCursor);m_hCursor = NULL;// If we want a cursorif (nCursorId != -1){hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId),RT_GROUP_CURSOR);// Load icon resourcem_hCursor = (HCURSOR)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);// If something wrong then return FALSEif (m_hCursor == NULL) return FALSE;}return TRUE;} // End of SetBtnCursorvoid CButtonST::SetFlat(BOOL bState){m_bIsFlat = bState;Invalidate();} // End of SetFlatBOOL CButtonST::GetFlat(){return m_bIsFlat;} // End of GetFlatvoid CButtonST::SetAlign(int nAlign){switch (nAlign){case ST_ALIGN_HORIZ:m_nAlign = ST_ALIGN_HORIZ;break;case ST_ALIGN_HORIZ_RIGHT:m_nAlign = ST_ALIGN_HORIZ_RIGHT;break;case ST_ALIGN_VERT:m_nAlign = ST_ALIGN_VERT;break;}Invalidate();} // End of SetAlignint CButtonST::GetAlign(){return m_nAlign;} // End of GetAlignvoid CButtonST::DrawBorder(BOOL bEnable){m_bDrawBorder = bEnable;} // End of DrawBorderconst char* CButtonST::GetVersionC(){return "2.6";} // End of GetVersionCconst short CButtonST::GetVersionI(){return 26; // Divide by 10 to get actual version} // End of GetVersionIvoid CButtonST::SetShowText(BOOL bShow){m_bShowText = bShow;Invalidate();} // End of SetShowTextBOOL CButtonST::GetShowText(){return m_bShowText;} // End of GetShowTextvoid CButtonST::OnMouseMove(UINT nFlags, CPoint point){CWnd* pWnd; // Finestra attivaCWnd* pParent; // Finestra che contiene il bottoneCButton::OnMouseMove(nFlags, point);// If the mouse enter the button with the left button pressed// then do nothingif (nFlags & MK_LBUTTON && m_MouseOnButton == FALSE) return;// If our button is not flat then do nothingif (m_bIsFlat == FALSE) return;pWnd = GetActiveWindow();pParent = GetOwner();if ((GetCapture() != this) &&(#ifndef ST_LIKEIEpWnd != NULL &&#endifpParent != NULL)){m_MouseOnButton = TRUE;//SetFocus(); // Thanks Ralph!SetCapture();Invalidate();}else{/*CRect rc;GetClientRect(&rc);if (!rc.PtInRect(point)){*/POINT p2 = point;ClientToScreen(&p2);CWnd* wndUnderMouse = WindowFromPoint(p2);// if (wndUnderMouse != this)if (wndUnderMouse && wndUnderMouse->m_hWnd != this->m_hWnd){// Redraw only if mouse goes outif (m_MouseOnButton == TRUE){m_MouseOnButton = FALSE;Invalidate();}// If user is NOT pressing left button then release capture!if (!(nFlags & MK_LBUTTON)) ReleaseCapture();}}} // End of OnMouseMovevoid CButtonST::OnKillFocus(CWnd * pNewWnd){CButton::OnKillFocus(pNewWnd);// If our button is not flat then do nothingif (m_bIsFlat == FALSE) return;if (m_MouseOnButton == TRUE){m_MouseOnButton = FALSE;Invalidate();}} // End of OnKillFocusvoid CButtonST::OnCaptureChanged(CWnd *pWnd){if (m_MouseOnButton == TRUE){ReleaseCapture();Invalidate();}// Call base message handlerCButton::OnCaptureChanged(pWnd);} // End of OnCaptureChangedvoid CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS) {#ifdef ST_USE_MEMDCCDC *pdrawDC = CDC::FromHandle(lpDIS->hDC); CMemDC memDC(pdrawDC);CDC *pDC = &memDC;#elseCDC* pDC = CDC::FromHandle(lpDIS->hDC);#endifCPen *pOldPen;BOOL bIsPressed = (lpDIS->itemState & ODS_SELECTED); BOOL bIsFocused = (lpDIS->itemState & ODS_FOCUS); BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED);CRect itemRect = lpDIS->rcItem;pDC->SetBkMode(TRANSPARENT);if (m_bIsFlat == FALSE){if (bIsFocused || (GetDefault() == TRUE)){CBrush br(RGB(0,0,0));pDC->FrameRect(&itemRect, &br);itemRect.DeflateRect(1, 1);}}// Prepare draw... paint button's area with background colorCOLORREF bgColor;if ((m_MouseOnButton == TRUE) || (bIsPressed))bgColor = GetActiveBgColor();elsebgColor = GetInactiveBgColor();CBrush br(bgColor);// Draw transparent?if (m_bDrawTransparent == TRUE){PaintBk(pDC);}else{pDC->FillRect(&itemRect, &br);}// Disegno lo sfondo del bottone//CBrush br(GetSysColor(COLOR_BTNFACE));//pDC->FillRect(&itemRect, &br);// Draw pressed buttonif (bIsPressed){if (m_bIsFlat == TRUE){if (m_bDrawBorder == TRUE){pDC->Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));/*CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // Bianco CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Grigio scuro// Disegno i bordi a sinistra e in alto// Dark gray linepOldPen = pDC->SelectObject(&penBtnShadow);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.left, itemRect.top);pDC->LineTo(itemRect.right, itemRect.top);// Disegno i bordi a destra e in basso// White linepDC->SelectObject(penBtnHiLight);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.top-1);//pDC->SelectObject(pOldPen);*/}}else{CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));pDC->FrameRect(&itemRect, &brBtnShadow);}}else // ...else draw non pressed button{CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // WhiteCPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); // Light grayCPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Dark gray CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Blackif (m_bIsFlat == TRUE){if (m_MouseOnButton == TRUE && m_bDrawBorder == TRUE){pDC->Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor (COLOR_BTNSHADOW));/*// Disegno i bordi a sinistra e in alto// White linepOldPen = pDC->SelectObject(&penBtnHiLight);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.left, itemRect.top);pDC->LineTo(itemRect.right, itemRect.top);// Disegno i bordi a destra e in basso// Dark gray linepDC->SelectObject(penBtnShadow);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.top-1);//pDC->SelectObject(pOldPen);*/}}else{// Disegno i bordi a sinistra e in alto// White linepOldPen = pDC->SelectObject(&penBtnHiLight);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.left, itemRect.top);pDC->LineTo(itemRect.right, itemRect.top);// Light gray linepDC->SelectObject(pen3DLight);pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);pDC->LineTo(itemRect.left+1, itemRect.top+1);pDC->LineTo(itemRect.right, itemRect.top+1);// Disegno i bordi a destra e in basso// Black linepDC->SelectObject(pen3DDKShadow);pDC->MoveTo(itemRect.left, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.bottom-1);pDC->LineTo(itemRect.right-1, itemRect.top-1);// Dark gray linepDC->SelectObject(penBtnShadow);pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);pDC->LineTo(itemRect.right-2, itemRect.bottom-2);pDC->LineTo(itemRect.right-2, itemRect.top);//pDC->SelectObject(pOldPen);}}// Read the button's titleCString sTitle;GetWindowText(sTitle);// If we don't want the title displayedif (m_bShowText == FALSE) sTitle.Empty();CRect captionRect = lpDIS->rcItem;// Draw the iconif (m_hIconIn != NULL){DrawTheIcon(pDC, &sTitle, &lpDIS->rcItem, &captionRect, bIsPressed, bIsDisabled); }// Write the button title (if any)if (sTitle.IsEmpty() == FALSE){// Disegno la caption del bottone// Se il bottone e' premuto muovo la captionRect di conseguenzaif (bIsPressed)captionRect.OffsetRect(1, 1);// ONL Y FOR DEBUG// Evidenzia il rettangolo in cui verra' centrata la caption//CBrush brBtnShadow(RGB(255, 0, 0));//pDC->FrameRect(&captionRect, &brBtnShadow);#ifdef ST_USE_MEMDC// Get dialog's fontCFont *pCurrentFont = GetFont();CFont *pOldFont = pDC->SelectObject(pCurrentFont);#endifif ((m_MouseOnButton == TRUE) || (bIsPressed)){pDC->SetTextColor(GetActiveFgColor());pDC->SetBkColor(GetActiveBgColor());}else{pDC->SetTextColor(GetInactiveFgColor());pDC->SetBkColor(GetInactiveBgColor());}// Center textCRect centerRect = captionRect;pDC->DrawText(sTitle, -1, captionRect, DT_SINGLELINE|DT_CALCRECT);captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2);/* RFUcaptionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);*/pDC->SetBkMode(TRANSPARENT);pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),TRUE, 0, (CBrush*)NULL);#ifdef ST_USE_MEMDCpDC->SelectObject(pOldFont);#endif}if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE)){// Draw the focus rectif (bIsFocused){CRect focusRect = itemRect;focusRect.DeflateRect(3, 3);pDC->DrawFocusRect(&focusRect);}}} // End of DrawItemvoid CButtonST::DrawTheIcon(CDC* pDC, CString* title, RECT* rcItem, CRect* captionRect, BOOL IsPressed, BOOL IsDisabled){CRect iconRect = rcItem;CRect btnRect;switch (m_nAlign){case ST_ALIGN_HORIZ:if (title->IsEmpty()){// Center the icon horizontallyiconRect.left += ((iconRect.Width() - m_cxIcon)/2);}else{// L'icona deve vedersi subito dentro il focus recticonRect.left += 3;captionRect->left += m_cxIcon + 3;}// Center the icon verticallyiconRect.top += ((iconRect.Height() - m_cyIcon)/2);break;case ST_ALIGN_HORIZ_RIGHT:GetClientRect(&btnRect);if (title->IsEmpty()){// Center the icon horizontallyiconRect.left += ((iconRect.Width() - m_cxIcon)/2);}else{// L'icona deve vedersi subito dentro il focus rectcaptionRect->right = captionRect->Width() - m_cxIcon - 3;captionRect->left = 3;iconRect.left = btnRect.right - m_cxIcon - 3;// Center the icon verticallyiconRect.top += ((iconRect.Height() - m_cyIcon)/2);}break;case ST_ALIGN_VERT:// Center the icon horizontallyiconRect.left += ((iconRect.Width() - m_cxIcon)/2);if (title->IsEmpty()){// Center the icon verticallyiconRect.top += ((iconRect.Height() - m_cyIcon)/2);}else{captionRect->top += m_cyIcon;}break;}// If button is pressed then press the icon alsoif (IsPressed) iconRect.OffsetRect(1, 1);// Ole'!pDC->DrawState( iconRect.TopLeft(),iconRect.Size(),(m_MouseOnButton == TRUE || IsPressed) ? m_hIconIn : m_hIconOut,(IsDisabled ? DSS_DISABLED : DSS_NORMAL),(CBrush*)NULL);} // End of DrawTheIconvoid CButtonST::PreSubclassWindow(){UINT nBS;nBS = GetButtonStyle();// Check if this is the default buttonif (nBS & BS_DEFPUSHBUTTON) m_bIsDefault = TRUE;// Add BS_OWNERDRAW styleSetButtonStyle(nBS | BS_OWNERDRAW);CButton::PreSubclassWindow();} // End of PreSubclassWindowBOOL CButtonST::PreTranslateMessage(MSG* pMsg){InitToolTip();m_ToolTip.RelayEvent(pMsg);return CButton::PreTranslateMessage(pMsg);} // End of PreTranslateMessageLRESULT CButtonST::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) {if (message == WM_LBUTTONDBLCLK){message = WM_LBUTTONDOWN;}return CButton::DefWindowProc(message, wParam, lParam);} // End of DefWindowProcvoid CButtonST::SetDefaultInactiveBgColor(BOOL bRepaint){m_crInactiveBg = ::GetSysColor(COLOR_BTNFACE);if (bRepaint == TRUE) Invalidate();} // End of SetDefaultInactiveBgColorvoid CButtonST::SetInactiveBgColor(COLORREF crNew, BOOL bRepaint) {m_crInactiveBg = crNew;if (bRepaint == TRUE) Invalidate();} // End of SetInactiveBgColorconst COLORREF CButtonST::GetInactiveBgColor(){return m_crInactiveBg;} // End of GetInactiveBgColorvoid CButtonST::SetDefaultInactiveFgColor(BOOL bRepaint){m_crInactiveFg = ::GetSysColor(COLOR_BTNTEXT);if (bRepaint == TRUE) Invalidate();} // End of SetDefaultInactiveFgColorvoid CButtonST::SetInactiveFgColor(COLORREF crNew, BOOL bRepaint) {m_crInactiveFg = crNew;if (bRepaint == TRUE) Invalidate();} // End of SetInactiveFgColorconst COLORREF CButtonST::GetInactiveFgColor(){return m_crInactiveFg;} // End of GetInactiveFgColorvoid CButtonST::SetDefaultActiveBgColor(BOOL bRepaint){m_crActiveBg = ::GetSysColor(COLOR_BTNFACE);if (bRepaint == TRUE) Invalidate();} // End of SetDefaultActiveBgColorvoid CButtonST::SetActiveBgColor(COLORREF crNew, BOOL bRepaint) {m_crActiveBg = crNew;if (bRepaint == TRUE) Invalidate();} // End of SetActiveBgColorconst COLORREF CButtonST::GetActiveBgColor(){return m_crActiveBg;} // End of GetActiveBgColorvoid CButtonST::SetDefaultActiveFgColor(BOOL bRepaint){m_crActiveFg = ::GetSysColor(COLOR_BTNTEXT);if (bRepaint == TRUE) Invalidate();} // End of SetDefaultActiveFgColorvoid CButtonST::SetActiveFgColor(COLORREF crNew, BOOL bRepaint) {m_crActiveFg = crNew;if (bRepaint == TRUE) Invalidate();} // End of SetActiveFgColorconst COLORREF CButtonST::GetActiveFgColor(){return m_crActiveFg;} // End of GetActiveFgColorvoid CButtonST::SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint) {m_bDrawFlatFocus = bDrawFlatFocus;// Repaint the buttonif (bRepaint == TRUE) Invalidate();} // End of SetFlatFocusBOOL CButtonST::GetFlatFocus(){return m_bDrawFlatFocus;} // End of GetFlatFocusBOOL CButtonST::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) {// If a cursor was specified then use it!if (m_hCursor != NULL){::SetCursor(m_hCursor);return TRUE;}return CButton::OnSetCursor(pWnd, nHitTest, message);} // End of OnSetCursorvoid CButtonST::SetTooltipText(CString* spText, BOOL bActivate){// We cannot accept NULL pointerif (spText == NULL) return;// Initialize ToolTipInitToolTip();// If there is no tooltip defined then add itif (m_ToolTip.GetToolCount() == 0){CRect rectBtn;GetClientRect(rectBtn);m_ToolTip.AddTool(this, (LPCTSTR)*spText, rectBtn, 1);}// Set text for tooltipm_ToolTip.UpdateTipText((LPCTSTR)*spText, this, 1);m_ToolTip.Activate(bActivate);} // End of SetTooltipTextvoid CButtonST::SetTooltipText(int nId, BOOL bActivate){CString sText;// load string resourcesText.LoadString(nId);// If string resource is not emptyif (sText.IsEmpty() == FALSE) SetTooltipText(&sText, bActivate); } // End of SetTooltipTextvoid CButtonST::ActivateTooltip(BOOL bActivate){// If there is no tooltip then do nothingif (m_ToolTip.GetToolCount() == 0) return;// Activate tooltipm_ToolTip.Activate(bActivate);} // End of EnableTooltipBOOL CButtonST::GetDefault(){return m_bIsDefault;} // End of GetDefaultvoid CButtonST::DrawTransparent(BOOL bRepaint){m_bDrawTransparent = TRUE;// Restore old bitmap (if any)if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL){m_dcBk.SelectObject(m_pbmpOldBk);}m_bmpBk.Detach();m_dcBk.Detach();// Repaint the buttonif (bRepaint == TRUE) Invalidate();} // End of DrawTransparentvoid CButtonST::InitToolTip(){if (m_ToolTip.m_hWnd == NULL){// Create ToolTip controlm_ToolTip.Create(this);// Create inactivem_ToolTip.Activate(FALSE);}} // End of InitToolTipvoid CButtonST::PaintBk(CDC * pDC){CClientDC clDC(GetParent());CRect rect;CRect rect1;GetClientRect(rect);GetWindowRect(rect1);GetParent()->ScreenToClient(rect1);if (m_dcBk.m_hDC == NULL){m_dcBk.CreateCompatibleDC(&clDC);m_bmpBk.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);}pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);} // End of PaintBkHBRUSH CButtonST::CtlColor(CDC* pDC, UINT nCtlColor){return (HBRUSH)::GetStockObject(NULL_BRUSH);} // End of CtlColorvoid CButtonST::OnSysColorChange()。

相关文档
最新文档