///////////////////////////////////////////////////////////////////// // DialogWindow.cpp - Demonstrate how to use ATL Window Classes // // to build a Dialog window application. // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2007 // ///////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "DialogWindow.h" #define MAX_LOADSTRING 100 LRESULT CDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) { // dialog manager calls create on the child controls listBox.Attach(GetDlgItem(IDC_LIST1)); edit.Attach(GetDlgItem(IDC_EDIT1)); CenterWindow(); edit.AppendText(L"Enter some text here"); edit.SetSelAll(); edit.SetFocus(); Invalidate(); return 1; } LRESULT CDialog::OnOK(WORD, UINT, HWND, BOOL&) { static int count = 0; std::wostringstream temp; temp << "string #" << ++count << " - "; const int buffLen = 255; wchar_t buffer[buffLen]; edit.GetLine(0,buffer,buffLen); temp << buffer; listBox.InsertString(0,temp.str().c_str()); Invalidate(); edit.SetSelAll(); edit.SetFocus(); return 0; } LRESULT CDialog::OnCancel(WORD, UINT, HWND, BOOL&) { EndDialog(IDOK); PostQuitMessage(0); return 0; } // //----< entry point >------------------------------------------------ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR /* lpCmdLine */, int nCmdShow) { TCHAR szTitle[MAX_LOADSTRING]; // The title bar text LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); HACCEL hAccelTable; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DIALOGWINDOW)); CDialog dlg; dlg.DoModal(); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; }