我想让已开始的窗口就是对话框怎么作
谢谢
谢谢
解决方案 »
- VC6.0如何实现把excel中的数据读取后显示在listctrl列表上
- 程序刚开始的一段时间,虚拟内存使用率基本没变化,10分钟后就一直增加,牛人帮分析一下是什么原因
- CreateCaret函数的疑问
- Listbox 怎么才会得到LBN_SELCANCEL
- 谁知道怎么连接到ifix的odbc数据源么,
- 刚开始学习线程,第一个例子就编译不过去
- 有人做过线形算法吗?
- 用install shield 打包时,在程序组中建立快睫方式时,图标始终是用VC建立程序的图标,why
- 数据库问题!急!!!!解决了立即给分!
- CArray<CString,CString>aFilename为什么编译有错???
- 请问大家怎样将对话框中的一个命令按钮资源和一CButton类对象m_Button相连,让我只需对此对象进行操作便能控制那个按钮,同时我就是不知
- 请教如何使得[关机]后,自动关电源啊?
应该就可以了
#include <windowsx.h>
#include <windows.h>BOOL CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);//1 入口
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hDialog=0; //2 createDialog
hDialog = CreateDialog(hInstance,
//identifies dialog box template name
MAKEINTRESOURCE (IDD_DEMO),
// handle to owner window
0,
// pointer to dialog box procedure
DialogProc);
if (!hDialog)
{
char buf[100];
//formats and stores a series of characters and values in a buffer
wsprintf (buf,"Error x%x", GetLastError());
MessageBox(0,buf,"CreateDialog",MB_ICONEXCLAMATION | MB_OK);
return 1;
} MSG msg;
int status;
//3 消息循环
//If message other than WM_QUIT, the return value is nonzero.
//If the WM_QUIT message, the return value is 0.
//If there is an error, the return value is -1.
while ((status=GetMessage(&msg,0,0,0))!=0)
{
if (status==-1)
return -1;
//whether a message is intended for the specified dialog box,
//and if it is, processes the message to the Dialog procedure.
//else ,process the message as usual.
if (!IsDialogMessage(hDialog,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
} //4 dialog procedure
BOOL CALLBACK DialogProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
// inite dialog
case WM_INITDIALOG:
break;
//close the dialog
case WM_CLOSE:
DestroyWindow(hDlg); //send WM_DESTROY
break;
//destroy the window
case WM_DESTROY:
PostQuitMessage(0); //send WM_QUIT,then GetMessage is broken
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDCANCEL:
MessageBox(hDlg,"you click cancel, Dialog will close.\n\n 下次再见!","Dialog test",0);
EndDialog(hDlg,TRUE);
DestroyWindow(hDlg); //send WM_QUIT,then GetMessage is broken
break;
case IDOK:
char szText[128],buf[256];
GetDlgItemText(hDlg,IDC_TXT,szText,sizeof(szText));
wsprintf(buf,"Hello! you click OK.\n\n text is:%s",szText);
MessageBox(hDlg,buf,"Dialog test",0);
break; }
break; default:
return FALSE;
}
return TRUE;
}
#include <windows.h>BOOL CALLBACK DialogProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLSPROC)DialogProc);
return FALSE;
}BOOL CALLBACK DialogProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE; case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg,LOWORD(wParam));
break;
}
return TRUE; default:
break;
} return FALSE;
}
DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLSPROC)DialogProc);
^
为:
DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLGPROC)DialogProc);
^