|
Thank you very much!! U help me a lot!;P
I want to ask if u want to get the text u key in on combo box and then insert it into mysql database. How to get the text and then convert to vachar so that can insert into database?????
|
|
|
|
|
I don't know if i've understood you
get the text from combobox is:
CString str;
GetDlgItem(IDC_COMBO...)->GetWindowText(str);
convert str to char is with:
char test[100];
test=str.GetBuffer(str.GetLength());
|
|
|
|
|
That what i mean. But got error when i try to run it.
The error is below:
error C2440: '=' : cannot convert from 'char *' to 'char [100]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
Thanks!
|
|
|
|
|
then use only the pointer
char *temp = str.GetBuffer.....
|
|
|
|
|
I change to pointer oledi but still cannot insert to database.
The 'test' is not recognize by the database and declase as char test to insert into database and not the text you key in. Help me please
MYSQL mysql;
//MYSQL *connection;
CString str;
GetDlgItem(IDC_COMBO1)->GetWindowText(str);
char * test;
test=str.GetBuffer(str.GetLength());
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
mysql_real_connect(&mysql,"localhost", "admin", "123", "test", 0, NULL, 0);
sprintf(sql,"INSERT INTO %s (CodPais,Nombre,Prefijo,Code) VALUES ('auto','test','','te')",table); //e.g. i don't know your database
//modify ist with UPDATE and delete ist with DELETE FROM look api
mysql_query(&mysql, sql);
//add ist with insert into table values
mysql_close(&mysql);
MessageBox("Data telah ditambah");
|
|
|
|
|
you have to modify sprintf.
Show the useage of sprintf
sprintf(sql,"INSERT INTO %s table VALUES ('auto','%s','','te')",table, test.GetBuffer(getLength()) );
if you only write test "he" thinks it is a string not a variable
Heiko
|
|
|
|
|
There still got error. Is that my code below got problem?
#define table "paises"
// TODO: Add your control notification handler code here
char sql[4000];
//m_cboPais.GetLBText(m_cboPais.GetCurSel(),d);
MYSQL mysql;
//MYSQL *connection;
CString str;
GetDlgItem(IDC_COMBO1)->GetWindowText(str);
char * test;
test=str.GetBuffer(str.GetLength());
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
mysql_real_connect(&mysql,"localhost", "admin", "123", "test", 0, NULL, 0);
//sprintf(sql,"INSERT INTO %s VALUES ('auto',\test,'','te')",table); //e.g. i don't know your database
//modify ist with UPDATE and delete ist with DELETE FROM look api
sprintf(sql,"INSERT INTO %s table (CodPais,Nombre,Prefijo,Code) VALUES ('auto','%s','','te')",table, test.GetBuffer(getLength()) );
mysql_query(&mysql, sql);
//add ist with insert into table values
mysql_close(&mysql);
MessageBox("Data telah ditambah");
Error statement:
C:\Documents and Settings\lau\Desktop\myfuture\mysql++\DlgMySql2\DlgMySqlDlg.cpp(215) : error C2228: left of '.GetBuffer' must have class/struct/union type
C:\Documents and Settings\lau\Desktop\myfuture\mysql++\DlgMySql2\DlgMySqlDlg.cpp(215) : error C2065: 'getLength' : undeclared identifier
Error executing cl.exe.
|
|
|
|
|
Sorry,
my fault again
that's why test is not a CString.
Cstring str;
GetDlgItem(IDC_...).>GetWindowText(str);
sprintf(sql,"INSERT INTO %s table VALUES ('auto','%s','','te')",table, str.GetBuffer(str.getLength()) );
tip: have a look at MSDN at the members of CString
Heiko
|
|
|
|
|
i get the following compilation problem in the following code:
-------------------------------------------------------------------------------------------------
class CXFaceRecognitionDlg : public CDialog
{
// Construction
public:
CXFaceRecognitionDlg(CWnd* pParent = NULL); // standard constructor
// TODO:Why compilation error goes here??
CStatusBar GetStatusBar(){ return m_wndStatusBar; }
protected:
HICON m_hIcon;
CStatusBar m_wndStatusBar;
-------------------------------------------------------------------------------------------------
d:\documents and settings\lim ming wee's pc\my documents\yccheok\xfacerecognition\xfacerecognitiondlg.h(29) : error C2558: class 'CStatusBar' : no copy constructor available
i solve it by changing the statement from
CStatusBar GetStatusBar(){ return m_wndStatusBar; } ==>
CStatusBar& GetStatusBar(){ return m_wndStatusBar; }
and solve the problem.
however, i have no idea what is the cause of this problem. can anyone tell me why?
thank you.
regards
yccheok
|
|
|
|
|
As the compiler said:
no copy constructor available
You cannot create a new CStatusBar instance from an existing one. You must either use references (as you have done it) or pointers.
So
CStatusBar bar1;
CStatusBar bar2 = bar1; would fail. Correct is
CStatusBar bar1;
CStatusBar *bar2 = &bar1;
...
anyfunction(*bar2, ...);
But remember, if you change bar2, bar1 changes too.
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
i just move from c to c++ recently and have no idea on the causes of the following compilation problem (i am using visual c++ 6.0).
=======================================================================
// FaceDlg.h
#include "Picture.h"
class CFaceDlg : public CDialog
{
// Construction
public:
CFaceDlg(CWnd* pParent = NULL); // standard constructor
void SayHai(void);
=======================================================================
// Picture.h
class CFaceDlg;
class CPicture : public CStatic
{
// Construction
public:
CPicture(CFaceDlg* parent);
CFaceDlg* m_pParent;
=======================================================================
// FaceDlg.cpp
BOOL CFaceDlg::OnInitDialog()
{
// ... wizard generated initialization code ommited...
// TODO: Add extra initialization here
m_pPicture = new CPicture(this);
return TRUE; // return TRUE unless you set the focus to a control
}
=======================================================================
// Picture.cpp
CPicture::CPicture(CFaceDlg* parent)
{
m_pParent = parent;
//??? m_pParent->SayHai();
}
=======================================================================
The following code compile no problem. however, when i try to uncomment out
m_pParent->SayHai() in CPicture constructor, i get the following error:
D:\Documents and Settings\Lim Ming Wee's PC\Desktop\Face\Picture.cpp(20) : error C2027: use of undefined type 'CFaceDlg'
d:\documents and settings\lim ming wee's pc\desktop\face\picture.h(12) : see declaration of 'CFaceDlg'
D:\Documents and Settings\Lim Ming Wee's PC\Desktop\Face\Picture.cpp(20) : error C2227: left of '->SayHai' must point to class/struct/union
Error executing cl.exe.
can anyone tell me how to solve this problem?
thank you.
regards
yccheok
|
|
|
|
|
I find it easier to let the class wizard make my dialog boxes than to code them by hand.
|
|
|
|
|
In FaceDlg.cpp #include "FaceDlg.h" .
In Picture.cpp #include "Picture.h" .
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
I have a strange problem. I create a toolbar on my mfc application and I load a bitmap with buttons.
My buttons are red but when the toolbar apears the buttons are almost black, like the brightness has been reduced
to almost 5%.
The code looks like this.
UINT buttons[3] = {ID_ADD,ID_NEWS,ID_OTHER_VIEW};
if (!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadBitmap(IDB_MY_TOOLBAR) ||
!m_wndToolBar.SetButtons(buttons,3))
{
TRACE0("Failed to create myToolBar\r\n");
return -1;
}
m_wndToolBar.SetSizes(CSize(37,36),CSize(30,30));
Does anyone have any idea? I've look through MSDN but I didn't find anything related to this.
Thanks.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
the code like this:
UINT MyThread(LPVOID){
while(1){
::SendMessage(lParam->m_hWnd, WM_MYMESSAGE, 0, 0);
sleep(100);
}
return 0;
}
void A::Fun1(){ //this function will be called frequencily (eg. 10ms)
m_count++; //the member variable;
}
void A::Fun2(){ //this function receive the WM_MYMESSAGE message;
i=m_count;
m_count--;
~~~~~~~~~~~~ if there is only one A object, it's right;
but if there are two or more A objects, some of
them will wrong, the m_count will always 0 in
Fun2(),why?
thank's for you help.
}
.
|
|
|
|
|
Hmm, it's quite difficult to say from the source you provided m_count is a member of A, I assume.
Did you ever call the Fun1() for the second instance? Or it is just always called only for the first one? This would be probably the reason I guess.
|
|
|
|
|
yes, m_count is a member of A,
i call every A instances's Fun1(), but not every one can work,
some of them maybe wrong. but this matter is not allways happened.
I use them like this:
CDlg1 has a A instance m_first;
CDlg2 has a A instance m_second;
I add the CDlg1 dlg1, CDlg2 dlg2 in a TabCtrl;
normally the m_first and m_second can work.
but sometime the m_first maybe wrong, and sometime the m_secodn
maybe wrong.
.
|
|
|
|
|
then I'd put the following trace to the Fun1() as well as to the Fun2() . You should see diffenent numbers - you will see exactly what is stored in m_count in different instances. This could help to define the next debugging steps.
<br />
TRACE( "instance 0x%08X called, m_count = %d\r\n", this, m_count );<br />
|
|
|
|
|
One reason the design does not work is because there is no synchronization. Threads and processes must be synchronized.
Kuphryn
|
|
|
|
|
to geo_m:
thank you for your help, i add the TRACE in the Fun2(),then
i find one of the A instance create the thead failed;
When i call AfxBeginThread(), it return 0, so some A do not work.
thank you very much.
.
|
|
|
|
|
to geo_m:
thank you for your help, i add the TRACE in the Fun2(),then
i find one of the A instance create the thead failed;
When i call AfxBeginThread(), it return 0, so some A do not work.
i call it again, it's ok!
but i don't understand why it will fail.
.
|
|
|
|
|
In a DLG based app,I want to draw something on a CONTROL (static) and there are some another CONTROL on the Dialog.
I Get the DC of the Static control and draw something on it,but failed.I see nothing on the static control.So I delete the sentnce
CDialog::OnPaint()
And then,all of these control except the staitc can't be seen.(they are not being paint)
I want to paint the Static control but hope the other control will draw it themself!
How can I do?
Thank you for your help!
Don't look at me in that way!
|
|
|
|
|
from the MSDN under GetDlgItem, changed to be a CStatic, assuming you are using the MFC
// uses GetDlgItem to return a pointer to a user interface control
CStatic* pStatic;
pStatic= (CStatic*) GetDlgItem(IDC_STATIC1);
pStatic->SetWindowText(_T("Hello world"));
<HR SIZE=1 /HR>
<i>If I have seen further it is by standing on the shoulders of Giants.</i> - Isaac Newton 1676
|
|
|
|
|
I just want to draw a picture on it!
exmaple:
I want to draw some lines on the static control!
when I do this ,nothing can be seen in the control.
Don't look at me in that way!
|
|
|
|
|
I am working from memory here.
In that case the best method, I think, would be to subclass the control.
Or you could try get the CDC of the static control, using my #1 method and use this to paint, also add the paint logic into the OnPaint. BUT the control may decide to paint it it's slef therefore overwriting what you have put there! I use this method to place a bitmap into a static control.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|