|
if you please can u sent me some specific sites and examples not the MSDN or if so specifie to me wut should i write or where should i search .Because i am learning MFC newly and i have 1 week to hand in my project .
I need to know how can i read from a file or to a file in MFC classes and if u dont mind i would like to have an updating file example as well .
thank you in advance
|
|
|
|
|
CFile
Most of the member functions have examples, Open most likely has the most thorough example.
See CFile::modeNoTruncate flag for appending data to files.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
The best way is to use standard C++ most of the time. If you google ifsteam or ofstream, you're bound to find some references.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm having trouble figuring out how to pass a
pointer to a double array (1 dimensional)
to a C function.
Declaring array as: double xx[100];
Declaring func. int process( double *input[] )
Calling func. as one of the following:
process ( xx );
process ( &xx[0] );
I get various "can't convert, can't recast"
error messages from the compiler.
I have also tried declaring a double pointer and
pointing address of index zero of the array to the
double pointer - no luck either.
Using Visual Studio/Visual C 6.0
Many thanks,
Robert
|
|
|
|
|
int process(double *input)
double xx[100];
xx[0] = 1.1;
xx[1] = 2.2;
xx[2] = 3.3;
xx[3] = 4.4;
...
process(xx);
|
|
|
|
|
|
Declaring array as: double xx[100];
Declaring func. int process( double *input[] )
The second one is a double pointer (pointer to an array). So, pass your array like:
process(&xx);
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
You can write either of these in the function:
int process ( double* input );
int process ( double input[] ); The two are equivalent, and the equivalence is an artifact of C's predecessor languages. Note that you also need a way to tell process() the size of the array, because the input parameter is just a pointer. The usual way is to add a second parameter of type size_t where you pass the number of elements in the array.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Gentlemen,
Thank-you for your assistance.
Have it working now.
All the best,
Robert
|
|
|
|
|
When I send a message to main thread I also have to send a string and an int.
I have to use LPARAM and WPARAM?
Here my code:
...
#define MY_WM_MESSAGE1 (WM_APP + 1)
...
ON_MESSAGE(MY_WM_MESSAGE1, OnMyMessage1)
...
LRESULT CProvaDlg::OnMyMessage1(WPARAM wParam, LPARAM lParam){
/***
// here I want to use a string and an int sent by message
*/
return 0; // I handled this message
}
Tnx
(sorry for my english)
|
|
|
|
|
When you send the message, cast the values to WPARAM and LPARAM and then cast them back in the message handler:
// sending
TCHAR* pszValue = _T("abc");
int iValue = 42;
SendMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)pszValue, (LPARAM)iValue);
// receiving
LONG CYourClass::OnMessage1(WPARAM wp, LPARAM lp)
{
TCHAR* psz = (TCHAR*)wp;
int i = (int) lp;
...
|
|
|
|
|
CString* pString = new CString(_T("Text"));
int nNumber = 100;
PostMessage(hMyWnd, MY_WM_MESSAGE1, reinterpret_cast<WPARAM>(pString), reinterpret_cast<LPARAM>(nNumber));
The string must be allocated on the heap, otherwise it will bomb on you when it goes out of scope.
You'll need to free the memory for it when the OnMyMessage1 is received.
in OnMyMessage1...
CString* pString = reinterpret_cast<CString*>(wParam);
int nNumber = reinterpret_cast<int>(lParam);
...
delete pString;
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Yes, as other have just suggested you may cast your int and string to wparam and lparam repectively.
But what are you going to do if you will need to pass more data than do not fit in two variables later? I'd suggest to declare a struct, that would contain any information you need to pass with a message. This has one long tern advantage - if the code to be tweaked sometime later, tweaking will not affect function signatures and the app's architecture.
<br />
struct MYMESSAGEDATA<br />
{<br />
int nInteger;<br />
char* nString;<br />
};<br />
<br />
...<br />
...<br />
MYMESSAGEDATA* pData = new MYMESSAGEDATA;<br />
pData->nInteger = 1;<br />
pData->nString = "string";<br />
...<br />
...<br />
<br />
::SendMessage(hwnd, msg, NULL, (WPARAM)pData); <br />
<br />
...<br />
LRESULT CProvaDlg::OnMyMessage1(WPARAM wParam, LPARAM lParam)<br />
{ <br />
MYMESSAGEDATA* pIncomingData = (MYMESSAGEDATA*)lParam;<br />
<br />
<br />
...<br />
...<br />
<br />
delete pIncomingData;<br />
<br />
return 0;<br />
}<br />
As you can see in above example, you have a spare wParam which could be used to pass, for example, ID of the sender of the message, consider it as another advantage of this approach.
|
|
|
|
|
Rouslan Grabar [Russ] wrote:
struct MYMESSAGEDATA
{
int nInteger;
char* nString;
// add here anything you want later
// e.g. status flags, length of a string, etc.
};
...
Sounds similiar to WM_COPYDATA
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Tnx a lot
very useful
|
|
|
|
|
I need to know if there is any source code that has implemented tree view and MDI association just like windows explorer.But i need to draw graphical data on the windows.So any articles or source code that has this feature.
I have implemented the same but iam facing huge memory problem and deletion of
tree nodes and their mapping to the MDI Windows has been done tediously but not stable.
So any source code available with that complies to MDI doc -view architecture.
Thanx in advance
laiju
|
|
|
|
|
I want to connect a second mouse to the computer (XP). This mouse should have its own cursor and I want full control of it i.e. all mouse events must be captured and handled by my application regardless of the cursor positition and which application is active.
I have tried with DirectInput but this does not work since in XP all attached mouse devices are treated as the system mouse. I have also tried Raw Input but this is dependent of the windows message WM_INPUT and can thus only capture mouse events generated when my application is active.
Do I need to write a mouse driver or is there a simpler solution?
Thanks in advance,
Christian
|
|
|
|
|
chribben wrote:
This mouse should have its own cursor
Think about what would happen if that were possible. What would GetMessagePos() and GetCursorPos() return?
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
hi all,
I want to use C# to interop with the shell extension, for example the DLL from this code(http://www.codeproject.com/shell/shellextguide1.asp[^]) using pinvoke.
Can I define my own STDAPI in the DLL?
how the STDAPI controls the DllMain?
The final objective I want to archieve is to use C# to control the DLL to change the menuitem name of the context menu, but is it possible?
Thank you
|
|
|
|
|
After reading a little about MFC i have started to write the program after i wrote it and tried run it it gave me this error--->
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
i am using the V C++ that comes with the book is this the reason i have change the settings and all the to include MFC shared DLL i guess from NO MFC . is it becoz the CD is an Introductory edition it not running by the way the program i am trying to run is copy paste program from a Deitel book and if it is not form the CD tell if u please tell me the answer urgently
thank u in advance
|
|
|
|
|
newerStudent wrote:
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
Have you verified that this file exists on the development machine? Do you get a similar error when compiling for "Release" instead of "Debug" mode?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
newerStudent wrote:
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
This file should be present under MFC\lib.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
I tried to get the currently clicked item on the tree ctrl using the foll.
code But it does not return me the current item.
What could be wrong
void COSDDlgBar::OnNMClickTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
CTreeCtrl *pm_Tree = NULL;
pm_Tree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
HTREEITEM hItem = pm_Tree->GetSelectedItem();
*pResult = 0;
}
laiju
|
|
|
|
|
I don't think the selection will change until after the NM_CLICK has been processed.
Try handling TVN_SELCHANGED and call your code from there. (or better yet, use the itemNew variable in the NM_TREEVIEW struct)
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
I tried to get the currently clicked item on the tree ctrl using the foll.
code But it does not return me the current item.
What could be wrong
void COSDDlgBar::OnNMClickTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
CTreeCtrl *pm_Tree = NULL;
pm_Tree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
HTREEITEM hItem = pm_Tree->GetSelectedItem();
*pResult = 0;
}
laiju
|
|
|
|