国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

MFC 通用對(duì)話框之顏色對(duì)話框

這篇具有很好參考價(jià)值的文章主要介紹了MFC 通用對(duì)話框之顏色對(duì)話框。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

CColorDialog類封裝了顏色對(duì)話框,此類允許您將顏色選擇對(duì)話框合并到應(yīng)用程序中。顏色對(duì)話框就像畫家的調(diào)色板一樣,可顯示系統(tǒng)定義的顏色列表,用戶可以從列表中選擇或創(chuàng)建特定顏色。構(gòu)造一個(gè)CColorDialog類對(duì)象后,可用DoModal( )函數(shù)來顯示顏色對(duì)話框。

CColorDialog的構(gòu)造函數(shù)原型如下:

CColorDialog(COLORREF clrInit = 0, DWORD dwFlags = 0, CWnd* pParentWnd = NULL);

參數(shù)

clrInit
默認(rèn)顏色選擇。 如果未指定任何值,則默認(rèn)值為 RGB (0,0,0) (黑色) 。

dwFlags
一組用于自定義對(duì)話框的函數(shù)和外觀的標(biāo)志。 有關(guān)詳細(xì)信息,請(qǐng)參閱 Windows SDK 中的CHOOSECOLOR結(jié)構(gòu)。

pParentWnd
指向?qū)υ捒虻母复翱诨蛩姓叽翱诘闹羔槨?/p>

除DoModal( )函數(shù)外,還有以下幾個(gè)成員函數(shù):

CColorDialog:: GetColor 返回一個(gè)?COLORREF?結(jié)構(gòu),該結(jié)構(gòu)包含選定顏色的值。
CColorDialog::GetSavedCustomColors 檢索用戶創(chuàng)建的自定義顏色。
CColorDialog::SetCurrentColor 強(qiáng)制當(dāng)前顏色選擇指定的顏色。

CCorlorDialog類有一個(gè)CHOOSECOLOR結(jié)構(gòu)類型的公共數(shù)據(jù)成員m_cc, 可以使用?m_cc來實(shí)現(xiàn),設(shè)置顏色對(duì)話框的初始選擇顏色等。CHOOSECOLOR結(jié)構(gòu)定義如下:

typedef struct { 
  DWORD        lStructSize; 
  HWND         hwndOwner; 
  HWND         hInstance; 
  COLORREF     rgbResult; 
  COLORREF   * lpCustColors; 
  DWORD        Flags; 
  LPARAM       lCustData; 
  LPCCHOOKPROC lpfnHook; 
  LPCTSTR      lpTemplateName; 
} CHOOSECOLOR, *LPCHOOSECOLOR; 

其成員功能描述如下(摘自MSDN Library):

lStructSize

Specifies the length, in bytes, of the structure.

hwndOwner

Handle to the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.

hInstance

If the CC_ENABLETEMPLATEHANDLE flag is set in the Flags member, hInstance is a handle to a memory object containing a dialog box template. If the CC_ENABLETEMPLATE flag is set, hInstance is a handle to a module that contains a dialog box template named by the lpTemplateName member. If neither CC_ENABLETEMPLATEHANDLE nor CC_ENABLETEMPLATE is set, this member is ignored.

rgbResult

If the CC_RGBINIT flag is set, rgbResult specifies the color initially selected when the dialog box is created. If the specified color value is not among the available colors, the system selects the nearest solid color available. If rgbResult is zero or CC_RGBINIT is not set, the initially selected color is black. If the user clicks the OK button, rgbResult specifies the user's color selection.

To create a COLORREF color value, use the RGB macro.

lpCustColors

Pointer to an array of 16 COLORREF values that contain red, green, blue (RGB) values for the custom color boxes in the dialog box. If the user modifies these colors, the system updates the array with the new RGB values. To preserve new custom colors between calls to the ChooseColor function, you should allocate static memory for the array.

To create a COLORREF color value, use the RGB macro.

Flags

A set of bit flags that you can use to initialize the Color dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following flags.

Flag Meaning
CC_ANYCOLOR Causes the dialog box to display all available colors in the set of basic colors.
CC_ENABLEHOOK Enables the hook procedure specified in the lpfnHook member of this structure. This flag is used only to initialize the dialog box.
CC_ENABLETEMPLATE Indicates that the hInstance and lpTemplateName members specify a dialog box template to use in place of the default template. This flag is used only to initialize the dialog box.
CC_ENABLETEMPLATEHANDLE Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName member if this flag is specified. This flag is used only to initialize the dialog box.
CC_FULLOPEN Causes the dialog box to display the additional controls that allow the user to create custom colors. If this flag is not set, the user must click the Define Custom Color button to display the custom color controls.
CC_PREVENTFULLOPEN Disables the Define Custom Colors button.
CC_RGBINIT Causes the dialog box to use the color specified in the rgbResult member as the initial color selection.
CC_SHOWHELP Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
CC_SOLIDCOLOR Causes the dialog box to display only solid colors in the set of basic colors.

lCustData

Specifies application-defined data that the system passes to the hook procedure identified by the lpfnHook member. When the system sends the WM_INITDIALOG message to the hook procedure, the message's lParam parameter is a pointer to the CHOOSECOLOR structure specified when the dialog was created. The hook procedure can use this pointer to get the lCustData value.

lpfnHook

Pointer to a CCHookProc hook procedure that can process messages intended for the dialog box. This member is ignored unless the CC_ENABLEHOOK flag is set in the Flags member.

lpTemplateName

Pointer to a null-terminated string that names the dialog box template resource in the module identified by the hInstance member. This template is substituted for the standard dialog box template. For numbered dialog box resources, lpTemplateName can be a value returned by the MAKEINTRESOURCE macro. This member is ignored unless the CC_ENABLETEMPLATE flag is set in the Flags member.

示例(基于演示文件對(duì)話框所創(chuàng)建的單文檔工程):

1. 在IDR_MAINFRAME 菜單文件中新建“ColorDialogTest”菜單,及子菜單“Set Color”、“Draw Line”,如下:

MFC 通用對(duì)話框之顏色對(duì)話框

2. 在視圖類中添加變量mSelCorlor,如下:?

MFC 通用對(duì)話框之顏色對(duì)話框

?3. 為“SetCorlor”添加事件處理程序,如下:

MFC 通用對(duì)話框之顏色對(duì)話框

?代碼如下:

void CFileDialogTestView::OnSetColor()
{
	// TODO: 在此添加命令處理程序代碼
	CColorDialog cdlg(mSelColor);
	cdlg.m_cc.rgbResult = mSelColor;
	if (cdlg.DoModal()==IDOK)
	{
		mSelColor = cdlg.GetColor();
	}
}

4. 為菜單“Draw Line”添加事件處理函數(shù),如下:

MFC 通用對(duì)話框之顏色對(duì)話框

代碼如下:

void CFileDialogTestView::OnDrawLine()
{
	// TODO: 在此添加命令處理程序代碼
	drawType = 2;
}

5.?在視圖類中添加變量endPoint及bDraw,如下:

MFC 通用對(duì)話框之顏色對(duì)話框

MFC 通用對(duì)話框之顏色對(duì)話框

6. 在OnLButtonDown(UINT nFlags, CPoint point)消息處理函數(shù)中加入“case 2:”的對(duì)應(yīng)代碼如下:

void CFileDialogTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值
	CClientDC dc(this);
	switch(drawType)
	{
	case 1:
		TEXTMETRIC tm;
		dc.GetTextMetrics(&tm);
		CreateSolidCaret(tm.tmAveCharWidth / 8, tm.tmHeight);
		//CreateSolidCaret(mLogfont.lfWidth/8, mLogfont.lfHeight);
		SetCaretPos(point);
		ShowCaret();
		startPoint = point;
		mstr.Empty();
		break;
	case 2:
		startPoint = point;
		break;
	default:
		break;
	}
	
	CView::OnLButtonDown(nFlags, point);
}

7. 在視圖類中添加OnMouseMove(UINT nFlags, CPoint point)消息處理函數(shù),代碼如下:

void CFileDialogTestView::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值
	if (bDraw == true)
	{
		CClientDC dc(this);
		INT oldMode = dc.SetROP2(R2_NOT);
		dc.MoveTo(startPoint);
		dc.LineTo(endPoint);
		endPoint = point;
		dc.MoveTo(startPoint);
		dc.LineTo(endPoint);
		dc.SetROP2(oldMode);
		
	}
	CView::OnMouseMove(nFlags, point);
}

8.在視圖類中添加OnLButtonUp(UINT nFlags, CPoint point)消息處理函數(shù),代碼如下:

void CFileDialogTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值
	CClientDC dc(this);
	switch(drawType)
	{
	case 1:
		TEXTMETRIC tm;
		dc.GetTextMetrics(&tm);
		CreateSolidCaret(tm.tmAveCharWidth / 8, tm.tmHeight);
		//CreateSolidCaret(mLogfont.lfWidth/8, mLogfont.lfHeight);
		SetCaretPos(point);
		ShowCaret();
		startPoint = point;
		mstr.Empty();
		break;
	case 2:
		startPoint = point;
		endPoint = point;
		bDraw = true;
		break;
	default:
		break;
	}
	
	CView::OnLButtonDown(nFlags, point);
}

9. 按Ctrl+F5 運(yùn)行程序,然后點(diǎn)擊SetColor菜單

MFC 通用對(duì)話框之顏色對(duì)話框

設(shè)置顏色,如下:

MFC 通用對(duì)話框之顏色對(duì)話框

10. 點(diǎn)擊“Draw Line” 菜單,繪制直線,結(jié)果如下:

MFC 通用對(duì)話框之顏色對(duì)話框

?可見繪制直線的顏色,即是設(shè)置的顏色。文章來源地址http://www.zghlxwxcb.cn/news/detail-457631.html

到了這里,關(guān)于MFC 通用對(duì)話框之顏色對(duì)話框的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • MFC(十三)多個(gè)對(duì)話框

    1.打開類視圖,右鍵項(xiàng)目---類向?qū)?-添加Cpropsheet類,命名為mypropsheet CPropertySheet 是 MFC 的一個(gè)類,用于創(chuàng)建包含多個(gè)屬性頁(yè)的對(duì)話框。它可以使用內(nèi)置的向?qū)J剑蛴脩麸@示“下一步”和“上一步”按鈕 2.在Cmypropsheet.h中,聲明三個(gè)屬性類的對(duì)象 ?3.在構(gòu)造函數(shù)里,把三個(gè)對(duì)

    2024年02月08日
    瀏覽(25)
  • MFC為對(duì)話框資源添加類

    MFC為對(duì)話框資源添加類

    VC6新建一個(gè)對(duì)話框類型的工程; 建立之后資源中默認(rèn)有2個(gè)對(duì)話框,一個(gè)是主對(duì)話框,About這個(gè)是默認(rèn)建立的關(guān)于版權(quán)信息的; 然后主對(duì)話框有對(duì)應(yīng)的.h和.cpp文件;可以在其中進(jìn)行編程; ? 默認(rèn)建立的有一個(gè) 關(guān)于 對(duì)話框; ? 在資源中新插入一個(gè)對(duì)話框,IDD_DIALOG1是對(duì)話框I

    2024年02月01日
    瀏覽(23)
  • MFC 對(duì)話框與控件的使用

    MFC 對(duì)話框與控件的使用

    1、 熟悉 Windows 對(duì)話框應(yīng)用程序開發(fā)的基本過程; 2、 學(xué)習(xí)標(biāo)準(zhǔn)控件的使用; 3、 學(xué)些 CommonDialog ActiveX 控件的使用; 4、 練習(xí)較復(fù)雜的交互式操作的控制流程; 5、 練習(xí)文件輸入/輸出流的使用。 實(shí)現(xiàn)一個(gè)具有一定實(shí)用價(jià)值的通訊錄程序設(shè)計(jì)。界面如圖所示 ①界面的基本設(shè)計(jì)

    2024年02月05日
    瀏覽(26)
  • MFC 給對(duì)話框添加圖片背景

    MFC 給對(duì)話框添加圖片背景

    在windows開發(fā)當(dāng)中做界面的主要技術(shù)之一就是使用MFC,通常我們看到的QQ,360,暴風(fēng)影音這些漂亮的界面都可以用MFC來實(shí)現(xiàn)。今天我們來說一下如何用MFC美化對(duì)話框,默認(rèn)情況下,對(duì)話框的背景如下: 那么,我們?nèi)绾螌⑺谋尘白兂扇缦陆缑婺兀疫€要保留對(duì)話框的移動(dòng)功能,

    2024年02月06日
    瀏覽(27)
  • MFC--對(duì)話框的一個(gè)畫圖控件-HighSpeedChart

    MFC--對(duì)話框的一個(gè)畫圖控件-HighSpeedChart

    下載鏈接在最下面? (免費(fèi)) 可在vs2022,vs2019等vs版本使用 ?成果展示 下載好文件后,將 ?整個(gè)文件夾,添加到項(xiàng)目中,? 1.之后,將控件拖到對(duì)話框里,修改屬性到與圖片相同 ? ???????? 2.為對(duì)話框添加類,我這里添加的是? 3.為控件增加變量,因?yàn)椴皇荲S自帶的控件 4.點(diǎn)

    2024年02月04日
    瀏覽(26)
  • Opencv顯示圖片(MFC基于對(duì)話框窗口)

    Opencv顯示圖片(MFC基于對(duì)話框窗口)

    #1.編輯對(duì)話框按鈕,修改各個(gè)按鈕窗口ID和綁定變量 picture 控件 “打開圖片”按鈕控件 #2.編寫顯示圖片函數(shù) void DrawMat(cv::Mat img, UINT nID); .h文件進(jìn)行聲明 .cpp進(jìn)行定義 #3.定義CString fun_LoadImg();函數(shù) .h文件進(jìn)行聲明 .cpp文件進(jìn)行定義 #4.雙擊“打開圖片”按鈕 系統(tǒng)自動(dòng)彈出響應(yīng)函數(shù)

    2024年04月15日
    瀏覽(38)
  • MFC 單文檔彈出對(duì)話框 標(biāo)題圖標(biāo)

    創(chuàng)建MFC時(shí) 1、應(yīng)用程序類型:以單個(gè)文檔-項(xiàng)目樣式選擇MFC標(biāo)準(zhǔn) 菜單關(guān)聯(lián)對(duì)話框? 2、菜單關(guān)聯(lián)-資源視圖中的Menu-IDR_MAINFRAME(此處看想關(guān)聯(lián)誰(shuí),如果是想關(guān)聯(lián)一個(gè)對(duì)話框,那就先創(chuàng)建一個(gè)對(duì)話框再進(jìn)行關(guān)聯(lián),如果是想關(guān)聯(lián)一個(gè)類,可以看函數(shù)在哪個(gè)類下面從而進(jìn)行關(guān)聯(lián)) a.關(guān)聯(lián)

    2024年02月06日
    瀏覽(21)
  • MFC基于對(duì)話框使用dll進(jìn)行多語(yǔ)言切換

    MFC基于對(duì)話框使用dll進(jìn)行多語(yǔ)言切換

    title: MFC基于對(duì)話框使用dll進(jìn)行多語(yǔ)言切換 categories:[MFC] tags:[音視頻編程] date: 2021/12/15 作者:hackett 微信公眾號(hào):加班猿 Qt使用qm文件切換有兩種加載方式,比較容易一些 在資源文件中加載(這個(gè)比較好): 優(yōu)點(diǎn): 在程序發(fā)布時(shí)不用把最新的.qm文件拷貝到加載路徑中,降低了修

    2024年02月08日
    瀏覽(31)
  • qt學(xué)習(xí):QT對(duì)話框+顏色+文件+字體+輸入

    qt學(xué)習(xí):QT對(duì)話框+顏色+文件+字體+輸入

    目錄 概述 繼承圖 QColorDialog 顏色對(duì)話框 QFileDialog 文件對(duì)話框 保存文件對(duì)話框 QFontDialog 字體對(duì)話框 QInputDialog 輸入對(duì)話框 對(duì)于對(duì)話框的功能,在GUI圖形界面開發(fā)過程,使用是非常多,那么Qt也提供了豐富的對(duì)話框類 QDialog是所有對(duì)話框的基類 QWidget? QDialog QColorDialog 顏色對(duì)話框

    2024年01月21日
    瀏覽(94)
  • MFC為資源對(duì)話框添加消息處理函數(shù)和初始化控件

    MFC為資源對(duì)話框添加消息處理函數(shù)和初始化控件

    現(xiàn)在我VC6新建了一個(gè)對(duì)話框工程;又在資源添加了一個(gè)新的對(duì)話框,并為新的對(duì)話框添加了名為CTestDlg的類; 在主對(duì)話框的cpp文件包含#include \\\"TestDlg.h\\\"; 在主對(duì)話框的cpp文件的OnInitDialog()成員函數(shù)中,添加2句, ?? ?CTestDlg tdlg; ?? ?tdlg.DoModal(); 就可以彈出這個(gè)對(duì)話框; 在新

    2024年01月18日
    瀏覽(32)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包