|
Hi,
currently I work with a CSocket derived class to poll UDP servers and receive some packets from them. But there's one function CSocket does not seem to provide: A timeout for the receive function. I want my program to wait no longer than 1 second for the server packet receival. Is there a way to accomplish this?
thanks in advance
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You might want to try using CAsyncSocket instead. From the MSDN, it appears to give you more control over blocking.
Another option would be to have a 'watchdog' thread. Each time the receive thread tries to read a packet, it should reset the watchdog timer. The watchdog thread waits for the watchdog timer to expire. If the timer ever expires, the watchdog thread handles the timeout condition, perhaps by terminating the receive thread, closing the socket (which will return an error to the receive thread), or whatever action is appropriate to your application.
Software Zen: delete this;
|
|
|
|
|
Thanks!
I tried a simple timer (without a second thread). Seems to work fine however
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi all
I am wondering where i can find some information or example about how to create a new moniker of a program, especially url moniker. i've read the articles in MSDN about moniker, but it doesn't tell how to implement the interfaces and others.
anybody can provide me some articles or books i can find that in?
|
|
|
|
|
I am new to programming but I need to make a message box pop up on my screen everday at 5pm. From what I understand I need to use the ontimer function to do this. I was given some instructions on how to do it in the past but I didn't understand enough of the terms to do what was being talked about. Does anyone have some source code with some simple instructions that show how I could do this? Thank you very much. Mavrock
|
|
|
|
|
Well, you can use WM_TIMER, but I wonder if you'd be better off figuring out how to poll the system clock. Obviously you still need to use a timer, but it would be more reliable than trusting the timer alone. Create an MFC project, dialog based, hit CTRL_W to bring up the class wizard, add an OnTimer message handler. In your initial code add something like:
SetTimer(42, 60000, NULL);
Then in your OnTimer, check the timer id to see if it's 42, if it is, check the time and then either reset the timer for another minute, or show your message box.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
How can i detect the current system XP color scheme...
|
|
|
|
|
I'm working on an ATL Control for performing some graphic operations to be deployed to users in VB. I've got all my properties persisting etc, but while the control is in the development environment, and a property is changes, how do I get the windows to redraw ??
Currently the form containing the control must be closed, and then reopened.. There must be a better way.
This control doesn't use MFC.
|
|
|
|
|
Never mind, after further searching I found the answer.
You have to Call FireViewChange() after changing a property value.
http://msdn.microsoft.com/library/en-us/vcmfc98/html/vcconexampleimplementingpropertypage.asp?frame=true
|
|
|
|
|
just wondering, how to "calculate" average "request per second" given the number of employee in an organisation?
i need this figure so that I can conduct a test with Application Test Center
Thanks.
norm
|
|
|
|
|
What do you mean ? Are you asking about asp page requests ( I'm guessing based on what else you've been asking about ) ? If so, this is the wrong forum, and there is no real way to answer it. Are the employees going to use your system non-stop ? How long will they look at each page ? There are a lot of variables to consider.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Just want to general direction. I wish SQL server to notify a windows service i write everytime table schema has been altered as opposed to having the service to periodically poll the database via ADO or ODBC (that'll work, but a bit amateur). Yet one other option is to monitor transaction log for ALTER DATABASE. Is it true that this must be done thru DMO? and direct access to trn files should be avoided?
i was thinking triggers, but they are for insert/update/delete
is there any "trigger" for schema change, say, drop column? ALTER DATABASE? Once this problem is solved, I can communicate with a Windows Service via one of the following mechanism...
OPTION 1: OLE Automation Procedures: Allows standard OLE automation objects to be used within a standard Transact-SQL batch. So, I'll use a stored procedure to invoke a COM server to inform the windows service that table schema has been changed.
For instance:
sp_OACreate progid, | clsid,
objecttoken OUTPUT
[ , context ]
OPTION 2: xp_cmdshell (security concern)
OPTION 3: DTS to export schema to a flat file.
Unfortunately, All requires some sort of mechanism that invoke the store procedure or DTS package. And Triggers cant do the job.
Any suggestion?
norm
|
|
|
|
|
Hi,
I just need to need how to play a midi instrument sound... Please, not how to playback midi-files - just how to play different notes!!!
I have currently got a working program using only MFC that reads the midi-in, but I might switch to directX if that is easier to implement...
(I am trying to write a program that reads tones from midi-in, and then plays three notes tango-style based on the note hit on the midi-keyboard...)
Thanks alot,
|
|
|
|
|
Is there a sure fire way of predicting a dialog's rectangle without creating it?
Happy programming!!
|
|
|
|
|
I've not done this, but it appears you can find this information out by loading the dialog resource into memory without actually creating the dialog. Look up the functions FindResource , LoadResource , and LockResource for how to load the dialog resource into memory. Look up function CreateDialogIndirect and structure DLGTEMPLATE for information on what the memory looks like.
Software Zen: delete this;
|
|
|
|
|
I'm having difficulty with implementing a custom MFC control on an eVC Pocket PC dialog-type application. I create a custom control derived from CStatic following the methods of the CDoubleListPicker custom control example I found on this site, and when I run the program I can see the caption fine, but not the sub-controls that are created in my custon control.
Just to check on this problem, I took the CDoubleListPicker application and ported it to eVC, basically taking out things that aren't supported by the eVC environment, like the about box and resizing of the dialog. When I run this program, I have the same problem that none of the internal controls of CDoubleListPicker appear. I really made an effort to only take out the code that the compiler gave errors on, so I don't think I took out anything critical.
I will admit that I am only running this on the emulator, as my new device has not arrived yet, but I wanted to get a head start on programming...
Here's the class that I created, as well as what I think are the most critical functions.... Note that in the app I added a CStatic object to the dialog using the graphical dialog editor, and associated this control with the variable m_FileChooser of type CFileChooser (the custom control class).
Any help would be appreciated.
class CFileChooser : public CStatic
{
public:
CFileChooser();
public:
#define ID_BASE_ID ((UINT)-1)
enum {
ID_DIR_DROP_BOX = (ID_BASE_ID - 1),
ID_FILE_LIST_BOX = (ID_BASE_ID - 2),
};
public:
public:
virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
protected:
virtual void PreSubclassWindow();
public:
virtual ~CFileChooser();
protected:
void DoSizing();
int CreateChildControls();
CComboBox m_dirDropBox;
CListBox m_fileListBox;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnEnable(BOOL bEnable);
DECLARE_MESSAGE_MAP()
};
int CFileChooser::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
if (!CreateChildControls())
return -1;
return 0;
}
void CFileChooser::PreSubclassWindow()
{
CStatic::PreSubclassWindow();
SetWindowText(_T("FileChooser"));
ModifyStyleEx(WS_EX_STATICEDGE, 0);
CreateChildControls();
DoSizing();
}
int CFileChooser::CreateChildControls()
{
if (m_dirDropBox.GetSafeHwnd() != NULL)
return TRUE;
CWnd* pParent = GetParent();
if (pParent == NULL)
return FALSE;
CRect rc(0, 0, 0, 0);
if (!m_dirDropBox.Create(DW_DROP_STYLE, rc, pParent, ID_DIR_DROP_BOX))
return FALSE;
if (!m_fileListBox.Create(LBS_MULTIPLESEL|DW_LIST_STYLE, rc, pParent, ID_FILE_LIST_BOX))
return FALSE;
BOOL bEnable = IsWindowEnabled();
BOOL bShow = (GetStyle() & WS_VISIBLE);
m_dirDropBox.EnableWindow(bEnable);
m_dirDropBox.ShowWindow(bShow ? SW_SHOW : SW_HIDE);
m_fileListBox.EnableWindow(bEnable);
m_fileListBox.ShowWindow(bShow ? SW_SHOW : SW_HIDE);
return TRUE;
}
void CFileChooser::DoSizing()
{
if (m_dirDropBox.GetSafeHwnd() == NULL)
return;
if (GetParent() == NULL)
return;
CRect rc;
GetWindowRect(&rc);
GetParent()->ScreenToClient(&rc);
m_dirDropBox.ShowWindow(GetStyle() & WS_VISIBLE ? SW_SHOW : SW_HIDE);
m_dirDropBox.MoveWindow(rc.left, rc.top, rc.Width(), DROP_BOX_SIZE);
rc.top += BOX_CTRL_GAP + DROP_BOX_SIZE;
m_fileListBox.MoveWindow(rc.left, rc.top, rc.Width(), rc.Height());
RedrawWindow();
m_dirDropBox.RedrawWindow();
m_fileListBox.RedrawWindow();
}
- Kati
|
|
|
|
|
In order to do this so my edit control can be resized everytime the text changes I assume I have to use SendMessage(hwndEditCtrl, EM_SETMARGINS, EC_USEFONTINFO, NULL); I have yet to accomplish this task...Can anyone give some advice as to how to approach this problem?
|
|
|
|
|
You can size the edit control with MoveWindow or SetWindowPos.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
Hi!
I have modified the sample application from MSDN lib and having a trouble: Custom Control with interfaces
CEdit
A
|
|
CParsedEdit
A
|
|
CParsedEditExport (for custom controls)
Now I change design pattern: extract interface from implementation, and enable RTTI in compiler option, theoretically:
CEdit IEdit(abstract as interface)
A A
| /
| /
CParsedEdit
A
|
|
CParsedEditExport (for custom controls)
Here is the code:
interface:
class IEdit {
public:
virtual void setText(TCHAR* text)=0;
virtual int getText(TCHAR* text, int count)=0;
};
class CParsedEdit : public IEdit, public CEdit {
public:
virtual void setText(TCHAR* text) { SetWindowText(text); }
virtual int getText(TCHAR* text, int count) { return GetWindowText(text, count); }
protected:
....
};
user:
class CWclsEditDlg : public CDialog {
public:
IEdit* Edit1()
{ return dynamic_cast<IEdit*>(GetDlgItem(IDC_EDIT1)); }
IEdit* Edit2()
{ return dynamic_cast<IEdit*>(GetDlgItem(IDC_EDIT2)); }
IEdit* Edit3()
{ return dynamic_cast<IEdit*>(GetDlgItem(IDC_EDIT3)); }
IEdit* Edit4()
{ return dynamic_cast<IEdit*>(GetDlgItem(IDC_EDIT4)); }
....
};
Does anyone know how to solve this?
Thanks.
Sovann.
Why waste time learning while ignorence is instantaneous ? [Hobbes]
|
|
|
|
|
Sadly, dynamic_cast (and it's MFC cousin) won't work on CWnd::GetDlgItem() since it actually returns a CWnd (which is very likely to be a temporary object). Hence the dyanmic cast will fail.
The best way would actually be to subclass your edit controls using DDX_Control()...that way you can manipulate them directly without using GetDlgItem().
Anna
"Be yourself - not what others think you should be" - Marcia Graesch
|
|
|
|
|
I'm trying to access a parallel port in my project...
I've got a DLL that should solve my troubles, but the problem is: How do I use a DLL in Visual C++?
|
|
|
|
|
There are mainly two options you have:
1. If you have the dll, a .h file describing the functions available in the dll and a .lib file you should be able to #include the .h file and add the lib file to your linker settings. Then you can call the functions in the dll just like any other function.
2. If you however have only got the dll itself and know the layout of the functions then you would have to use ::LoadLibrary / ::GetProcAddress to load the address of the function you want to call at runtime. Assuming the function you want to use takes two parameters; one integer and one LPCTSTR; and returns BOOL then you could use a code similar to this:
<br />
typedef BOOL ( CALLBACK* MyExportedFunction )( int, LPCTSTR );<br />
<br />
HINSTANCE hInst = ::LoadLibrary( _T( "theDLLIWantToUse.dll" ) );<br />
<br />
if ( hInst != NULL )<br />
{<br />
MyExportedFunction myFunc = (MyExportedFunction) GetProcAddress( (HMODULE)hInst, _T("TheFunctionIWantToCall") );<br />
if ( myFunc != NULL )<br />
{<br />
BOOL bRetVal = myFunc( 7, _T("This is a string parameter") );<br />
}<br />
::FreeLibrary( (HMODULE)hInst );<br />
}<br />
<br />
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Hi.
I added a simple CListCtrl box with a List style to a dialog box. However, I cannot insert more than one item. Another possible problem is that Windows is not drawing the other items. Nonetheless, only one item shows up. Here is an example what how I inserted items.
-----
OnInitDialog(...)
{
LVITEM Item;
Item.mask = LVIF_TEXT;
Item.state = LVIS_SELECTED;
Item.stateMask = LVIS_SELECTED;
Item.cchTextMax = 0;
Item.iImage = 0;
Item.lParam = 0;
Item.iSubItem = 0;
Item.pszText = TEXT("November");
// I would like to insert ten items in the list box.
for (unsigned i = 0; i < 10; ++i)
theListBox.InsertItem(&Item);
-----
After the insertion above, only one line of "Novermber" will show up in the CListCtrl box.
I have worked with CListCtrl boxes using Report Style. I have not had this problem. I would like to know why does it ignore all new items except the first line?
Thanks,
Kuphryn
|
|
|
|
|
Okay - I'll be the first to admit I don't know what I'm doing. But it looks like you're trying to insert the same item (ie, same memory address pointing to the item) multiple times.
I would try creating a second LVITEM called Item2, insert that, and see if you get multiple values in the CListCtrl. In the .InsertItem() function it may actually check and see if an item is already there, and if so, don't add it again.
- Kati
|
|
|
|
|