Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MessageBox 1

Status
Not open for further replies.

peterve

IS-IT--Management
Joined
Mar 19, 2000
Messages
1,348
Location
NL
-level : beginner

Hi,

I have some code behind a button on my form.
When I press the button, some stuff gets executed (runs fine); including a custom written function.

I have defined the function in the same cpp file,
and prototyped the function at the top of the cpp file.

For some reason, when I try to run a simple MessageBox from within that function, it doesn't compile anymore...

error C2660: 'MessageBoxA' : function does not take 1 parameters

What is wrong here ?

--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
MessageBox(0, "message", "caption", 0);

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
thanks, that worked...
What's the deal behind the 0 as first and fourth parameter ?


Other (but quite similar question) :
How can I access a - for example - listbox from within the function ?

Accessing a listbox object from code behind a button works, but when I call a function - the code doesn't work anymore

For example :

CListBox *ListItems = (CListBox *) GetDlgItem(IDC_LIST1);
This code works within the code behind a button click,

but it does not compile when it sits in a function...




--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
fist 0 should be NULL. It is parent HWND of message box. The second 0 is style of box. It can be for example MB_OK, or MB_YESNO, or many other styles and/or combinations ebtween them.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
thanks

so, if we apply the same rule to the GetDlgItem function, what would be a working reference to IDC_LIST1 ?

(I read some articles on the internet about not using GetDlgItem anymore, and using member variables instead...
I'm using member variables in the code behind the buttons, but how can I reference to a member variable from another function ? So that's why I tried to use the GetDlgItem function...

Is there another way ? better way ?


--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
MessaegBox has nothing to do with dialog boxes.

If you want to use a DialogBox use

CYourDialog dlg;
int responce = dlg.doModal();
someValue= dlg.getSomeVariable...;
any values in DialogBoxes you will use inside them. To refresh variables use member method UpdateData.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
hmmm.. ok.. I guess my explanation s*cks... :-)
The reason why I linked MessageBox to my other problem was because they both gave compilation errors... so forget about the MessageBox for now :-)

This is the situation

Form, Listbox and a button
Application class: MyAppDlg
When clicking the button, some code does some stuff (works fine) and calls another function.

That function
#include otherfuncs.h
void func(int a)
{

}

is not a member of the MyAppDlg class
(I tried it, but the function is used because of functions in otherfuncs.h...
so when I declare function 'func' as
void MyAppDlg::func(int a)
it even gives me more errors...
(Maybe I should try to solve that... I don't know)
Anyways,
In that function I need to access the Listbox on the form,
but I'm getting compilation errors on the

CListBox *ListItems = (CListBox *) GetDlgItem(IDC_LIST1);
when trying to connect to the Listbox

Any ideas ? (Don't tell me to buy a book on Visual C++ and MFC; because I ordered it yesterday... I know I need that book for sure, but I want to make some progress in the meantime)

THanks


--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
what exactly error gives you the compiller?

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
1. When using the member variable of IDC_LIST1 (m_ListBox1)
I'm getting this error
Error C2597: illegal reference to data member 'CNetAccessMonitorDlg::m_ListBox1' in a static member function

This is the function
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
CListBox *SnifferLog = (CListBox *) GetDlgItem(CNetAccessMonitorDlg::m_ListBox1);
}


2. When using the object name

CListBox *SnifferLog = (CListBox *) GetDlgItem(IDC_LIST1);

then I'm getting
error C2660: 'GetDlgItem' : function does not take 1 parameters

--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
ok,
it means you access a nonstatic memebr or function from a static function. You can not do it.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I figured that one out...
But what did I do wrong ? How can I add a string to the listbox from a function that is not connected to the main form Class ?



--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
you should add handler to one of your button, double click on it in design mode and wizard will add handler automatically. Handler look like this:

void CYourDlg::OnBnClickedSomeButton()
{
// TODO: Add your control notification handler code here
m_ListBox1.AddString("hello");
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
ok, but suppose I call another function from within the button handler;
and suppose that function is declared as

void funct() instead of void CYourDlg::funct()

Then how can I access the listbox element on my form from within that function ?






--------------------------------------------------------------------
--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
You should find out some way to gibe to your function a pointer to your dialog. Usualy this does not make sence, but if you want it is possible.

CYourDlg* x = NULL;

BOOL CZzZzZDlg::OnInitDialog()
{
.....
x = this;//initialization of x
.....
}
//your function
void funct()
{
if(x)x->m_ListBox1.AddString("hello");
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top