[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

C++ and Smart Card Error

Hi there,

I just develop a c++/mfc  based full screen kiosk which embeded with a web page.

My system short story: If the user didn't insert the smart card(SLE4442), kiosk is only display web page c:\WEBSERVER\home.htm. If the user insert the card and verification is succesfull, the kiosk will change the web page from c:\WEBSERVER\home.htm to C:\WEBSERVER\members.htm. Lastly once user eject the card from the card reader ( ACR20U ), kiosk will change back to c:\WEBSERVER\home.htm

1- c:\WEBSERVER\home.htm <- before insert the smart card
2- c:\WEBSERVER\members.htm <- after insert the smart card
3- c:\WEBSERVER\home.htm <- after eject the smartcard from reader

My problem:

a) It's running OK. but the first page before user insert the card is keep blinking. It blinking with number 1 and number 3. But after user insert the card, the members.htm wont infected with this blinking. Only number 1 and number 2.

Here is my main code:

// SampleDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Sample.h"
#include "SampleDlg.h"

#include "Msg.h"


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

#define            WM_ICON_NOTIFY            WM_USER+10

CFont pToolTipFont;
BOOL m_iskeyUnregistered;
HWND hStartHandle;
CWnd pStartWnd;
CRect rect;
char szModulePath[MAX_PATH];

#define      APP_HOTKEY                              1
#define      OPEN_HOTKEY                              2


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

class CAboutDlg : public CDialog
{
public:
      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
      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)
            // No message handlers
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog

CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CSampleDlg::IDD, pParent)
{
      //{{AFX_DATA_INIT(CSampleDlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
      m_pApp = (CSampleApp*)AfxGetApp();
      m_pBrush.CreateSolidBrush(RGB(236,233,216));
}

void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CSampleDlg)
      DDX_Control(pDX, IDC_EXPLORER1, m_browser);
      
      //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
      //{{AFX_MSG_MAP(CSampleDlg)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_WM_TIMER()
      ON_COMMAND(ID_POPUP_EXIT, OnPopupExit)
      ON_COMMAND(ID_POPUP_LOCKWORKSTATION, OnPopupLockworkstation)
      ON_WM_CTLCOLOR()
      ON_BN_CLICKED(IDC_STATIC_MSG, OnStaticMsg)
      ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers

BOOL CSampleDlg::OnInitDialog()
{
      CDialog::OnInitDialog();

      int m_reader;
      CString csErr;
      

      ModifyStyleEx(WS_EX_APPWINDOW,0);

      // IDM_ABOUTBOX must be in the system command range.
      ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
      ASSERT(IDM_ABOUTBOX < 0xF000);

      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
            CString strAboutMenu;
            strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
                  
            }

                              

      }

      // Set the icon for this dialog.  The framework does this automatically
      //  when the application's main window is not a dialog

      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon
      
      m_reader = AC_Open(ACR_AUTODETECT,AC_USB);
      if ( m_reader < 0 )
      {
            csErr.Format("Reader Not Found : %s",CheckErrRet(m_pApp->g_hReader));
            AfxMessageBox( csErr );
      }
      else
      {
            m_pApp->m_pSession.CardType = AC_AM2KS;
            m_pApp->g_hReader = m_reader;
            GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
            
            UpdateWindow();

            SetTimer(TX_CARD,500,NULL);
      }
      
      int cx, cy;
      HDC dc = ::GetDC(NULL);
      cx = GetDeviceCaps(dc,HORZRES) + GetSystemMetrics(SM_CXBORDER);
      cy = GetDeviceCaps(dc,VERTRES) + GetSystemMetrics(SM_CYBORDER);
      ::ReleaseDC(0,dc);

      // Remove caption and border
      SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & (~(WS_CAPTION | WS_BORDER)));

      // Put window on top and expand it to fill screen
      ::SetWindowPos(m_hWnd, HWND_TOPMOST, - (GetSystemMetrics(SM_CXBORDER)+1), -(GetSystemMetrics(SM_CYBORDER)+1), cx+1,cy+1, SWP_NOZORDER);

      GetModuleFileName(NULL, szModulePath, sizeof(szModulePath));
      strTemp.Format("%s", szModulePath);
//      SetRegValue(HKLM, REG_CHILD_KEY, REG_KEY_NAME, strTemp);
      PostMessage(WM_SIZE, SIZE_MINIMIZED, 0L);

      pToolTipFont.Detach();
      VERIFY(pToolTipFont.CreateFont(
                                       40,                        // nHeight
                                       0,                         // nWidth
                                       0,                         // nEscapement
                                       0,                         // nOrientation
                                       FW_NORMAL,                        // nWeight
                                       TRUE,                      // bItalic
                                       FALSE,                     // bUnderline
                                       0,                         // cStrikeOut
                                       ANSI_CHARSET,              // nCharSet
                                       OUT_DEFAULT_PRECIS,        // nOutPrecision
                                       CLIP_DEFAULT_PRECIS,       // nClipPrecision
                                       DEFAULT_QUALITY,           // nQuality
                                       DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
                                       "Arial Black"));                  // lpszFacename



      if (!m_TrayIcon.Create(NULL,WM_ICON_NOTIFY, _T("Lock Workstation"),  // tooltip
                              (HICON)::LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDR_MAINFRAME)),  // Icon to use
                     IDR_POPUP_MENU))                 // ID of tray icon

      return -1;
      m_TrayIcon.SetMenuDefaultItem(2, TRUE);      

      BOOL bKeySuccess = RegisterHotKey(AfxGetMainWnd()->m_hWnd, OPEN_HOTKEY,MOD_CONTROL | MOD_ALT,VK_SUBTRACT);
      if(!bKeySuccess)
      {
      
    return FALSE;

      }
      // first

      m_browser.Navigate("c:/WEBSERVER/home.htm", NULL, NULL, NULL, NULL);
      //ShowWindow(SW_SHOWMAXIMIZED);
      nPrevCardState = 0x00;

      return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
      if ((nID & 0xFFF0) == IDM_ABOUTBOX)
      {
            CAboutDlg dlgAbout;
            dlgAbout.DoModal();
      }
      else
      {
            CDialog::OnSysCommand(nID, lParam);
      }

      
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSampleDlg::OnPaint()
{
      if (IsIconic())
      {
            CPaintDC dc(this); // device context for painting

            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

            // Center icon in client rectangle
            int cxIcon = GetSystemMetrics(SM_CXICON);
            int cyIcon = GetSystemMetrics(SM_CYICON);
            CRect rect;
            GetClientRect(&rect);
            int x = (rect.Width() - cxIcon + 1) / 2;
            int y = (rect.Height() - cyIcon + 1) / 2;

            // Draw the icon
            dc.DrawIcon(x, y, m_hIcon);

      }
      else
      {
            CDialog::OnPaint();
      }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSampleDlg::OnQueryDragIcon()
{
      return (HCURSOR) m_hIcon;
}

bool CSampleDlg::ReadCard(CARD_INFO *pszCardInfo)
{
      
      BYTE szSW[2]={0};
      CString csTmp;
      CString csCardID;
      CString csTerminalID_0;
      CString csTerminalID_1;
      CString csTerminalID_2;
      CString csExpDate2;
      CString csCardType;
      CString csErr;
      SYSTEMTIME sysExpTime,sysCurr;
      
      GetLocalTime(&sysCurr);
      
      int nRet;
      nRet =       AC_StartSession(m_pApp->g_hReader, &m_pApp->m_pSession);
      if ( nRet < 0 )
            
            return false;
            //AfxMessageBox("Card Error!!!Please Insert Card");

      memset(&m_pApp->m_Apdu,0,sizeof(m_pApp->m_Apdu));
      
      m_pApp->m_Apdu.CLA = 0;
      m_pApp->m_Apdu.INS = ACI_Read;
      m_pApp->m_Apdu.P1 =  0;
      m_pApp->m_Apdu.P2 =  0x00;
      m_pApp->m_Apdu.Lc =  0;
      m_pApp->m_Apdu.Le =  0xC0;
      
      nRet = AC_ExchangeAPDU(m_pApp->g_hReader,&m_pApp->m_Apdu);
      if ( nRet < 0 )
            ;
      else
      {
            szSW[0] = (BYTE)(m_pApp->m_Apdu.Status >> 8 ) & 0xFF;
            szSW[1] = (BYTE)(m_pApp->m_Apdu.Status & 0xFF);
      }
      
      if ( !nRet )
      {
            if (( szSW[0] != 0x90 ) && ( szSW[1] != 0x0 ))
                  return false;
            else
                  AssignData(pszCardInfo);
      }

      int nCheckTemp = atoi(pszCardInfo->szCardID);
      csErr.Format(_T("Number = %d"),nCheckTemp );
      if ( !nCheckTemp )
            return false;
            
      csTmp = pszCardInfo->szCardID;
      csTmp.TrimLeft();csTmp.TrimRight();
      csCardID = csTmp;

      

      WriteLog("Card ID : " + csTmp);

      if ( csTmp.GetLength() < 10 )
            return false;

      csTmp = pszCardInfo->szExpDate2;
      csTmp.TrimLeft();csTmp.TrimRight();
      csExpDate2 = csTmp;

      WriteLog( csTmp );
      memset(&sysExpTime,0,sizeof(sysExpTime));

      sysExpTime.wDay = atoi(csTmp.Left(2));
      sysExpTime.wMonth = atoi(csTmp.Mid(2,2));
      sysExpTime.wYear = atoi(csTmp.Right(4));
      
      csErr.Format("Expiry Date %.4d/%.2d/%.2d", sysExpTime.wYear ,sysExpTime.wMonth ,sysExpTime.wDay );
      WriteLog( csErr );

      COleDateTime ctime1( sysExpTime );
      COleDateTime ctime2( sysCurr );
      
      CMsg m_dlg;
      CString csMsg;

      COleDateTimeSpan ts1 = ctime1 - ctime2;

      if ( ts1.GetTotalSeconds() <= 0 )
      {
            csMsg = "Sorry, your card is Expired";
            m_dlg.csMsg = csMsg;
            m_dlg.DoModal();
            csTmp.Format("Card Expired, %s",pszCardInfo->szCardID);
            WriteLog( csTmp );
            
            return false;
      }
      //AfxMessageBox("Valid Card....\nCard ID : " + csTmp );
      csTmp = pszCardInfo->szTerminalID_0;
      csTmp.TrimLeft();
      csTerminalID_0 = csTmp;

      csTmp = pszCardInfo->szTerminalID_1;
      csTmp.TrimLeft();
      csTerminalID_1 = csTmp;

      csTmp = pszCardInfo->szTerminalID_2;
      csTmp.TrimLeft();
      csTerminalID_2 = csTmp;

      csTmp = pszCardInfo->szCardType;
      csTmp.TrimLeft();
      csCardType = csTmp;

      csMsg = "CARD ID: " + csCardID + "\nDAYS CARD: " + csCardType + "\n\nYOU HAVE VISIT :\n\n" + csTerminalID_0 + "\n" + csTerminalID_1 + "\n" + csTerminalID_2 + "\n\n" + "EXPIRY DATE : " + csExpDate2;
      
      m_dlg.csMsg = csMsg;
      m_dlg.DoModal();
      // Third
      m_browser.Navigate(("c:/WEBSERVER/members.htm"), NULL, NULL, NULL, NULL);
      //ShowWindow(SW_SHOWMAXIMIZED);
      
      nPrevCardState = 0x00;

      
      DisableStartButton(FALSE);
      return TRUE;
}

void CSampleDlg::AssignData(CARD_INFO *pszInfo)
{
      TCHAR g_szRspbuf[1000];
      TCHAR *g_pszRsp;
      
      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(int i=16 ; i < 26; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szCardID,_T("%s"),g_szRspbuf);
      
      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=26 ; i < 34; i++)
      {      
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szDate ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=34 ; i < 42; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szCardType,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=42 ; i < 50; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTime,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=50 ; i < 58; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalCounter ,_T("%s"),g_szRspbuf);
//start      
      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=58 ; i < 66; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_0 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=66 ; i < 74; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }

      wsprintf(pszInfo->szTerminalID_1 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=74 ; i < 82; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_2 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=82 ; i < 90; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_3 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=90 ; i < 98; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_4 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=98 ; i < 106; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_5 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=106 ; i < 114; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_6 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=114 ; i < 122; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_7 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=122 ; i < 130; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_8 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=130 ; i < 138; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_9 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=138 ; i < 146; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szTerminalID_10 ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=146 ; i < 152; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szPinNumber ,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=154 ; i < 162; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szExpDate1,_T("%s"),g_szRspbuf);

      g_pszRsp = g_szRspbuf;
      wsprintf(g_pszRsp,_T(""));

      for(i=162 ; i < 170; i++)
      {
            wsprintf(g_pszRsp,_T("%c"),m_pApp->m_Apdu.DataOut[i]);
            g_pszRsp++;
      }
      
      wsprintf(pszInfo->szExpDate2 ,_T("%s"),g_szRspbuf);

}

void CSampleDlg::OnTimer(UINT nIDEvent)
{
      int nRet = 0;
      
      if ( nIDEvent == TX_CARD )
      {
            nRet = AC_GetInfo(m_pApp->g_hReader,&m_pApp->m_pInfo);
            if (!nRet)
            {
                  if (m_pApp->m_pInfo.CStat == 0x00)
                  {
                        
                  GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
                  DisableStartButton(TRUE);
                  //page3
            
            
                  m_browser.Navigate("c:/WEBSERVER/home.htm", NULL, NULL, NULL, NULL);
            //      ShowWindow(SW_SHOWMAXIMIZED);
                  nPrevCardState = 0x00;

      
                  }

                  else if (m_pApp->m_pInfo.CStat == 0x01)
                  
                  {
                        GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please insert card"));
                        
                        if (!ReadCard(&m_pApp->m_CardInfo))
                        {
                              GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Card Error"));
                              WriteLog("Card Error...");
      
                              CMsg m_dlg;
                              CString csMsg;
                                                            
                              csMsg = "Sorry, your card is invalid.";
                                                            
                              m_dlg.csMsg = csMsg;
                              m_dlg.DoModal();
                              
                              
                        }
                        
                  }
                  
            }
            
      }

      nPrevCardState = m_pApp->m_pInfo.CStat;

      CDialog::OnTimer(nIDEvent);
      
}

void CSampleDlg::WriteLog(CString csLog)
{
      TCHAR szLog[100];
      SYSTEMTIME sysDate;

      memset(&sysDate,0,sizeof(sysDate));
      GetLocalTime(&sysDate);

      FILE *fp = fopen("c:\\CardLog.txt","a+");
      if (!fp)
            return;

      wsprintf(szLog,"DATE : %.2d/%.2d/%.4d\tTIME : %.2d:%.2d:%.2d\t[LOG]\t%s\n",sysDate.wDay,sysDate.wMonth,sysDate.wYear,sysDate.wHour,sysDate.wMinute,sysDate.wSecond,csLog);
      fputs(szLog,fp);
      fclose(fp);

}

void CSampleDlg::DisableStartButton(BOOL bDisable)
{
      if (bDisable)
      {
            BOOL m_isKeyRegistered = RegisterHotKey(GetSafeHwnd(), APP_HOTKEY,      MOD_ALT, VK_TAB);
            SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, NULL, SPIF_SENDCHANGE);
            SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
            CString szText;
            hStartHandle = FindWindowEx(0, 0, "Shell_TrayWnd", NULL);
            pStartWnd.m_hWnd=hStartHandle;
             pStartWnd.EnableWindow(TRUE);
            ShowWindow(SW_SHOW);
            ShowCursor(TRUE);
            
      //      DisableCtrlAltDelete(bDisable);
      //      SetRegValue(HKLM, TASK_MANAGER, DISABLE_TASK, 1);            //Disabling Ctrl+Alt+Del
      //      SetRegValue(HKCU, TASK_MANAGER, DISABLE_TASK, 1);            //Disabling Ctrl+Alt+Del

      
      }
      
      else
      {
            CString szText;
            UnregisterHotKey(AfxGetMainWnd()->m_hWnd, APP_HOTKEY);
            SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, NULL, SPIF_SENDCHANGE);
            hStartHandle = FindWindowEx(0, 0, "Shell_TrayWnd", NULL);
            pStartWnd.m_hWnd=hStartHandle;
      
       pStartWnd.EnableWindow(TRUE);
      //      SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

      //      DisableCtrlAltDelete(bDisable);
      //      SetRegValue(HKLM, TASK_MANAGER, DISABLE_TASK, 1);            //Disabling Ctrl+Alt+Del
      //      SetRegValue(HKCU, TASK_MANAGER, DISABLE_TASK, 1);            //Disabling Ctrl+Alt+Del
            ShowWindow(SW_SHOW);
            ShowCursor(TRUE);
            
            
      }
}

void CSampleDlg::OnPopupExit()
{
      DisableStartButton(FALSE);
      KillTimer(TX_CARD);      
      EndDialog(0);
      
}

void CSampleDlg::OnPopupLockworkstation()
{
            
}

HBRUSH CSampleDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      return m_pBrush;
}
void CSampleDlg::DisableCtrlAltDelete(bool bDisabled)
{
    SystemParametersInfo (SPI_SCREENSAVERRUNNING,bDisabled,
    NULL,NULL);
}

void CSampleDlg::OnStaticMsg()
{
      // TODO: Add your control notification handler code here
      
}



BEGIN_EVENTSINK_MAP(CSampleDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CSampleDlg)
      ON_EVENT(CSampleDlg, IDC_EXPLORER1, 102 /* StatusTextChange */, OnStatusTextChangeExplorer1, VTS_BSTR)
      //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CSampleDlg::OnStatusTextChangeExplorer1(LPCTSTR Text)
{
      // TODO: Add your control notification handler code here

}

void CSampleDlg::OnButton1()
{
      // TODO: Add your control notification handler code here
      
}
0
operation1611
Asked:
operation1611
  • 4
1 Solution
 
novitiateCommented:
At first glance, the blink looks more than obvious.

perhaps its got to do with this...

SetTimer(TX_CARD,500,NULL);

void CSampleDlg::OnTimer(UINT nIDEvent)
{
     int nRet = 0;
     
     if ( nIDEvent == TX_CARD )
     {
          nRet = AC_GetInfo(m_pApp->g_hReader,&m_pApp->m_pInfo);
          if (!nRet)
          {
               if (m_pApp->m_pInfo.CStat == 0x00)
               {
                   
               GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
               DisableStartButton(TRUE);
               //page3
         
         
               m_browser.Navigate("c:/WEBSERVER/home.htm", NULL, NULL, NULL, NULL);


_novi_
0
 
operation1611Author Commented:
Thanks for reply..

I got this error:

SampleDlg.cpp
D:\Development\C++\SAMPLE\SampleDlg.cpp(628) : error C2501: 'SetTimer' : missing storage-class or type specifiers
D:\Development\C++\SAMPLE\SampleDlg.cpp(628) : error C2373: 'SetTimer' : redefinition; different type modifiers
        C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winuser.h(4478) : see declaration of 'SetTimer'
D:\Development\C++\SAMPLE\SampleDlg.cpp(628) : error C2078: too many initializers
Error executing cl.exe.
Creating browse info file...

Sample.exe - 3 error(s), 0 warning(s)
0
 
operation1611Author Commented:
if i do two of below, the page is still blinking:

1)
void CSampleDlg::OnTimer(UINT nIDEvent)
{
      int nRet = 0;
      SetTimer(TX_CARD,500,NULL);

      if ( nIDEvent == TX_CARD )
      {
            
            nRet = AC_GetInfo(m_pApp->g_hReader,&m_pApp->m_pInfo);
            if (!nRet)
            {
                  if (m_pApp->m_pInfo.CStat == 0x00)
                  {
                        
                  GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
                  DisableStartButton(TRUE);
                  //page3

2)

void CSampleDlg::OnTimer(UINT nIDEvent)
{
      int nRet = 0;
      
      if ( nIDEvent == TX_CARD )
      {
            SetTimer(TX_CARD,500,NULL);

            nRet = AC_GetInfo(m_pApp->g_hReader,&m_pApp->m_pInfo);
            if (!nRet)
            {
                  if (m_pApp->m_pInfo.CStat == 0x00)
                  {
                        
                  GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
                  DisableStartButton(TRUE);
                  //page3
0
 
operation1611Author Commented:
THANKS...

I just notice that the value of the time is only 500...when i change to
SetTimer(TX_CARD,999999,NULL);...the page wont blink anymore...

thanks a lot
0
 
operation1611Author Commented:
ops...sorry...it's true the page wont blink again...

but when the card is insert to the reader....the reader wont read it immediately,...maybe it takes the same value as 999999 to read the card

I insert the SetTimer(TX_CARD,500,NULL); as below


void CSampleDlg::OnTimer(UINT nIDEvent)
{
     int nRet = 0;
     SetTimer(TX_CARD,500,NULL);

     if ( nIDEvent == TX_CARD )
     {
         
          nRet = AC_GetInfo(m_pApp->g_hReader,&m_pApp->m_pInfo);
          if (!nRet)
          {
               if (m_pApp->m_pInfo.CStat == 0x00)
               {
                   
               GetDlgItem(IDC_STATIC_MSG)->SetWindowText(_T("Please Insert Card"));
               DisableStartButton(TRUE);
               //page3
 
 
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now