|
Hello everyone!
Look at my function:
<br />
char * getPartName(char * fileName, int part)<br />
{<br />
printf("%i\n", sizeof(fileName));<br />
<br />
<br />
char *partName, *numExt, *partStr, *unexName;<br />
int remSpace;<br />
<br />
<br />
partName = malloc(sizeof(char) * (sizeof(getUnextendedName(fileName)) + 4));<br />
<br />
<br />
strcpy(partName, getUnextendedName(fileName));<br />
<br />
<br />
if (part == -1)<br />
strcat(partName, ".mtx");<br />
<br />
<br />
else<br />
{<br />
<br />
partStr = malloc(sizeof(char) * 4);<br />
<br />
<br />
sprintf(partStr, ".%2i", part);<br />
<br />
<br />
strcat(partName, partStr);<br />
}<br />
<br />
return partName;<br />
}
See the debug printf at the top? Well, why does it print out "4"? It's supposed to be 14... Even when I change that printf to display the actual filename it prints out "screenshot.png", so why the heck would it be 4? Anyone know? Thanks!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
fileName is a char *
And sizeof(char *) == 4.
If you want to know the length, use strlen(fileName)
|
|
|
|
|
filename is a pointer to a char array, and a pointer is always 4 bytes long. Use strlen instead.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
The reason is because your using the sizeof operator to request the size of the array an not the pointer
eg:
<code>#include <iostream.h>
void main()
{
char *pszSite = "Code project";
cout << "The size of string is: " << (sizeof)pszSite << endl;
cout << "The size of character is: " << (sizeof)*pszSite << endl;
cout << "The size of pointer is: " << (sizeof)&pszSite << endl;
}</code>
In other words with using pointers to chars
- No prefix operator treats it as a string.
- Deferencing (asterisk) operator means get the contents to where it is
pointing to. - Address of (ampersand) operator means get the actual address of the
pointer
I hope that makes sense
Alton
|
|
|
|
|
|
I am trying to build a grid with 3 or 4 columns with editctrl. Any idea of how to expand it to a full fledged grid control
|
|
|
|
|
And why do you want to do that with an editcltr ? Why don't you simply use a grid control for that purpose ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
may be u can user editctrls with flexgrid.i.e work in the reverse order ,make a flexgrid and add controls to it .. search for editgrids...
|
|
|
|
|
|
arunvalli wrote: am trying to build a grid with 3 or 4 columns with editctrl. Any idea of how to expand it to a full fledged grid control
that require hell lot of coding, and why are you reinventing the Wheel, when there are thousands of freely available FlexGrid and related things
"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
Support CRY- Child Relief and You
|
|
|
|
|
Hello everyone:
Please help me how to send a custom message to a window service?
Thanks.
-Freehawk
|
|
|
|
|
I think you should first check if it is practically possible to create a hidden window from a service. Since the service normally is started before the user enters the system, I suppose it will be impossible to create the helper window on early stage. You should try to create the window after the user logs in.
If you manage to create a helper hidden window from your service, then you can use the WM_COPYDATA message to send messages from your application to service.
Otherwise, if you do not found a solution, I am afraid you have to use a thing called Inter-process Communication (IPC). There is a series of methods: sockets, shared memory, pipes and others, that you have to investigate.
|
|
|
|
|
sunyw_2006 wrote: Please help me how to send a custom message to a window service?
Nishant Sivakumar has written a nice article on Windows Service. Apart from that take a look at ControlService and SERVICE_USER_DEFINED_CONTROL .
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Hi friends,
I have an application built using VC++ 6.0 .
In these we incorporate serial communication using
rs-232 serial port and also thru USB-Serial adapater
Now ny requirement is to put a small delay only when
the application runs thru USB-Serial not when normal serial
communication is used to run the application.
These delay is have to do since the data transfer
thru USB-Serial is faster as compared to normal serial
Now can u please tell me how to find whether the application
is running thru USB-Serial or Normal Serial port.
|
|
|
|
|
Veeresh Hiremath wrote: Now ny requirement is to put a small delay only when
the application runs thru USB-Serial not when normal serial
communication is used to run the application.
These delay is have to do since the data transfer
thru USB-Serial is faster as compared to normal serial
Why do you need to do such a thing ?
That sounds very strange. Your applications (on both sides) should never be dependent on the time needed to transmit the data on the link (it can be unreliable).
Anyway, with windows, you won't be able to have a precision under 10 or 15 msec as windows is not a real-time operating system.
Maybe if you describe more in detail your problem we can help you to find another solution (please, describe it with keeping in mind that we don't know your app and that we cannot see your screen).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
i use this to get date from date timepicker :
m_datetime .UpdateData();
char *str=new char[100];
m_datetime.GetWindowText (str,10);
AfxMessageBox(str);
now how can i convert this date into mysql format so that iw will store in mysql table;
plz tel me after this code wat code i write
gourav dogra jfjunf
|
|
|
|
|
Extract the numbers based on tokenizing the string by / . In this way you can get the year, month and day in different strings.
Use CString stt;
stt.Format("%s-%s-%s",strYear,strMonth,strDay);
AfxMessageBox(stt);
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
gourav456 wrote: i use this to get date from date timepicker :
m_datetime .UpdateData();
char *str=new char[100];
m_datetime.GetWindowText (str,10);
AfxMessageBox(str);
now how can i convert this date into mysql format so that iw will store in mysql table;
I think you have created Control variable..
Try the following:
1)Create Value variable
2)Suppose variable name is m_DateTime then
CString strDate=m_DateTime.Format("%Y-%m-%d"); 3)strDate is resultant Date.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
gourav456 wrote: now how can i convert this date into mysql format so that iw will store in mysql table;
How many times do you plan on asking this same question? It has been answered no less than three times in as many days.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi ,
I need to show the IDC_HAND cursor if the mouse moves over a particular subitem. I wrote the follwoing code. But the mouse cursor is not changing.
Any alternative please.
void CList::OnMouseMove(UINT nFlags, CPoint Point)
{
//Get the mouse position
const MSG* pMessage;
pMessage = GetCurrentMessage();
ASSERT(pMessage);
CPoint pt;
pt = pMessage->pt; // get the point from the message
// see if the point falls onto a list item
LVHITTESTINFO lvhitTestInfo;
lvhitTestInfo.pt = pt;
int nItem = m_List.SubItemHitTest(&lvhitTestInfo);
int nSubItem = lvhitTestInfo.iSubItem;
if (nItem >= 0 && lvhitTestInfo.iSubItem > 0)
{
int m_nSubItemHit = lvhitTestInfo.iSubItem;
if ( lvhitTestInfo.iSubItem == 8)
{
SetCursor(hCursor);
} }
}
Thanks
Raji
|
|
|
|
|
RajiRaghu wrote: //Get the mouse position
const MSG* pMessage;
pMessage = GetCurrentMessage();
ASSERT(pMessage);
CPoint pt;
pt = pMessage->pt; // get the point from the message
Why r u taking the mouse point in this method when the point is passed to the function....?
Replace ur code with the below one..
void CList::OnMouseMove(UINT nFlags, CPoint Point) <br />
{<br />
<br />
LVHITTESTINFO lvhitTestInfo;<br />
<br />
lvhitTestInfo.pt = Point;<br />
<br />
int nItem = m_List.SubItemHitTest(&lvhitTestInfo);<br />
int nSubItem = lvhitTestInfo.iSubItem;<br />
if (nItem >= 0 && lvhitTestInfo.iSubItem > 0)<br />
{<br />
int m_nSubItemHit = lvhitTestInfo.iSubItem;<br />
if ( lvhitTestInfo.iSubItem == 8)<br />
{<br />
SetCursor(hCursor); <br />
} }<br />
}
nave
|
|
|
|
|
Not working.
The hand cursor is changing on different place. Not in the list control.
Any solutions please
Thanks
Raji
|
|
|
|
|
This is the code that i have used for checking.. This code works correctly..it changes the cursor to IDC_HAND when the mouse is over the subitem number 1.
void MyList::OnMouseMove(UINT nFlags, CPoint point)
{
static HCURSOR hCursor = LoadCursor( 0, IDC_HAND );
LVHITTESTINFO lvhitTestInfo;
lvhitTestInfo.pt = point;
int nItem = SubItemHitTest(&lvhitTestInfo);
int nSubItem = lvhitTestInfo.iSubItem;
if (nItem >= 0 && lvhitTestInfo.iSubItem > 0)
{
int m_nSubItemHit = lvhitTestInfo.iSubItem;
if ( lvhitTestInfo.iSubItem == 1)
{
SetCursor(hCursor);
}
}
CListCtrl::OnMouseMove(nFlags, point);
}
nave
|
|
|
|
|
I think better is to handle the cursor in OnSetCursor... What do you think?
- NS -
|
|
|
|
|
Consider a solution in which you handle the WM_SETCURSOR notification. Within the OnSetCursor handler, obtain the mouse coordinates with GetCursorPos , make a test and call SetCursor to set your cursor, then return TRUE . Otherwise, call the parent OnSetCursor handler and return its value.
Hope it will work.
|
|
|
|