Title is No Title

not very good here!

导航

when create a new thread ,always have problem at that:can not turn "" to type long _..."that 's because should put the threadproc in global app.

#include "MainFrm.h"
#include "testPint2Doc.h"
#include "testPint2View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


DWORD WINAPI threadProc()
//long __stdcall CAboutDlg::threadProc()
{
CTime time;
CString m_time;
for(;;)
{
 time=CTime::GetCurrentTime();
 m_time=time.Format("%H:%M:%S");
 AfxMessageBox(m_time);
 //::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_TIME,m_time);
 
 Sleep(1000);
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CTestPint2App

BEGIN_MESSAGE_MAP(CTestPint2App, CWinApp)
 //{{AFX_MSG_MAP(CTestPint2App)
 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  // NOTE - the ClassWizard will add and remove mapping macros here.
  //    DO NOT EDIT what you see in these blocks of generated code!
 //}}AFX_MSG_MAP
 // Standard file based document commands
 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
 // Standard print setup command
 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestPint2App construction

CTestPint2App::CTestPint2App()
{
 // TODO: add construction code here,
 // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTestPint2App object

CTestPint2App theApp;

/////////////////////////////////////////////////////////////////////////////
// CTestPint2App initialization

BOOL CTestPint2App::InitInstance()
{
 AfxEnableControlContainer();

 // Standard initialization
 // If you are not using these features and wish to reduce the size
 //  of your final executable, you should remove from the following
 //  the specific initialization routines you do not need.

#ifdef _AFXDLL
 Enable3dControls();   // Call this when using MFC in a shared DLL
#else
 Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

 // Change the registry key under which our settings are stored.
 // TODO: You should modify this string to be something appropriate
 // such as the name of your company or organization.
 SetRegistryKey(_T("Local AppWizard-Generated Applications"));

 LoadStdProfileSettings();  // Load standard INI file options (including MRU)

 // Register the application's document templates.  Document templates
 //  serve as the connection between documents, frame windows and views.

 CSingleDocTemplate* pDocTemplate;
 pDocTemplate = new CSingleDocTemplate(
  IDR_MAINFRAME,
  RUNTIME_CLASS(CTestPint2Doc),
  RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  RUNTIME_CLASS(CTestPint2View));
 AddDocTemplate(pDocTemplate);

 // Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))
  return FALSE;

 // The one and only window has been initialized, so show and update it.
 m_pMainWnd->ShowWindow(SW_SHOW);
 m_pMainWnd->UpdateWindow();

 return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{

 public :
 DWORD threadId;
 HANDLE hThread;
public:
    //DWORD WINAPI  threadProc();
 //long __stdcall threadProc();
 CAboutDlg();

// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 afx_msg void OnPrint();
 afx_msg void OnThreadBegin();
 afx_msg void OnEndThread();
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
 ON_BN_CLICKED(IDC_Print, OnPrint)
 ON_BN_CLICKED(IDC_ThreadBegin, OnThreadBegin)
 ON_BN_CLICKED(IDC_EndThread, OnEndThread)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CTestPint2App::OnAppAbout()
{
 CAboutDlg aboutDlg;
 aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CTestPint2App message handlers


void CAboutDlg::OnPrint()
{
 CMainFrame *win=(CMainFrame*)AfxGetMainWnd();
 HWND hwin=win->m_hWnd;

 //::SendMessage(hwin,ID_FILE_PRINT,NULL,NULL);
 
 // ::SendMessage(hwin,ID_FILE_PRINT_SETUP,NULL,NULL);
 CWinApp *app=::AfxGetApp();
 CTestPint2View *view =  (CTestPint2View*)win->GetActiveView();
 view->OnFilePrint();
 //CDC *cdc=view->GetDC();
 
 //cdc->TextOut(23,45,"ss");
 //view->OnDraw(cdc);
 //CPrintInfo *pInfo=new CPrintInfo;
 //view->OnPrint(cdc,pInfo);
 //HWND happ=app->m_pMainWnd
 /*
 //------------------
 // Ôö¼ÓÈçÏ´úÂë
char szprinter[80];
char *szDevice,*szDriver,*szOutput;
HDC hdcprint; // ¶¨ÒåÒ»¸öÉ豸»·¾³¾ä±ú
//¶¨ÒåÒ»¸ö´òÓ¡×÷Òµ
static DOCINFO di={sizeof(DOCINFO),"printer",NULL};
// µÃµ½É豸×Ö·û´®´æÈëÊý×észprinterÖÐ
GetProfileString("windows","device",",,,",szprinter,80);
// ½«É豸×Ö·û´®·Ö½â
if(NULL!=(szDevice=strtok(szprinter,","))&&
NULL!=(szDriver=strtok(NULL,","))&&
NULL!=(szOutput=strtok(NULL,",")))
// ´´½¨Ò»¸ö´òÓ¡»úÉ豸¾ä±ú
if((hdcprint=CreateDC(szDriver,szDevice,szOutput,NULL))!=0)
{
if(StartDoc(hdcprint,&di)>0) //¿ªÊ¼Ö´ÐÐÒ»¸ö´òÓ¡×÷Òµ
{
StartPage(hdcprint); //´òÓ¡»ú×ßÖ½,¿ªÊ¼´òÓ¡
SaveDC(hdcprint); //±£´æ´òÓ¡»úÉ豸¾ä±ú
// Êä³öÒ»ÐÐÎÄ×Ö
TextOut(hdcprint,1,1,"ÕâÊÇÒ»¸öÀý×Ó",12);
// Êä³öÒ»ÌõÖ±Ïß
MoveToEx(hdcprint,20,20,NULL);
LineTo(hdcprint,120,120);
RestoreDC(hdcprint,-1); //»Ö¸´´òÓ¡»úÉ豸¾ä±ú
EndPage(hdcprint); //´òÓ¡»úÍ£Ö½,Í£Ö¹´òÓ¡
EndDoc(hdcprint); //½áÊøÒ»¸ö´òÓ¡×÷Òµ
MessageBox("´òÓ¡Íê±Ï!","Ìáʾ",MB_ICONINFORMATION);
}
// ÓÃAPIº¯ÊýDeleteDCÏú»ÙÒ»¸ö´òÓ¡»úÉ豸¾ä±ú
DeleteDC(hdcprint);
}
else
{
MessageBox("ûÓÐĬÈÏ´òÓ¡»ú,»òÕßûÓа²×°´òÓ¡»ú!");
return;
}
*/
}

void CAboutDlg::OnThreadBegin()
{
 hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadProc,NULL,0,&threadId);
}

void CAboutDlg::OnEndThread()
{
TerminateThread(hThread,1);
}

posted on 2004-03-21 20:11  abraham  阅读(386)  评论(0)    收藏  举报