在記憶體建立對話方塊資源

2021-09-24 00:04:32 字數 4298 閱讀 4615

#pragma once

class cbasedyndialog : public cdialog

;public:

dword m_dwdlgexstyle, m_dwdlgstyle; //風格

wchar m_szdlgtitle[128]; //標題

rect m_rcdlgrect; //位置&尺寸

wchar m_szfontface[64]; //字型名稱

word m_wfontpoint; //字型大小

word m_wfontweight; //字型比重

bool m_wfontitalic; //斜體?

lpcwstr m_szdlgmenuid; //選單

lpcwstr m_szdlgclass; //類

public:

bool inittemplate();

bool addcontrol(dword exstyle, dword lstyle, rect rc, dword dwid,

lpcwstr sztitle, word *wclass, int iclasslen,

byte *pbexdata=null, word wextlen=0);

void endtemplateupdate(cwnd *pparent);

public:

bool addbutton(dword lstyle, rect rc, uint uid, lpcwstr stitle);

bool addedit(dword lstyle, rect rc, uint uid, lpcwstr stitle);

public:

virtual int_ptr dodlginmemory(cwnd *pparent);

virtual void onok();

};

#include "stdafx.h"

#include "basednydialog.h"

#include #ifdef _debug

#define new debug_new

#undef this_file

static char this_file = __file__;

#endif

/*windowclass 0xffff +

0x0080 button

0x0081 edit

0x0082 static

0x0083 list box

0x0084 scroll bar

0x0085 combo box

*/implement_dynamic(cbasedyndialog, cdialog)

cbasedyndialog::cbasedyndialog()

cbasedyndialog::~cbasedyndialog()

}//拷貝字串到模板

lpword cbasedyndialog::copywstring (lpword lpwcstr, lpcwstr lpstrin)

*lpwcstr++= (word) *lpstrin;

lpstrin++;

} return lpwcstr;

} //初始化模板

bool cbasedyndialog::inittemplate()

dlgtemplateex;

*/m_itemplateoffset = 0;

m_maxsubitemnums = 0;

word *p = m_pdlgtemplate + m_itemplateoffset;

/* start to fill in the dlgtemplate information, addressing by words */

dword exstyle = m_dwdlgexstyle;

dword lstyle = ds_modalframe | m_dwdlgstyle;

if(m_szfontface[0])

*p++ = 1; // dl**er

*p++ = 0xffff; // signature

*p++ = 0; // loword helpid

*p++ = 0; // hiword helpid

*p++ = loword(exstyle); // loword exstyle

*p++ = hiword(exstyle); // hiword exstyle

*p++ = loword(lstyle); // loword lstyle

*p++ = hiword(lstyle); // hiword lstyle

*p++ = 0; // numberofitems

*p++ = (word)m_rcdlgrect.left; // x

*p++ = (word)m_rcdlgrect.top; // y

*p++ = (word)(m_rcdlgrect.right - m_rcdlgrect.left); // cx

*p++ = (word)(m_rcdlgrect.bottom - m_rcdlgrect.top); // cy

p = copywstring(p, m_szdlgmenuid); // menu

p = copywstring(p, m_szdlgclass); // class

p = copywstring(p, m_szdlgtitle); // title

/* font information because of ds_setfont */

if(lstyle & ds_setfont)

m_itemplateoffset = (long)(ulong_ptr)(p - m_pdlgtemplate);

return true;

}//新增控制項

bool cbasedyndialog::addcontrol(dword exstyle, dword lstyle, rect rc, dword dwid,

lpcwstr sztitle, word *wclass, int iclasslen, byte *pbexdata, word wextlen)

dlgitemtemplateex;

*/__try

//class

p = copywstring(p, sztitle); //text

// advance pointer over nextrastuff word

if(wextlen > 0 && pbexdata)

else

m_itemplateoffset = (long)(ulong_ptr)(p - m_pdlgtemplate);

m_maxsubitemnums++;

} __except(getexceptioncode() == exception_access_violation)

return true;

}//結束模板更新

void cbasedyndialog::endtemplateupdate(cwnd *pparent)

//新增按鈕

bool cbasedyndialog::addbutton(dword lstyle, rect rc, uint uid, lpcwstr stitle)

; return addcontrol(0, lstyle | bs_pushbutton, rc, uid, stitle, wclass, 2);

}//新增編輯框

bool cbasedyndialog::addedit(dword lstyle, rect rc, uint uid, lpcwstr stitle)

; return addcontrol(0, lstyle | ws_border, rc, uid, stitle, wclass, 2);

}///

//應用

int_ptr cbasedyndialog::dodlginmemory(cwnd *pparent)

void cbasedyndialog::onok()

//測試

MFC不使用對話方塊資源模版建立對話方塊

在mfc程式中使用對話方塊時首先在資源模版裡建立對話方塊資源,然後domodal 或者create顯示出模式對話方塊或者非模式對話方塊,這樣建立出的對話方塊移植性差,從乙個工程移動到另乙個工程比較麻煩。如下 建立記憶體對話方塊資源模版類,h檔案 pragma once define dlg temp...

建立簡單對話方塊

簡單對話方塊playgame.cpp在搞了大約乙個星期左右,終於看見想要的框了,不過還不太完善,先寫出這個星期來所學到的問題吧!1.首先要定義資源 resource dialog r dlg player name dialog dlg line 2.接下來編寫對話方塊 executeld 用於裝載...

建立 AlertDialog對話方塊

對話方塊是一種顯示於 activity之上的介面元素,是作為 activity的一部分被建立和顯示的,常用的對話方塊種類有 提示對話方塊 alertdialog 進度對話方塊 progressdialog 日期選擇對話方塊datepickerdialog 時間選擇對話方塊 timepickerdia...