如何获取对话框类的类模板名(lpszTemplateName),其实想通过模板名Create()窗口,这里我不用IDD还有个问题是:我如何才能两次Create这个对话框对象。因为第二次create会失败在
CreateIndirect(hTemplate, pParentWnd, hInst);//就算我之前已经对这个对话框对象进行了 temppage1.SendMessage(WM_CLOSE);
temppage1.SendMessage(WM_DESTROY);
temppage1.DestroyWindow();
temppage1.CreateObject();
temppage1.Create(...);//失败这是我的一个试验~
CreateIndirect(hTemplate, pParentWnd, hInst);//就算我之前已经对这个对话框对象进行了 temppage1.SendMessage(WM_CLOSE);
temppage1.SendMessage(WM_DESTROY);
temppage1.DestroyWindow();
temppage1.CreateObject();
temppage1.Create(...);//失败这是我的一个试验~
解决方案 »
- mfc中如何产生类似飞机炮弹的效果
- 为庆祝我的淘宝小店落地深圳www.v-gd.com,同时纪念和GF分手一周年,写了个修改运行中EXE的演示程序,烦请大家闲余时试验下!
- 100分急问,串口中的流控(又叫线路状态)
- 如何判断拖放过程中鼠标位置
- 请教:UNICODE和_UNICODE的区别及应用领域
- 哪位大虾进来帮小弟分析一下 谢谢
- 用户设定(变量)如何保存?
- 有谁知道如何在VC中得到特殊字符的GBK内码值???快来拿分?
- 这个功能怎么实现?请看。
- 高手留步!关于NDIS网络驱动程序
- 我想运行客户端程序,可总是服务器端程序被编译和执行,vc2003如何选择要执行的工程呢?
- 请问如何在视图中通过ActiveMovieContrilObject播放视频
对话框销毁后可以再次创建,DestroyWindow、Create就可以,不需要发其它消息,不过其它一些地方可能会有所影响,最好重新构造对象。你可以在OnCreate、OnInitDialog函数设置断点调试一下。
其实这个对话框对像我是在一个按纽函数中弹出尝试的~
static CDLG temppage1;//的 当涵数结束还在
我知道了,,这个资源名就是我所说的(lpszTemplateName),我还以为是类模板名.
这样一来,就是IDD和这个lpszTemplateName是不能共存的吗?要么就其中一个?
那么应该都没什么人用CreateDlg(),而用Create()了那么关于CreateEx()它可不可以修改到(他里面有style参数设置应该可以,,,但我不会用~因为有lpszClassName,听说要注册?) 资源创建前 将WS_CHILD转换为WS_POPUP呢? 因为Create()的的参数没有style设置,要modifystyle只有等create后才能~
我的CreateEx()总不成功
我已经用了
WNDCLASS wndclass=
{
CS_DBLCLKS,
// CS_HREDRAW|
// CS_VREDRAW,
//CS_GLOBALCLASS|
//CS_OWNDC|
//CS_PARENTDC|
//CS_NOCLOSE|
AfxWndProc,
0,0,
AfxGetInstanceHandle(),
AfxGetApp()->LoadIcon(IDR_MAINFRAME),
::LoadCursor(NULL,IDC_CROSS),
(HBRUSH)(COLOR_APPWORKSPACE),
NULL/*MAKEINTRESOURCE(IDR_MAINFRAME)*/,
"MyClassName"
};
AfxRegisterClass(&wndclass);
//page1.Create(CSheetPage::IDD,NULL);
page1.CreateEx(0,"MyClassName"
,"aa",WS_POPUPWINDOW,CRect(10,10,500,500),this,CSheetPage::IDD);/////////////////////////////////////////////////////////////////////////
或者用了////////
CString strMyClass; // load stock cursor, brush, and icon for
// my own window class try
{
strMyClass = AfxRegisterWndClass(
CS_VREDRAW | CS_HREDRAW,
::LoadCursor(NULL, IDC_ARROW),
(HBRUSH) ::GetStockObject(WHITE_BRUSH),
::LoadIcon(NULL, IDI_APPLICATION));
}
catch (CResourceException* pEx)
{
AfxMessageBox(
_T("Couldn't register class! (Already registered?)"));
pEx->Delete();
}
page1.CreateEx(0, strMyClass
,"aa",WS_POPUPWINDOW,CRect(10,10,500,500),this,CSheetPage::IDD);////最后的
page1.ShowWindow(SW_SHOW);//都失败~出错,无效句柄 m_hWnd=NULL
第二次Create换一个类名如 temppage2 重新构造
Applications sometimes adapt or modify the content of dialog boxes depending on the current state of the data being processed. In such cases, it is not practical to provide all possible dialog box templates as resources in the application's executable file. But creating templates in memory gives the application more flexibility to adapt to any circumstances. In the following example, the application creates a template in memory for a modal dialog box that contains a message and OK and Help buttons. In a dialog template, all character strings, such as the dialog box and button titles, must be Unicode strings. This example uses the MultiByteToWideChar function to generate these Unicode strings. The DLGITEMTEMPLATE structures in a dialog template must be aligned on DWORD boundaries. To align these structures, this example uses a helper routine that takes an input pointer and returns the closest pointer that is aligned on a DWORD boundary.Example#define ID_HELP 150
#define ID_TEXT 200LPWORD lpwAlign ( LPWORD lpIn)
{
ULONG ul; ul = (ULONG) lpIn;
ul +=3;
ul >>=2;
ul <<=2;
return (LPWORD) ul;
}LRESULT DisplayMyMessage(HINSTANCE hinst, HWND hwndOwner,
LPSTR lpszMessage)
{
HGLOBAL hgbl;
LPDLGTEMPLATE lpdt;
LPDLGITEMTEMPLATE lpdit;
LPWORD lpw;
LPWSTR lpwsz;
LRESULT ret;
int nchar; hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
if (!hgbl)
return -1;
lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
// Define a dialog box.
lpdt->style = WS_POPUP | WS_BORDER | WS_SYSMENU
| DS_MODALFRAME | WS_CAPTION;
lpdt->cdit = 3; // number of controls
lpdt->x = 10; lpdt->y = 10;
lpdt->cx = 100; lpdt->cy = 100; lpw = (LPWORD) (lpdt + 1);
*lpw++ = 0; // no menu
*lpw++ = 0; // predefined dialog box class (by default) lpwsz = (LPWSTR) lpw;
nchar = 1+ MultiByteToWideChar (CP_ACP, 0, "My Dialog",
-1, lpwsz, 50);
lpw += nchar; //-----------------------
// Define an OK button.
//-----------------------
lpw = lpwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
lpdit = (LPDLGITEMTEMPLATE) lpw;
lpdit->x = 10; lpdit->y = 70;
lpdit->cx = 80; lpdit->cy = 20;
lpdit->id = IDOK; // OK button identifier
lpdit->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; lpw = (LPWORD) (lpdit + 1);
*lpw++ = 0xFFFF;
*lpw++ = 0x0080; // button class lpwsz = (LPWSTR) lpw;
nchar = 1+MultiByteToWideChar (CP_ACP, 0, "OK", -1, lpwsz, 50);
lpw += nchar;
lpw = lpwAlign (lpw); // align creation data on DWORD boundary
*lpw++ = 0; // no creation data //-----------------------
// Define a Help button.
//-----------------------
lpw = lpwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
lpdit = (LPDLGITEMTEMPLATE) lpw;
lpdit->x = 55; lpdit->y = 10;
lpdit->cx = 40; lpdit->cy = 20;
lpdit->id = ID_HELP; // Help button identifier
lpdit->style = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; lpw = (LPWORD) (lpdit + 1);
*lpw++ = 0xFFFF;
*lpw++ = 0x0080; // button class atom lpwsz = (LPWSTR) lpw;
nchar = 1+MultiByteToWideChar (CP_ACP, 0, "Help", -1, lpwsz, 50);
lpw += nchar;
lpw = lpwAlign (lpw); // align creation data on DWORD boundary
*lpw++ = 0; // no creation data //-----------------------
// Define a static text control.
//-----------------------
lpw = lpwAlign (lpw); // align DLGITEMTEMPLATE on DWORD boundary
lpdit = (LPDLGITEMTEMPLATE) lpw;
lpdit->x = 10; lpdit->y = 10;
lpdit->cx = 40; lpdit->cy = 20;
lpdit->id = ID_TEXT; // text identifier
lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; lpw = (LPWORD) (lpdit + 1);
*lpw++ = 0xFFFF;
*lpw++ = 0x0082; // static class for (lpwsz = (LPWSTR)lpw;
*lpwsz++ = (WCHAR) *lpszMessage++;
);
lpw = (LPWORD)lpwsz;
lpw = lpwAlign (lpw); // align creation data on DWORD boundary
*lpw++ = 0; // no creation data GlobalUnlock(hgbl);
ret = DialogBoxIndirect(hinst, (LPDLGTEMPLATE) hgbl,
hwndOwner, (DLGPROC) DialogProc);
GlobalFree(hgbl);
return ret;
}