473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SetDlgItemText() does not exit

2
Hi,

I have a C++ program that runs fine on Windows 2000 for about 5 yrs now and PC is old, I want to replace this PC and Windows 2000 with a new PC and XP, but when I run this program, it hangs at SetDlgItemText() when it displays a message on screen. If I kill this displaying message then the program continue to run and run fine.

I know very little about C++, I have been using C. Please advise how to make this function to exit correctly as it does on Windows 2000.

Thanks so much.

TTAM
Apr 25 '07 #1
2 2076
Banfa
9,065 Expert Mod 8TB
How about you post the code in question.
Apr 25 '07 #2
ttam
2
Thanks for helping me out.

I deleted a lot of code out of this program, so the post doesn't get too long,
I hope that it still has enough info to see the problem.

Thanks so much,

----------------------------------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. /////////////////////////////////////////////////////////////////////////////
  2. // CDigPotDlg dialog
  3.  
  4. CDigPotDlg::CDigPotDlg(CWnd* pParent /*=NULL*/)
  5.     : CDialog(CDigPotDlg::IDD, pParent)
  6. {
  7.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  8. }
  9.  
  10.  
  11. void CDigPotDlg::DoDataExchange(CDataExchange* pDX)
  12. {
  13.     CDialog::DoDataExchange(pDX);
  14. }
  15.  
  16.  
  17. BEGIN_MESSAGE_MAP(CDigPotDlg, CDialog)
  18.     ON_WM_PAINT()
  19.     ON_WM_QUERYDRAGICON()
  20.     ON_MESSAGE( WM_SERIAL_RX_NOTIFY,OnRxNotify)
  21.     ON_MESSAGE( WM_TX_NOTIFY,OnTxNotify)
  22.     ON_MESSAGE( WM_FRAMING_ERROR_NOTIFY,OnFramingErrorNotify)
  23.     ON_MESSAGE( WM_PARITY_ERROR_NOTIFY,OnParityErrorNotify)
  24.     ON_MESSAGE( WM_HARDWARE_OVERRUN_ERROR_NOTIFY,OnHardwareOverrunErrorNotify)
  25.     ON_MESSAGE( WM_SOFTWARE_OVERRUN_ERROR_NOTIFY,OnSoftwareOverrunErrorNotify)
  26.     ON_MESSAGE( WM_BREAK_DETECT_NOTIFY,OnBreakDetectNotify)
  27. END_MESSAGE_MAP()
  28.  
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CDigPotDlg message handlers
  32.  
  33. BOOL CDigPotDlg::OnInitDialog()
  34. {
  35.     CDialog::OnInitDialog();
  36.  
  37.     m_iPortEvent = OPENPORT;
  38.  
  39.     g_eventwait.ResetEvent();
  40.  
  41.     SetIcon(m_hIcon, TRUE);
  42.     SetIcon(m_hIcon, FALSE);
  43.  
  44.  
  45.     beginPotCal();
  46.  
  47.     return TRUE; 
  48. }
  49.  
  50.  
  51. // If you add a minimize button to your dialog, you will need the code below
  52. //  to draw the icon.  For MFC applications using the document/view model,
  53. //  this is automatically done for you by the framework.
  54.  
  55. void CDigPotDlg::OnPaint() 
  56. {
  57.     if (IsIconic())
  58.     {
  59.         CPaintDC dc(this); // Device context for painting
  60.  
  61.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  62.  
  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.  
  71.         // Draw the icon
  72.         dc.DrawIcon(x, y, m_hIcon);
  73.     }
  74.     else
  75.     {
  76.         CDialog::OnPaint();
  77.     }
  78. }
  79.  
  80.  
  81. // The system calls this to obtain the cursor to display while the user drags
  82. //  the minimized window.
  83. HCURSOR CDigPotDlg::OnQueryDragIcon()
  84. {
  85.     return (HCURSOR) m_hIcon;
  86. }
  87.  
  88.  
  89.  
  90. /*******************************************************************************
  91. * OnRxNotify(): When data is received from the port, window sends a message
  92. *               which calls this fuction.  OnRxNotify tells the application 
  93. *               what is the next step.
  94. ********************************************************************************/ 
  95. LRESULT CDigPotDlg::OnRxNotify( WPARAM wParam, LPARAM lParam )
  96. {
  97.  
  98.     if (EPOT == true)
  99.     {
  100.         EPOT = false;
  101.         exit_attn();
  102.         _exit(1);
  103.     }
  104.  
  105.     if(m_calOffset == true)
  106.     {
  107.  
  108.         if (m_count == 0)
  109.         {
  110.         if(m_result < 0.1)
  111.         {
  112.             failure();
  113.             _exit(1);
  114.         }
  115.         }
  116.  
  117.  
  118.         if(m_result <= adjLimit && result >= -adjLimit)
  119.         {
  120.         storeAllWiperNV();
  121.         complete();
  122.         _exit(1);
  123.         }
  124.     }
  125.       return 1;
  126. }
  127.  
  128.  
  129. /********************************************************************************
  130. * OnTxNotify(): When data is Transmitted to the port, window sends a message
  131. *               which calls this fuction.  This function checks for the errors.
  132. *********************************************************************************/
  133. LRESULT CDigPotDlg::OnTxNotify( WPARAM state, LPARAM )
  134. {
  135.     if ( !m_bErrorNotification )
  136.     {
  137.         return 0;
  138.     }
  139.     return 1;
  140. }
  141.  
  142.  
  143. /********************************************************************************
  144. * beginPotCal(): Opens the USB communication port and begin the Cal
  145. *********************************************************************************/
  146. void CDigPotDlg::beginPotCal() 
  147. {
  148.  
  149.     calOffset();
  150. }
  151.  
  152.  
  153. /********************************************************************************
  154. * OnDestroy() - Call internally by windows. Destroys the dialog window.
  155. *********************************************************************************/
  156. void CDigPotDlg::OnDestroy() 
  157. {
  158.     CDialog::OnDestroy();
  159.     if ( m_pPort ) 
  160.     {
  161.         delete m_pPort;
  162.         m_pPort = 0;
  163.     }
  164. }
  165.  
  166.  
  167. /********************************************************************************
  168. * calOffset() - Setup the application for a offset adjustment. 
  169. *********************************************************************************/
  170. void CDigPotDlg::calOffset()
  171. {
  172.  
  173.     /* Let the operator know the adjustment has begun.
  174.      */
  175.     SetDlgItemText( IDC_STATIC, "Adjusting Offset");
  176.  
  177.     if(!writeDPvoltageDivider())
  178.     {
  179.         failure();
  180.     }
  181. }
  182.  
  183.  
  184. /*******************************************************************************
  185. * writeVale() - Write a value to the EEPROM location
  186. ********************************************************************************/
  187. void CDigPotDlg::writeValue()
  188. {
  189.     /* Let the operator know the adjustment has begun.
  190.      */
  191.      SetDlgItemText( IDC_STATIC, "Write value to EEPROM");
  192.  
  193.     aa_Write(byte,devAddr,m_byteAddress);
  194. }
  195.  
  196.  
  197. /*******************************************************************************
  198. * readValue() - Read a value to the EEPROM location
  199. ********************************************************************************/
  200. void CDigPotDlg::readValue()
  201. {
  202.  
  203.     /* Send the command to retrieve value
  204.      */
  205.      SetDlgItemText( IDC_STATIC, "Read value from EEPROM");
  206.  
  207.     aa_Read(devAddr);
  208. }
  209.  
  210.  
  211. /********************************************************************************
  212. * failure() - This function is called when an error occur
  213. ********************************************************************************/
  214. void CDigPotDlg::failure()
  215. {
  216.     fputs("fail\n",m_fp);
  217.     fputs((LPCTSTR)m_message,m_fp);
  218.     fclose(m_fp);
  219.  
  220.     delete m_pPort;
  221.     m_pPort = 0;
  222.     m_iPortEvent = OPENPORT;
  223.  
  224.     /* Exit the application
  225.      */
  226.     OnOK();
  227. }
  228.  
  229.  
  230. /********************************************************************************
  231. * exit_attn() - Exit the program and close the port
  232. ********************************************************************************/
  233. void CDigPotDlg::exit_attn()
  234. {
  235.  
  236.     if ( m_pPort )
  237.     {
  238.         delete m_pPort;
  239.         m_pPort = 0;
  240.         m_iPortEvent = OPENPORT;
  241.     }
  242.  
  243.     /* Exit the application
  244.      */
  245.     CDialog::OnOK();
  246.     return;
  247. }
  248.  
  249.  
  250. /*******************************************************************************
  251. * complete() is called when an adjustment has been completed
  252. ********************************************************************************/
  253. void CDigPotDlg::complete()
  254. {
  255.  
  256.     /* Close the comm port
  257.      */
  258.     if ( m_pPort )
  259.     {
  260.         delete m_pPort;
  261.         m_pPort = 0;
  262.         m_iPortEvent = OPENPORT;
  263.     }
  264.  
  265.     /* Exit the application
  266.      */
  267.     OnOK();
  268. }
  269.  
  270.  
  271.  
  272. LRESULT CDigPotDlg::OnParityErrorNotify( WPARAM, LPARAM )
  273. {
  274.     int result = m_pPort->ParityError( true );
  275.     return 1;
  276. }
  277.  
  278. LRESULT CDigPotDlg::OnFramingErrorNotify( WPARAM, LPARAM )
  279. {
  280.     int result = m_pPort->FramingError( true );
  281.     return 1;
  282. }
  283.  
  284. LRESULT CDigPotDlg::OnHardwareOverrunErrorNotify( WPARAM, LPARAM )
  285. {
  286.     int result = m_pPort->HardwareOverrunError( true );
  287.     return 1;
  288. }
  289.  
  290. LRESULT CDigPotDlg::OnSoftwareOverrunErrorNotify( WPARAM, LPARAM )
  291. {
  292.     int result = m_pPort->SoftwareOverrunError( true );
  293.     return 1;
  294. }
  295.  
  296. LRESULT CDigPotDlg::OnBreakDetectNotify( WPARAM, LPARAM )
  297. {
  298.     int result = m_pPort->BreakDetect( true );
  299.     return 1;
  300. }
  301.  
Apr 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Xzyx987X | last post by:
Sorry if this is off topic for this group, but I couln't find any place better for directing question on Windows API programming. Here's the problem, I am calling the SetDlgItemText() function to...
3
by: Stuart McGraw | last post by:
I am having a problem creating Access tables linked to a Mysql database. I get the widow to select a Data Source, click on the (system) DSN I created (and tested ok), and click ok. The Database...
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
28
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
16
by: Laurent Deniau | last post by:
I would like to know if the use of the pointer ref in the function cleanup() below is valid or if something in the norm prevents this kind of cross-reference during exit(). I haven't seen anything...
11
by: yawnmoth | last post by:
To quote from <http://php.net/function.include>, "Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value." ...
11
by: =?Utf-8?B?U3RldmVEQjE=?= | last post by:
Hi all. I'm using VS 2008 Express C++. I created a console application back in 1999, and updated it for VC++ 6.0 in 2001. I've updated again this past month, and have found enough differences...
39
by: mathieu | last post by:
Hi there, I am trying to reuse a piece of code that was designed as an application. The code is covered with 'exit' calls. I would like to reuse it as a library. For that I renamed the 'main'...
0
by: Matthew Fitzgibbons | last post by:
Matthew Fitzgibbons wrote: Here's a modified example that _almost_ works: #!/usr/bin/env python import code import time import threading
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.