Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 2.50 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. No class or namespace on creating a dialog Box
  2. #pragma once
  3.  
  4. #include "resource.h" // Hauptsymbole
  5. #include <atlhost.h>
  6.  
  7.  
  8. class CTestDlg : public CAxDialogImpl<CTestDlg>
  9. {
  10. private:
  11. bool m_cancel;
  12.  
  13.  
  14. public:
  15. CTestDlg()
  16. {
  17.     m_cancel = true;    
  18. }
  19.  
  20. ~CTestDlg()
  21. {
  22. }
  23.  
  24. enum { IDD = IDD_TESTDLG };
  25.  
  26. BEGIN_MSG_MAP(CTestDlg)
  27. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  28. COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
  29. COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
  30. COMMAND_HANDLER(IDC_EDIT1, EN_CHANGE, OnEnChangeEdit1)
  31. CHAIN_MSG_MAP(CAxDialogImpl<CTestDlg>)
  32. END_MSG_MAP()
  33.  
  34.  
  35.  
  36. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  37. {
  38.     CAxDialogImpl<CTestDlg>::OnInitDialog(uMsg, wParam, lParam, bHandled);
  39.     bHandled = TRUE;
  40.  
  41.     //CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
  42.     //pEdit->SetWindowTextW(L"Hello");
  43.     CWindow textBox(GetDlgItem(IDC_EDIT1));
  44.     textBox.SetWindowTextW(L"hello");
  45.     //textBox.SendMessageW(WM_SETTEXT, 0, (LPARAM)L"test!!!");
  46.     return 1;  // Das System kann den Fokus festlegen
  47. }
  48.  
  49. LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  50. {
  51.     EndDialog(wID);
  52.     m_cancel = false;
  53.     return 0;
  54. }
  55.  
  56. LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  57. {
  58.     EndDialog(wID);
  59.     return 0;
  60. }
  61.  
  62. LRESULT OnEnChangeEdit1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
  63.  
  64. bool IsCancelled() const { return m_cancel; }
  65. bool saveFile();
  66.  
  67. };
  68.        
  69. #include "CTestDlg.h"
  70. #include "stdafx.h"
  71.  
  72.  
  73.  
  74.  
  75. LRESULT CTestDlg::OnEnChangeEdit1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  76. {
  77. return 0;
  78. }
  79.  
  80. bool CTestDlg::saveFile()
  81. {
  82.  
  83. OPENFILENAME ofn;
  84. WCHAR szFileName[MAX_PATH] = L"";
  85.  
  86.  
  87. ZeroMemory( &ofn , sizeof( ofn));
  88.  
  89. ofn.lStructSize = sizeof(ofn);
  90. ofn.hwndOwner = NULL;
  91. ofn.lpstrFilter = (LPCWSTR)L"Text Files (*.txt)*.txtAll Files (*.*)*.*";
  92. ofn.lpstrFile = (LPWSTR)szFileName;
  93. ofn.nMaxFile = MAX_PATH;
  94. ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  95. ofn.lpstrDefExt = (LPCWSTR)L"txt";
  96.  
  97. if(GetSaveFileNameW(&ofn))
  98. {
  99.     HANDLE hFile = CreateFile(ofn.lpstrFile,
  100.         GENERIC_WRITE,
  101.         0,
  102.         NULL,
  103.         CREATE_NEW,
  104.         FILE_ATTRIBUTE_NORMAL,
  105.         NULL);
  106.  
  107.     DWORD dwBytesWritten = 0;
  108.     char str[] = "Example text testing WriteFile";
  109.     WriteFile( hFile, str, strlen(str), &dwBytesWritten, NULL );
  110.     CloseHandle(hFile);
  111.  
  112.     return true;
  113. }
  114. else
  115.     return false;
  116.  
  117. }
  118.        
  119. #include "CTestDlg.h"
  120. #include "stdafx.h"
  121.        
  122. #include "stdafx.h"
  123. #include "CTestDlg.h"