|
Mark Salsbery wrote: You should be able to add the control object from the dialog editor...
right click the text control and chose "Add variable..." (I can't remember
exactly in VC6).
you have to change name of IDC_STATIC to some else,to make editor aware that you want to add variable to that static control!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
You can use of Get/SetwindowText or WM_GETTEXT/WM_SETTEXT for get or set text toa control.
|
|
|
|
|
How can I free memory before returning the value in my function?. Here's the code, thank you very much.
int FindString(char*s, char* what, int len, int len2)
{
char * x = s;
for (int i = 0;i<len;i++,*x++)
{
if(memicmp(x,what,len2) == 0)
{
cout <<; "I found it @ " << i << endl;
return i;
}
}
return -1;
}
char *rr(char*s)
{
char cc[4] = {0x00,0x00,0x00,0x00};
int i =FindString(s,cc,512,4);
if( i > 0)
{
char * New = new char[i];
memcpy(New,s,i);
// How can I use 'delete' here before returning New???
return New;
}
return NULL;
}
|
|
|
|
|
Why do you want to delete the array before returning the pointer
to the caller? What are you trying to achieve?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You don't delete it before returning the Pointer. The function that called FindString receives this pointer. This calling function can do it's thing with the pointer, and, if needed return it again. When you're done with the value of the pointer you must call delete, otherwise you leak the memory. As soon as you call delete, the value of the pointer points no longer to valid memory, and may not be used again. Using it's value again is an error, and will lead sooner or later to unpredictible behaviour or even crashes.
regards
Bram van Kampen
|
|
|
|
|
Thanks for your answer. I was wondering if I had to return that pointer how to remove it if it was my desired return value. Thanks for your answer, Bram van Kampen. This way i'd be doing it fine??
<code>
int FindString(char*s, char* what, int len, int len2)
{
char * x = s;
for (int i = 0;i<len;i++,*x++)
{
if(memicmp(x,what,len2) == 0)
{
cout << "I found it @ " << i << endl;
return i;
}
}
return -1;
}
char *rr(char*s)
{
char cc[4] = {0x00,0x00,0x00,0x00};
char ReturnArray[1024] = {0};
int i =FindString(s,cc,512,4);
if( i > 0)
{
char * New = new char[i];
memcpy(New,s,i);
memcpy(ReturnArray,s,i);
delete[] New;
return ReturnArray;
}
return NULL;
} </code>
|
|
|
|
|
Hi,
U declared ReturnArray as a local buffer. ie it's scope is only within the function rr. So after the execution of rr ,ReturnArray will be destroyed. i think u r going to get a "memory cannot be read error" . am i right?.
thanks
Nitheesh
|
|
|
|
|
You could declare it as a global variable, outside the function instead:
char ReturnArray[1024] = {0};
<br />
char *rr(char*s)<br />
{<br />
char cc[4] = {0x00,0x00,0x00,0x00};<br />
|
|
|
|
|
These code put a string into name which is a column in database table
<br />
_RecordsetPtr rec; <br />
rec.CreateInstance(_uuidof(Recordset));<br />
<br />
CString cstrSQL;<br />
cstrSQL.Format("SELECT * FROM ... where ...");<br />
<br />
rec->Open(_bstr_t(cstrSQL), (IDispatch*)g_pConnections, adOpenDynamic, adLockOptimistic, adCmdText);<br />
rec->PutCollect("name",_variant_t("my name"));<br />
rec->Update();<br />
<br />
But,how to PutCollect a NULL value into this column?
|
|
|
|
|
_RecordsetPtr rec;
rec.CreateInstance(_uuidof(Recordset));
CString cstrSQL;
cstrSQL.Format("SELECT * FROM ... where ...");
rec->Open(_bstr_t(cstrSQL), (IDispatch*)g_pConnections, adOpenDynamic, adLockOptimistic, adCmdText);
if(sName =="") //NULL
{
rec->PutCollect("name", VT_NULL);
}
else
{
rec->PutCollect("name",_variant_t("my name"));
}
rec->Update();
|
|
|
|
|
Hi!
I've got a silly problem. I've created a SDI application based on CFormView (with wizard). 'CBazaDanychView' - that's the name of the class, that inherits CFormView in my program.
I'm using a simple (public) member function (it's CBazaDanychView member), that updates some list control on my form view.
Everything is fine, but I've also created another dialog window (CDialog). I want to use CBazaDanychView's method in this dialog, that updates the list control - the same method I was writing about in the last paragraph.
How can I do this? I've tried getting pointer to the main window, but I can't use my function in this way.
How do I access any variables or methods from my CBazaDanychView from another dialog?
I don't even know what's CBazaDanychView object's name and how to get it.
Please help me!
Thanks in advance!
|
|
|
|
|
I don't quite understand what you're trying to do. Do you want the new dialog to update the controls ON the form view or use the same logic to calculate what should be displayed and apply that change to controls on the dialog? If it is the first, you can't do that if the dialog is modal - the message pump for the form view does not run while a modal dialog is displayed. You can make the dialog modeless but it still should not directly updates controls on the form view. Post a message to the form view from the dialog telling the form view what to do and let it do the update itself. If it is the second, create a method that takes a control pointer as a parameter and call it from both places. As long as the method only operates on the passed in control pointer, it is fine.
Hope that helps since you're question was not clear
Judy
|
|
|
|
|
Thanks. The dialog is modeless now. I decided to use a 'Sendmessage' method to update list control on form view.
I've just created (for the form view) a message map:
ON_MESSAGE(UWM_UPDATE_L, &CBazaproduktówView::OnUpdateL)
and defined:
#define UWM_UPDATE_L (WM_APP + 1) .
There is also a function, that handles an event:
LRESULT CBazaproduktówView::OnUpdateL(WPARAM wParam, LPARAM lParam)<br />
{<br />
UpdateListyTowarow();
return 0;<br />
}
When I use Sendmessage(UWM_UPDATE_L) form the form view everything is fine! But... program crashes if I use it in the dialog:
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);<br />
CView * pView = (CView*)pFrame->GetActiveView();<br />
pView->SendMessage(UWM_UPDATE_L);
Bang!
What's wrong? I don't understand.
|
|
|
|
|
Two things. 1) Use the debugger - it will go right to the line having the problem when the program crashes. You'll be able to see what's wrong. 2) You're missing the last two parameters to SendMessage - it should be pView->SendMessage (UWM_UPDATE_L, 0, 0)
Judy
|
|
|
|
|
When I'm using this code
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);<br />
CView * pView = (CView*)pFrame->GetActiveView();<br />
pView->SendMessage(UWM_UPDATE_L, 0 ,0);
in any function/event of my form view, everything is fine. When I use it in the dialog - program crashes. Debuger didn't show me any interesting info about this problem. I'm a bit confused.
|
|
|
|
|
overheat wrote: Debuger didn't show me any interesting info about this problem
I find that highly unusual. Did you go back up the call stack, examining each and every parameter to your functions? Did you try putting a breakpoint in the function that crashes before the line that crashes and single-stepping? Since the problem is in the update function, did you single-step through that function? You haven't shown enough code to help - there is nothing wrong in what you've shown. There's probably something in that function you call from within the update that is the problem. Does it crash if you use PostMessage instead of SendMessage?
|
|
|
|
|
In one project I was wanting to do something like you say but mixing DialogBoxes that have to interact with other views gave me a lot of problems. At the end I changed the structure and use all view-derived classes. The structure was 1 ScrollView as Main view, and then so many CFormView derived forms of 3 possible different types as elements in the main view were, and all could be opened at once.
I got it saving a CElementView pointer in every element, to access the different views and its parameters through the pointer. If you think it is something similar with what you want to reach. Take a look to this message[^], it can maybe help you.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hello
-----
LONG MCIWndOpen(
hwnd,
szFile,
wFlags
);
I'm going to use above function in my unicode app. But it seems to not work with unicode as szFile parameter. Is there any way to have it to work with unicode OR convert my file path to ansi? (It's just in unicode at present)
|
|
|
|
|
The docs state "Unicode: Declared as Unicode and ANSI messages", whatever that means.
If you convert the string to ANSI and the call succeeds, then you have your answer
Not much strong typing in that ancient API.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It should work fine with Unicode. Searching the SDK turns up the following:
From "Vfw.h" (searching for "MCIWndOpen"):
------------------------------------------
#define MCIWndOpen(hwnd, sz, f) (LONG)MCIWndSM(hwnd, MCIWNDM_OPEN, (WPARAM)(UINT)(f),(LPARAM)(LPVOID)(sz))
From "Vfw.h" (searching for "MCIWNDM_OPEN"):
--------------------------------------------
#ifdef UNICODE
#define MCIWNDM_OPEN MCIWNDM_OPENW
#else
#define MCIWNDM_OPEN MCIWNDM_OPENA
#endif
From "Vfw.h" (searching for "MCIWndSM"):
----------------------------------------
#ifdef __cplusplus
#define MCIWndSM ::SendMessage /* SendMessage in C++*/
#else
#define MCIWndSM SendMessage /* SendMessage in C */
#endif /* __cplusplus */
From "WinUser.h" (searching for "SendMessage"):
-----------------------------------------------
#ifdef UNICODE
#define SendMessage SendMessageW
#else
#define SendMessage SendMessageA
#endif // !UNICODE
Steve
|
|
|
|
|
hi
Could someone please tell me how can i open a txt file with a press of a button (MFC)?
not with the infile >>> i mean open "text file"
and another question if i may....
Is there any way i can transform a cpp file to a txt file (keeping the same content) ?
and if it can be done .... how i can do it?
any help would be reallly appriciated
thanks in advance
|
|
|
|
|
lahom wrote: i open a txt file with a press of a button (MFC)
Create an event handler for the button press and call CreateFile
lahom wrote: Is there any way i can transform a cpp file to a txt file (keeping the same content)
A .cpp file IS a text file. Just change the extension
Judy
|
|
|
|
|
lahom wrote: Could someone please tell me how can i open a txt file with a press of a button (MFC)?
in your button's on click (actually BN_CLICKED) handler function.
{
CFileDialog dlg(TRUE, _T("txt"), NULL, OFN_FILEMUSTEXIST,
_T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"), NULL);
if(IDOK == dlg.DoModal())
{
CString strFileName = dlg.GetPathName();
try
{
CStdioFile file(strFileName, CFile::typeText | CFile::modeRead);
CString strLine;
while(file.ReadString(strLine))
{
}
file.Close();
}
catch (CFileException* pex)
{
pex->ReportError();
pex->Delete();
}
}
}
lahom wrote: Is there any way i can transform a cpp file to a txt file (keeping the same content) ?
.cpp files are plain text files in contents.
Simply, copy the file with .txt extension.
|
|
|
|
|
You must make a event for your button and then you can use of CFile class.
|
|
|
|
|
lahom wrote: Is there any way i can transform a cpp file to a txt file (keeping the same content) ?
see rename function and CopyFile api is of any use??
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|