iconic21logDlg.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // iconic21ogDlg.cpp : implementation file
  2. //
  3. #include "pch.h"
  4. #include "framework.h"
  5. #include "iconic21log.h"
  6. #include "iconic21logDlg.h"
  7. #include "afxdialogex.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. // Ciconic21ogDlg dialog
  12. Ciconic21ogDlg::Ciconic21ogDlg(CWnd* pParent /*=nullptr*/)
  13. : CDialogEx(IDD_webserver_DIALOG, pParent)
  14. {
  15. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  16. }
  17. void Ciconic21ogDlg::DoDataExchange(CDataExchange* pDX)
  18. {
  19. CDialogEx::DoDataExchange(pDX);
  20. }
  21. BEGIN_MESSAGE_MAP(Ciconic21ogDlg, CDialogEx)
  22. ON_WM_PAINT()
  23. ON_WM_QUERYDRAGICON()
  24. ON_WM_DESTROY()
  25. END_MESSAGE_MAP()
  26. // Ciconic21ogDlg message handlers
  27. BOOL Ciconic21ogDlg::OnInitDialog()
  28. {
  29. CDialogEx::OnInitDialog();
  30. // Set the icon for this dialog. The framework does this automatically
  31. // when the application's main window is not a dialog
  32. SetIcon(m_hIcon, TRUE); // Set big icon
  33. SetIcon(m_hIcon, FALSE); // Set small icon
  34. ShowWindow(SW_SHOWDEFAULT);
  35. // TODO: Add extra initialization here
  36. CRect rtDesk;
  37. CRect rtDlg;
  38. ::GetWindowRect(::GetDesktopWindow(), &rtDesk);
  39. GetWindowRect(&rtDlg);
  40. int iXpos = rtDesk.Width() / 2 - rtDlg.Width() / 2;
  41. int iYpos = rtDesk.Height() / 2 - rtDlg.Height() / 2;
  42. SetWindowPos(NULL, iXpos, iYpos, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
  43. HWND m_wnd = GetSafeHwnd();
  44. m_pwebsocket = weblib::webini();
  45. for (boost::int32_t i = 0; i < MSG_NUM; i++)
  46. {
  47. m_phttpmsg[i] = boost::make_shared<HttpSocket>();
  48. boost::shared_ptr<IIhttpsocket> phttp = m_phttpmsg[i];
  49. weblib::addmsg(m_pwebsocket, phttp);
  50. }
  51. weblib::webrun((void*)m_pwebsocket);
  52. return TRUE; // return TRUE unless you set the focus to a control
  53. }
  54. // If you add a minimize button to your dialog, you will need the code below
  55. // to draw the icon. For MFC applications using the document/view model,
  56. // this is automatically done for you by the framework.
  57. void Ciconic21ogDlg::OnPaint()
  58. {
  59. if (IsIconic())
  60. {
  61. CPaintDC dc(this); // device context for painting
  62. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  63. // Center icon in client rectangle
  64. int cxIcon = GetSystemMetrics(SM_CXICON);
  65. int cyIcon = GetSystemMetrics(SM_CYICON);
  66. CRect rect;
  67. GetClientRect(&rect);
  68. int x = (rect.Width() - cxIcon + 1) / 2;
  69. int y = (rect.Height() - cyIcon + 1) / 2;
  70. // Draw the icon
  71. dc.DrawIcon(x, y, m_hIcon);
  72. }
  73. else
  74. {
  75. CDialogEx::OnPaint();
  76. }
  77. }
  78. // The system calls this function to obtain the cursor to display while the user drags
  79. // the minimized window.
  80. HCURSOR Ciconic21ogDlg::OnQueryDragIcon()
  81. {
  82. return static_cast<HCURSOR>(m_hIcon);
  83. }
  84. void Ciconic21ogDlg::OnDestroy()
  85. {
  86. std::thread thr1([this]() {
  87. for (boost::int32_t i = 0; i < MSG_NUM; i++)
  88. {
  89. m_phttpmsg[i]->stopmsg();
  90. }
  91. weblib::delweb(m_pwebsocket);
  92. CDialogEx::OnDestroy();
  93. });
  94. thr1.detach();
  95. }