Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Y

Yves

@Yves
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Create really long timers in MFC
    Y Yves

    With this small class you can create a timer up to 1193 Hours #pragma once #include <string> typedef void (*TIMER_PROC)(UINT idEvent, void* obj); class CTimer { public: enum eTIME_TYPE { eONE_SHOT, ePERIOIDIC }; public: //--CONSTRUCTOR------------------------------------- CTimer(eTIME_TYPE _eType, DWORD _dWaitPeriod, TIMER_PROC _pFunct, LPVOID _pSegment); //--DESTRUCTOR-------------------------------------- virtual ~CTimer(); public: //--PUBLIC METHODS---------------------------------- inline const char* GetErrorMessage(){ return m_szError.c_str(); } UINT Start(); void Stop(); bool SetPeriod(DWORD _dwVal); eTIME_TYPE TimerType() { return m_eTimerType; } UINT GetTimerID(); protected: //--PROTECTED ATTRIBUTES---------------------------- TIMER_PROC m_pCALLBACKFUN; void* m_pSegm; eTIME_TYPE m_eTimerType; DWORD m_WaitPeriod; DWORD m_ThreadID; HANDLE m_hQuitEvent; HANDLE m_hThread; HANDLE m_hAdvisorThread; HANDLE m_hAdvise; HANDLE m_hQuitAdvisor; std::string m_szError; private: //--PRIVATE METHODS--------------------------------- static void TimerThread(void* _pParam); static void AdvisorThread(void* _pParam); }; The implementation //--FILE INCLUDES-------------------------------------------------------- #include <windows.h> #include "Timer.h" //!--CONSTRUCTOR----------------------------------------------------------- // // Method Name: CTimer(..., ...., ...) // /*! Notes Constructor. */ //------------------------------------------------------------------------- CTimer::CTimer(eTIME_TYPE _eType, DWORD _dWaitPeriod, TIMER_PROC _pFunct, LPVOID _pSegment) { m_pCALLBACKFUN = NULL; m_pSegm = NULL; m_eTimerType = _eType; m_WaitPeriod = _dWaitPeriod; if( m_WaitPeriod == 0 ) m_WaitPeriod = 1; m_hThread = m_hAdvisorThread = NULL; m_ThreadID=0; m_pCALLBACKFUN = _pFunct; m_pSegm = _pSegment; m_hQuitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL); m_hQuitAdvisor = ::CreateEvent(NULL, TRUE, FALSE, NULL); m_hAdvise = ::CreateEvent(NULL, FALSE, FALSE, NULL); m_hAdvisorThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AdvisorThread, this, 0, 0); } //!--DESTRUCTOR------------------------------------------------------------- // // Method Name: ~CTimer() // /*!

    C / C++ / MFC c++

  • How do i get the HWND for PostMessage
    Y Yves

    I have a main Dialog application wich instantiate a new Dialog Like this... m_pThread= AfxBeginThread(RUNTIME_CLASS(CMultiThread)); CMultiThread is a CWinThread . This one takes care of Showing the new dialog box on the screen BOOL CMultiThread::InitInstance() { CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } Everythings is working fine. On the ExitInstance() of this thread i want to post a message to the caller (Main Dialog) that CPostDialog is now over. The problem is no matter what i try i can't get the HWND of the caller. I think that i should get the HWND in the InitInstance What i did so far in the main dialog is to declare a public variable like this HWND m_LocalWnd; Then on the OnInitDialog() of the main dialog m_LocalWnd =m_hWnd; Then i change the InitInstance of my CWinThread like this BOOL CMultiThread::InitInstance() { CMessageTestDlg pApp; m_HwndSource = pApp.m_hWnd; CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } CMessageTestDlg is already running and i should be able to get the HWND.. but it always return 0 What is it wrong. Yves Lessard

    C / C++ / MFC question help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups