|
|
|
Hi brothers
I have written one application. This will connect more than 200 machine at a time using WNetAddConnection2(). 75% of machine are connected successfully but rest of them not connected. Error message is ‘The net work path is not found’ (error no 53) . But I can connect manually . If I run the same program, the same machine which is not connected previously is connected this time. But only 75% of machines are connected. I use multithread for connection. Domain, login user and password are ok .
How can solve this problem.
|
|
|
|
|
hi,
I am trying to owner draw a CMenu item. I want to change the color of menu. I changed the background color and text color. But is there any way to change the border color?
nave
-- modified at 0:45 Tuesday 4th April, 2006
|
|
|
|
|
|
|
Hi everyone,
I am trying to develop a Dialog based application for a device communicating through RS 232 serial Port. The serial port receives the new samples of data every 100 milli seconds. I am trying to display the message in a textbox and write the data to a file. For this purpose, i created a thread for receiving data. I am using a Timer with 100 milli seconds for Updating the textbox and writing the received data to the file.
The Problem now i am facing is, when the file gets full, i am trying to display error message and stop the timer. But Timer is not getting stopped by KillTimer().Timer continues in the running state.
BOOL MyDlg::OnInitDialog()
{
....
...
ConfigureSerialPort();
AfxBeginThread(Serial, NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
return TRUE;
}
void CMyDlg::OnClickStart()
{
fp = fopen(file_name,"a");
if (NULL == fp)
{
MessageBox ("Error Writing File",NULL, MB_OK|MB_ICONSTOP);
KillTimer(m_nTimer);
}
m_nTimer = SetTimer(1, 100, NULL);
fprintf(fp,"%d\n",status);
}
void CMyDlg::OnTimer(UINT nIDEvent)
{
OnClickStart();
CDialog::OnTimer(nIDEvent);
}
UINT Serial(LPVOID pParam)
{
while(1)
{
DWORD dwBytesTransferred;
ReadFile (hPort,
inbuf,
60,
&dwBytesTransferred,
NULL);
Sleep(100);
}
return TRUE;
}
Please help me regarding this problem. I am New to MultiThreading Concepts.
Thanks.
Chetan.
Helping others satisfies you...
|
|
|
|
|
chetan210183 wrote: The Problem now i am facing is, when the file gets full, i am trying to display error message and stop the timer. But Timer is not getting stopped by KillTimer().Timer continues in the running state.
This is because you are setting the timer again in OnClickStart . Why are you doing this? You don't have to set it again and again as you are doing now.
chetan210183 wrote: void CMyDlg::OnClickStart()
{
fp = fopen(file_name,"a");
if (NULL == fp)
{
MessageBox ("Error Writing File",NULL, MB_OK|MB_ICONSTOP);
KillTimer(m_nTimer);
}
m_nTimer = SetTimer(1, 100, NULL);
fprintf(fp,"%d\n",status);
}
Look at the lines in bold. You first Kill the timer and then again you set it. So how can you expect it to stop at all.
chetan210183 wrote: void CMyDlg::OnTimer(UINT nIDEvent)
{
OnClickStart();
CDialog::OnTimer(nIDEvent);
}
Again inside the timer function you are calling OnClickStart which in turn again sets the timer.
What you should be doing is...
void CMyDlg::OnClickStart()
{
m_nTimer = SetTimer(1, 100, NULL);
}
And now inside the timer function
void CMyDlg::OnTimer(UINT nIDEvent)
{
fp = fopen(file_name,"a");
if (NULL == fp)
{
MessageBox ("Error Writing File",NULL, MB_OK|MB_ICONSTOP);
KillTimer(m_nTimer);
}
}
Note: Well this is just guess work about what you want to do. You will have to modify the above procedure based on your requirements
Nibu thomas
Software Developer
|
|
|
|
|
Thanks for the Reply.
But without a messagebox, the code excecutes properly. When messageBox is inserted it is leading to infinite loop.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/timers/timerreference/timermessages/wm_timer.asp
In the above link, they have mentioned a statement like below.
"The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue. "
So instead of Timers , can i use threads and loop the function?
I mean replacing the Timers with Threads.
Thanks.
Chetan.
Helping others satisfies you...
|
|
|
|
|
chetan210183 wrote: "The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue. "
Yeah.
chetan210183 wrote: So instead of Timers , can i use threads and loop the function?
I mean replacing the Timers with Threads.
Why not!
Nibu thomas
Software Developer
|
|
|
|
|
Thanks a lot.
Can u please suggest links where i can get sample programs on Threads replacing the Timers.
Please......
Chetan.
Helping others satisfies you...
|
|
|
|
|
chetan210183 wrote: Can u please suggest links where i can get sample programs on Threads replacing the Timers.
Please......
I don't know if this is what you are searching for. Here[^] is it. Well it has got some topics on which multithreading depends. Will make a good reading for you.
Nibu thomas
Software Developer
|
|
|
|
|
You wrote:
void CMyDlg::OnClickStart()
{
fp = fopen(file_name,"a");
if (NULL == fp)
{
MessageBox ("Error Writing File",NULL, MB_OK|MB_ICONSTOP);
KillTimer(m_nTimer);
}
m_nTimer = SetTimer(1, 100, NULL);
fprintf(fp,"%d\n",status);
}
for killing timer use
KillTimer(1);
i.e what ID you provided to set the timer
The Timer returns the timer id when hwnd parameter of the settimer is NULL
hope this is enough for you
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|
|
A_Laxman wrote: for killing timer use
KillTimer(1);
i.e what ID you provided to set the timer
The Timer returns the timer id when hwnd parameter of the settimer is NULL
From MSDN:
Return value of SetTimer:
The timer identifier of the new timer if the function is successful. An application passes this value to the KillTimer member function to kill the timer. Nonzero if successful; otherwise 0.
Nibu thomas
Software Developer
|
|
|
|
|
You can mask the COM port, and wait for events happen in COM port and then only update the text box.
|
|
|
|
|
i want read and write email in lotus notes by VC
who can give me some advice?
thanks!
|
|
|
|
|
i use CreateToolhelp32Snapshot function to seach all the process id ,
but i can not use process id to look for the main frame hwnd!!
can anyone tell me how to find that
Thanks
hi
|
|
|
|
|
Use EnumWindows to enumerate all top level windows. For each window enumerated use the GetWindowThreadProcessId function to filter the windows to those belonging to the desired process.
Steve
|
|
|
|
|
There are a lot of hWnds in a top level window, such as Static, Button, EditBox etc. Using EnumWindow to look for hWnd wastes a lot of resources of system, and makes the system slowly.
Can anybody give me a good idea!! thanks.
hi
|
|
|
|
|
EnumWindows only enumerates top level windows. The procedure I outlined doesn't waste system resources - It's how it's done!
Steve
|
|
|
|
|
|
Here's an example that uses the technique:
------------------------------------------
// Win32App.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <assert.h>
#include <vector>
#include <algorithm>
#include <malloc.h>
typedef std::vector<HWND> HWNDS;
namespace
{
struct EnumInfo
{
DWORD dwProcessID;
HWNDS *pHWNDS;
};
BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
{
const EnumInfo *pInfo = reinterpret_cast<const EnumInfo *>(lParam);
DWORD dwProcessID;
GetWindowThreadProcessId(hWnd, &dwProcessID);
if ( dwProcessID == pInfo->dwProcessID )
{
pInfo->pHWNDS->push_back(hWnd);
}
return TRUE;
}
}
BOOL GetProcessTopLevelWindows( DWORD dwProcessId, HWNDS *pOut )
{
assert(pOut);
EnumInfo ei = {dwProcessId, pOut};
return EnumWindows(&EnumWindowsProc, reinterpret_cast<LPARAM>(&ei));
}
struct ShowWindowTitle
{
bool operator()(HWND hWnd) const
{
int Len = GetWindowTextLength(hWnd);
if ( Len>0 )
{
char *pText = reinterpret_cast<char*>(_alloca(Len+1));
GetWindowText(hWnd, pText, Len+1);
MessageBox(NULL, pText, "Window title", MB_OK);
return true;
}
return false;
}
};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWNDS wins;
if ( GetProcessTopLevelWindows(2216, &wins) ) // PID HARDCODED!
{
std::for_each(wins.begin(), wins.end(), ShowWindowTitle());
}
return 0;
}
Steve
|
|
|
|
|
class AFX_EXT_CLASS ConDlg : public CDialog
{
// Construction
public:
ConDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(ConDlg)
enum { IDD = IDD_DIALOG1 };
CDTPicker m_DateP1;
CDTPicker m_DateP2;
CDTPicker m_TimeP1;
CDTPicker m_TimeP2;
CString m_TypePk;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(ConDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
struct M_Cage my_cage;
CString m_String;
Confused:
why m_cage could be touch while another vaiables such as m_DateP1 and m_String could not?
Lee
-- modified at 23:58 Monday 3rd April, 2006
|
|
|
|
|
Because it is protected. The others are public.
|
|
|
|
|
you did not read his post ...
|
|
|
|