|
Use the FindFirstFile() /FindNextFile() pair for both.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
KevinSheedy wrote: The simpler the solution the better.
what about CFileFind MFC Class
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
Could someone help me modify the following code in order to dispaly in hex format the received bytes from a serial port.
<br />
CCom *pCom=(CCom*)ch;<br />
char *szReceive;<br />
int nr;<br />
szReceive = new char [(nr=(pCom->SizeUsedInRXBuf()+1))]; <br />
memset(szReceive,0,nr); <br />
pCom->ReadBuffer(szReceive,nr-1);<br />
CString str,toto;<br />
m_Edit.GetWindowText(str);<br />
str+=szReceive;<br />
delete [] szReceive; <br />
m_Edit.SetWindowText(str+"\r\n");
|
|
|
|
|
this is a function i use to convert BYTE arrays to hex strings. maybe it will help...
CString HexDump(BYTE *pData, DWORD dwSize, int imax)
{
CString out;
for (DWORD i=0; i < dwSize; i++)
{
CString f;
if (pData[i]<16)
f.Format("0%x", pData[i]);
else
f.Format("%x", pData[i]);
out+=f;
}
if (imax > 0 && imax < out.GetLength())
{
out = out.Left(imax);
out+="...";
}
return out;
}
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Looking at the formatting of the code reinforces my belief that using tabs for indenting should be banned. Use spaces only. No matter how careful you are to try and use tabs, somewhere in the code you are going to press the space bar 4 times rather than the tab key once. Now when the code is viewed with a different tab spacing it looks all screwy.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote: Looking at the formatting of the code reinforces my belief that using tabs for indenting should be banned.
sometimes, when i re-install VC, i forget to turn on Insert Spaces.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
That was exactly what I was looking for;
Thanks a lot
|
|
|
|
|
what are dwSize and imax for?
|
|
|
|
|
Use CString::Format() to get the hex representation:
CString str;
BYTE by = 42;
str.Format ( _T("%02X"), by );
You can use %x instead of %X to get lowercase letters but I find uppercase easier to read.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Actual sign at the laundromat I go to: "No tinting or dying."
|
|
|
|
|
Is there a way for a program to know when a network connection has been made? Ideally, I'd like to know when a certain interface is connected (I don't have to know when it was connected, just if it currently is physically connected). It seems as though XP can detect this since it has tray icons for this. Any idea how they are doing it?
|
|
|
|
|
If you only have to run on servers, you might be interested in the Network Monitor API:
Network Monitor captures network traffic for display and analysis. It enables you to perform tasks such as analyzing previously captured data in user-defined methods and extract data from defined protocol parsers.
No shirt, no shoes, no brains, no service.
|
|
|
|
|
InternetGetConnectedState
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks guys -
I don't think either one will work though.
The reason why InternetGetConnectedState won't work is that it seems to only detect if a connection to the internet is found. This won't be true since by default, any new PC will not be allowed to connect to the internet from within our building (MAC filtering).
What I need is a way to determine if the connection is good for a particular interface. Similar to what the connection status icon does in XP.
For now, I'm using a ping to our server name. I guess it's about as good as I will be able to do.
If anyone has a better suggestion, please let me know.
|
|
|
|
|
Is this of any help?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
lynchspawn wrote: Any idea how they are doing it?
ISensNetwork
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hello all! This is a duplicate from the SQL forum. It might be more suited for this forum.
I've recently completed a Pocket PC application in VB.NET that works with connections to a local SQL Server 2000 CE DB and a SQL Server 2000 via WiFi.
I'd like to look at doing the same thing using eMbedded Visual C++ 4.0 and OLE DB for a CE.NET device. While there are plenty of resources for SQL CE I can't find any for SQL Server 2000.
Does anyone know of a good sample for eVC++ that hits both SQL CE and SQL Server? No ActiveSync and no IIS for this solution thus RDA and Merge Repl are of no value.
Any input is much appreciated!
|
|
|
|
|
Hi,
My problem is that I can't make the size of the toolbar buttons right.
This is my code:
HWND CreateMyToolbar(HWND hWnd)<br />
{<br />
HWND hToolbar;<br />
hToolbar = NULL;<br />
hToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,"MyToolbar",WS_CHILD|WS_VISIBLE|TBSTYLE_TOOLTIPS ,0,0,0,0,hWnd,0,g_hInstance,NULL);<br />
if(hToolbar)<br />
{<br />
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);<br />
TBBUTTON tbb[1];<br />
TBADDBITMAP tbab;<br />
tbab.hInst = HINST_COMMCTRL;<br />
tbab.nID = IDB_STD_LARGE_COLOR; <br />
SendMessage(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbab);<br />
<br />
ZeroMemory(tbb, sizeof(tbb));<br />
<br />
tbb[0].iBitmap = STD_FILENEW;<br />
tbb[0].fsState = TBSTATE_ENABLED;<br />
tbb[0].fsStyle = TBSTYLE_BUTTON;<br />
tbb[0].idCommand = IDM_FILENEW; <br />
<br />
SendMessage(hToolbar, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);<br />
return hToolbar;<br />
}<br />
return NULL;<br />
<br />
}
I've set the IDB_STD_LARGE_COLOR imagelist, but in the result the button image is clipped on the bottom.
Can someone show me how to do this right?
thanks in advance,
Ward
|
|
|
|
|
Ok, I figured it out by myself. Finally.
Ward
|
|
|
|
|
Hello,
Would like to know how the contents of a control (say edit control / text box) can be sent to a printer. I am having a text box which is in a dialog. Normally print is supported for a view. But my requirement is to extract the contents of the control, which is in a VC++ 6.0 dialog and has to be printed.
Will help a lot, if a sample code is supported.
Regards,
Vairamuthu.G.
|
|
|
|
|
Hi,
Use following code:
DOCINFO di = { sizeof (DOCINFO) } ;<br />
PRINTDLG pd ;<br />
int yChar, iCharsPerLine, iLinesPerPage, iTotalLines, iTotalPages, iPage, iLine, iLineNum ;<br />
PTSTR pstrBuffer ;<br />
<br />
TCHAR szJobName [64 + MAX_PATH] ;<br />
TEXTMETRIC tm ;<br />
WORD iColCopy, iNoiColCopy ;<br />
<br />
pd.lStructSize = sizeof (PRINTDLG) ;<br />
pd.hwndOwner = hwnd ;<br />
pd.hDevMode = NULL ;<br />
pd.hDevNames = NULL ;<br />
pd.hDC = NULL ;<br />
pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION ;<br />
pd.nFromPage = 0 ;<br />
pd.nToPage = 0 ;<br />
pd.nMinPage = 0 ;<br />
pd.nMaxPage = 0 ;<br />
pd.nCopies = 1 ;<br />
pd.hInstance = NULL ;<br />
pd.lCustData = 0L ;<br />
pd.lpfnPrintHook = NULL ;<br />
pd.lpfnSetupHook = NULL ;<br />
pd.lpPrintTemplateName = NULL ;<br />
pd.lpSetupTemplateName = NULL ;<br />
pd.hPrintTemplate = NULL ;<br />
pd.hSetupTemplate = NULL ;<br />
<br />
if (!PrintDlg (&pd))
return TRUE ;<br />
<br />
if (0 == (iTotalLines = SendDlgItemMessage (hwnd,IDC_TEKSTVELD, EM_GETLINECOUNT, 0, 0)))<br />
return TRUE ;<br />
<br />
GetTextMetrics (pd.hDC, &tm) ;<br />
yChar = tm.tmHeight + tm.tmExternalLeading ;<br />
<br />
iCharsPerLine = GetDeviceCaps (pd.hDC, HORZRES) / tm.tmAveCharWidth ;<br />
iLinesPerPage = GetDeviceCaps (pd.hDC, VERTRES) / yChar ;<br />
iTotalPages = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage ;<br />
<br />
pstrBuffer = (PTSTR)malloc (sizeof (TCHAR) * (iCharsPerLine + 1)) ;<br />
<br />
<br />
di.lpszDocName =
<br />
if (StartDoc (pd.hDC, &di) > 0)<br />
{<br />
for (iColCopy = 0 ;<br />
iColCopy < ((WORD) pd.Flags & PD_COLLATE ? pd.nCopies : 1) ;<br />
iColCopy++)<br />
{<br />
for (iPage = 0 ; iPage < iTotalPages ; iPage++)<br />
{<br />
for (iNoiColCopy = 0 ;<br />
iNoiColCopy < (pd.Flags & PD_COLLATE ? 1 : pd.nCopies);<br />
iNoiColCopy++)<br />
{<br />
if (StartPage (pd.hDC) < 0)<br />
{<br />
bSuccess = FALSE ;<br />
break ;<br />
}<br />
for (iLine = 0 ; iLine < iLinesPerPage ; iLine++)<br />
{<br />
iLineNum = iLinesPerPage * iPage + iLine ;<br />
<br />
if (iLineNum > iTotalLines)<br />
break ;<br />
<br />
*(int *) pstrBuffer = iCharsPerLine ;<br />
<br />
int iAantalChars = (int) SendDlgItemMessage (hwnd,IDC_TEKSTVELD, EM_GETLINE,<br />
(WPARAM) iLineNum, (LPARAM) pstrBuffer);<br />
<br />
<br />
TextOut (pd.hDC, 0, yChar * iLine, pstrBuffer, iAantalChars);<br />
<br />
if (EndPage (pd.hDC) < 0)<br />
{<br />
break ;<br />
}<br />
<br />
<br />
}
<br />
}<br />
<br />
free (pstrBuffer) ;<br />
DeleteDC (pd.hDC) ;
This will surely help you.;)
kind regards,
Ward
|
|
|
|
|
I have function in a class called LoadFile
BOOL Bitmap::LoadFile(const char *FileName)<br />
{<br />
<br />
CFileException e;<br />
<br />
strcpy(m_FileName,FileName);<br />
<br />
}
to which i pass string during the call
const char *FileName= _T("c:\\1.bmp");<br />
BMP.LoadFile (FileName);
there is an error
error: unhandled exception , 0x0000000005 access violation
whats wrong
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
What is m_FileName ?
It seems to be something like:
char* m_FileName; //This should produce the error.
However,
char m_FileName[MAX_PATH];//This should not result in an error.
It is unclear from your post; it could be something else also.
this is this.
|
|
|
|
|
What is m_FileName declared as?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
|
|
|
|
|
It depends on what data type m_Filename is.
If it is of type CString, then I think this function will not work without first exposing the memory buffer (GetBuffer(0) ??).
If the variable is an array of characters, then it should work (unless the destination size is less than the source string).
I Dream of Absolute Zero
|
|
|
|
|
vikas amin wrote: strcpy(m_FileName,FileName);
change to
if ((!m_FileName) && (size_allocated_to(m_FileName) > ::strlen(FileName))) {
::strcpy(m_FileName, FileName);
}
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|