Search This Blog

Showing posts with label Thread. Show all posts
Showing posts with label Thread. Show all posts

Friday, May 15, 2009

UIThreadImplementation

Create a new class and inherit CWinThread
Add dialog member object in the Thread class


#pragma once
#include "MyDialog.h"
// CMyNewThread

class CMyNewThread : public CWinThread
{
     DECLARE_DYNCREATE(CMyNewThread)

protected:
     CMyNewThread(); // protected constructor used by dynamic creation
     virtual ~CMyNewThread();

public:
     virtual BOOL InitInstance();
     virtual int ExitInstance();

     CMyDialog *m_dlg;

protected:
     DECLARE_MESSAGE_MAP()
};


BOOL CMyNewThread::InitInstance()
{    
     m_dlg = new CMyDialog();
     m_dlg->Create (IDD_DIALOG_MY, NULL);
     m_dlg->ShowWindow( TRUE );
     m_dlg->UpdateWindow();
     return TRUE;

     //return TRUE;
}

// calling the Thread
void CMainFrame::OnNewCreatenewwindow()
{
// TODO: Add your command handler code here
CWinThread *pThread = AfxBeginThread( RUNTIME_CLASS( CMyNewThread ) );
}

Thursday, May 14, 2009

WorkerThread Implementation



class CWorkerThreadImplementationDlg : public CDialog
{
     typedef struct DLG_STRUCT
     {
          CWorkerThreadImplementationDlg* _this;
     }DLG_STRUCT , *PDLGSTRUCT;


void CWorkerThreadImplementationDlg::OnBnClickedOk()
{    
     //CString *cstrValue = new CString("Hai");
     //AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress , (LPVOID)cstrValue );
    
     PDLGSTRUCT lpDLG1 = new DLG_STRUCT;
     lpDLG1->_this = this;
     AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress1 , lpDLG1 );
     PDLGSTRUCT lpDLG2 = new DLG_STRUCT;
     lpDLG2->_this = this;
     AfxBeginThread( CWorkerThreadImplementationDlg::RunProgress2 , lpDLG2 );
}

UINT CWorkerThreadImplementationDlg::RunProgress( LPVOID lpThreadParam )
{
     CString pstr = *((CString*)lpThreadParam);
     return 1;
}

UINT CWorkerThreadImplementationDlg::RunProgress1( LPVOID lpThreadParam )
{
     PDLGSTRUCT pstr = (PDLGSTRUCT)lpThreadParam;
     int nPos = 0;
     while( nPos < 100 )
     {
          pstr->_this->m_Progress1.SetPos( nPos++ );
          Sleep( 100 );
     }
     return 1;
}
UINT CWorkerThreadImplementationDlg::RunProgress2( LPVOID lpThreadParam )
{
     PDLGSTRUCT pstr = (PDLGSTRUCT)lpThreadParam;
     int nPos = 0;
     while( nPos < 100 )
     {
          pstr->_this->m_Progress2.SetPos( nPos++ );
          Sleep( 100 );    
     }
     return 1;
}

Saturday, February 7, 2009

Code to Click Internt Explorer Security warning Dialog Box

//Code to Click Internt Explorer Security warning Dialog Box Automatically

BOOL g_bStopDialogWatcherThread = FALSE; // To Stop & start Thread

UINT WindowWatcher(LPVOID lpParam)
{
g_bStopDialogWatcherThread = FALSE;
while(1)
{
Sleep(300);
HWND hWnd;
HWND hWndWarning = ::FindWindow(NULL,"Internet Explorer");
hWnd=::FindWindowEx(hWndWarning , NULL , "Button","&Yes" );
if(hWnd!=NULL && hWndWarning!=NULL)
{
::SetForegroundWindow(hWndWarning);
::SetFocus(hWnd);
::PostMessage ( hWnd , WM_LBUTTONDOWN , 0 , 0 );
::PostMessage ( hWnd , WM_LBUTTONUP , 0 , 0 );
Sleep(1000);
}

if(g_bStopDialogWatcherThread)
{
break;
}
}
return 1;
}

AfxBeginThread(WindowWatcher,THREAD_PRIORITY_NORMAL,0,0,0);//to start the thread

Thursday, December 18, 2008

MFC Code to Close Task manager Automatically if it is lanched

BOOL g_bStopDialogWatcherThread = FALSE; // To Stop & start Thread

UINT DialogWatcher(LPVOID lpParam)
{
g_bStopDialogWatcherThread = FALSE;
while(1)
{
Sleep(300);
HWND hWnd = ::FindWindow(NULL,"Windows Task Manager");//Windows Task Manager


if(hWnd !=NULL)
{
// ::SetForegroundWindow(hWnd);
// ::SetFocus(hWnd);
// ::SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE );
// ::SendMessage(hWnd,WM_COMMAND,(WPARAM)0x0000025C,(LPARAM)0x0000025C);

::SendMessage(hWnd,WM_CLOSE,0,0);

}

if(g_bStopDialogWatcherThread)
{
break;
}
}
return 1;
}




void CFindWindowDlg::OnbtnClick()
{
AfxBeginThread(DialogWatcher,THREAD_PRIORITY_NORMAL,0,0,0);

}

void CFindWindowDlg::OnCancel()
{
g_bStopDialogWatcherThread = TRUE;
CDialog::OnCancel();
}