|
Hello
I Need A Simple MFC Project With Use DataBase In That and Programming Via Microsoft Visual Studio 2003 Like This Image :
http://i28.tinypic.com/n4b04g.jpg
My Project's Source Code Too Is Here :
http://uploadbazar.com/748PVD.zip
Please Help Me
How I Can Use Database In My Project ?
Thanks
Regards
Mohsen.Alipour@Hotmail.com
|
|
|
|
|
Mohsen.Alipour wrote: How I Can Use Database In My Project ?
See here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
as the topic,and also I want to get the Expection infomation if an exception threw out when compiling a source file,e.g stack overflow.There will be much information the program can catch.
how could I carry out this?any one can help me?
thanks in advance.
no cross no crown.
|
|
|
|
|
|
I'm using Visual C++ 6.0 - I'm new to windows programming.
I have a pop-up window where users enter data. It is setup as dialog using Visual C++. Sometimes I would like to display a note in this window that says "inches" and other times I would like this note to say "millimeters". I learned how to put up static messages, but I don't understand how to change them based on a variable in my C++ code. What is the simplest approach? Thanks ahead of time.
|
|
|
|
|
Are you using MFC? If so, you can add a CStatic control variable
to the window class, and use the CStatic::SetWindowText() method to
change the control's text.
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).
*edit* Actually, adding a string variable for the static control and using <br />
DDX is another possibly simpler MFC solution. I seem to have neglected that<br />
previously
If you use straight Win32, you can use the SetWindowText() API directly
on the control, something like:
HWND hwndControl = ::GetDlgItem(hwndDialog, IDC_MYSTATICCONTROL);
::SetWindowText(hwndControl, _T("New Text!"));
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the reply. Your answer changes the title of the window, but it led me to find the function:
void SetDlgItemText( int nID, LPCTSTR lpszString );
which seems to work okay for what I want.
|
|
|
|
|
For SetWindowText you need to a handle to controls but with SetDlgItemText you can use of control id.
|
|
|
|
|
Kwanalouie wrote: Your answer changes the title of the window
Not if the right HWNDs are used. For a static text/edit control HWNDs, the text
of the control should be set.
SetDlgItemText is great - it combines GetDlgItem() with SetWindowText() into one call
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
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?
|
|
|
|