//模态对话框
在要显示对话框的地方:
DialogBox(hInstance,//实力句柄
MAKEINTRESOURCE(IDD_DIALOG1),//对话框资源ID
hWnd,//父窗口句柄
DlgProc);//处理的窗口过程函数
//窗口处理过程函数
BOOL CALLBACK DlgProc (HWND hDlg, UINT message,WPARAM wParam, LPARAM lParam)
{
int i = 0;
switch (message)
{
case WM_INITDIALOG :
return TRUE ;//对话框初始化处理
case WM_COMMAND : //命令处理
switch (LOWORD (wParam))
{
case IDC_BUTTON1:
//设置服务器地址
char str[50];
GetWindowText(GetDlgItem(hDlg, IDC_IPADDRESS1), str, 16);
m_socket.SetServerAddress(str);
break;
case IDOK :
//设置服务器地址
SetWindowText(GetDlgItem(hDlg, IDC_TEXT), "abc");
case IDCANCEL :
EndDialog (hDlg, 0) ;//关闭对话框
return TRUE ;
}
break ;
}
return FALSE ; //没有处理返回FALSE
}
//非模态对话框
HINSTANCE hInst;
LRESULT MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HWND hMDlg = NULL;
hInst = hInstance;
hMDlg = CreateDialog(hInstance, (LPCTSTR)IDD_DLG_DICT, 0,(DLGPROC)MainDlgProc);
ShowWindow(hMDlg, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
int wmId, wmEvent;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDC_BUTTON_EXIT:
DestroyWindow(hDlg);
break;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
};
return FALSE;//返回FALSE给缺省对话框函数DefDlgProc(),表示没有处理本消息
}