vc/api请问用DialogBox宏创建的对话框怎么得到其对象?附源码
我如下建立一个对话框,得到的只是一个hwnd句柄,
我因此无法想里面添家listbox控件
请问怎么得到这个对话框对象?
#include "stdafx.h"
#include "resource.h"
#include <afxwin.h>
//do not include windows.h in StdAfx.h
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HWND hDlg;
CListBox lb;
DialogBox(
hInstance, // handle to application instance
MAKEINTRESOURCE(IDD_MAIN_DLG), // identifies dialog box template
hDlg, // handle to owner window
(DLGPROC)NULL // pointer to dialog box procedure
);
lb.Create(LBS_EXTENDEDSEL,CRect(1,1,99,99),hDlg,NULL);
AfxMessageBox("delay");
EndDialog(hDlg,0);
return 0;
}
问题点数:20、回复次数:5Top
1 楼huangbeyond(校园人渣)回复于 2001-06-16 17:17:00 得分 10
你建立的对话框,好像还没有“窗口进程”啊??
而且,如果要动态创建一个子窗口或者控件,
应该把创建的代码写在“窗口进程”的WM_INITDIALOG消息处理代码里。
呵呵,你上面的代码,基本是都是错的。 :)Top
2 楼yuhaiyu0344(yuhaiyu0344)回复于 2001-06-16 17:39:00 得分 0
我试试吧Top
3 楼yuhaiyu0344(yuhaiyu0344)回复于 2001-06-16 22:01:00 得分 0
程序我改成这样了,我希望向其中对话框中加入
一个ListBox控件,我应该怎么做呢?
#include "stdafx.h"
#include "resource.h"
//#include <afxwin.h>
//include windows.h in StdAfx.h
INT_PTR CALLBACK SessionsDlgProc( HWND hDlg, UINT msg,
WPARAM wParam, LPARAM lParam )
{
// HRESULT hr;
switch( msg )
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hDlg,0);
break;
}
default:
return FALSE; // Message not handled
}
// Message was handled
return TRUE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
// HWND hDlg;
// CListBox lb;
DialogBox(
hInstance, // handle to application instance
MAKEINTRESOURCE(IDD_MAIN_DLG), // identifies dialog box template
NULL, // handle to owner window
(DLGPROC)&SessionsDlgProc // pointer to dialog box procedure
);
//lb.Create(LBS_EXTENDEDSEL,CRect(1,1,99,99),hDlg,NULL);
// AfxMessageBox("delay");
return 0;
}
Top
4 楼huangbeyond(校园人渣)回复于 2001-06-16 22:06:00 得分 10
case WM_INITDIALOG:
//这里添加建立LISTBOX的代码
break;
建立LISTBOX,使用CreateWindow(),只能使用纯SDK的。Top
5 楼yuhaiyu0344(yuhaiyu0344)回复于 2001-06-17 22:31:00 得分 0
我试试看Top




