|
Ok I don't use ON_COMMAND_RANGE because I don't know in advance how many items I will add...
|
|
|
|
|
But there's upper limit. You won't be adding 10000 items for sure.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Ok you're right ;o)
But this isn't the problem : I try to access to the dynamically created menu :
CMenu menu;
menu.LoadMenu(ID_MENU); // load the menu
CMenu* submenu = menu.GetSubMenu(1);
CMenu* namesmenu = submenu.GetSubMenu(...);
int nItem = namesmenu.GetMenuItemCount();
but it doesn't work...
|
|
|
|
|
Have no idea how your menu looks like. Check if 'submenu' points is non-NULL. If it points to some CMenu object, then check if it's actually the submenu you're looking for - use GetMenuItemCount/GetMenuString. If you get this right, proceed to namesmenu.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Is there actually a difference between a pointer and a handle, or is it just the context of what you happen to be talking about?
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
Pointer is an address of object. Handle is an opaque value. The implementor may use a pointer as handle, but it's also free to use index in array or any other value identifying the object. You can't dereference the handle as you do with pointer - you just obtain the handle from CreateFoo-style function and pass it to other functions. These functions know how to interpret the value of handle, while you don't.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Would it be fair to say that handles are references to objects defined by the Win32API? Kind of a pointer to a pointer. Whereas pointers are references to objects created and defined within the application itself.
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
Not exactly. While Win32 API uses handles, it's by no means the only place where handles are used. And surely you can't call them pointer to pointer, because they can be indices in array as well.
You can think of handles as magic cookies passed from/to library code. You don't need to know what do they mean. This knowledge is encapsulated in library itself.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
I think I get the difference, thanks!
we need an lightbulb icon, or something else denoting understanding
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
Handle is the more general concept, an arbitrary identifier for something.
A pointer is a memory address at which may (or may not) be an object.
All pointers are handles to their object(s memory), but most handles are not pointers.
Windows HWNDs are not pointers but (I think) indices into an array of windows.
STL iterators are handle-objects, with operators overloaded to mimic pointers.
I hope I have added my share to the confusion
|
|
|
|
|
I'm having problems with installing my app on other machines. I keep on gettting
"Failed to create empty document", after going through the source code It looks to me like this message is ouput when creation of the MainFrame fails.
I NEED the trace statements to figure our what is going on!
Is there any way i can redirect the TRACE statements to a file, i've thought redirecting the afxDump variable to a file but the assignment = operator is protected
BOOL CExplorerApp::InitInstance()
{
CFile dumpfile;
dumpfile.Open(_T("C:\\Jexlog.txt"),CFile::modeCreate|CFile::modeWrite);
CDumpContext dc(&dumpfile);
afxDump = dc;
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
|
WOW...
I have to admit in the time its taken me to respond i've fixed the problem using another method.
But still i'll definately bookmarking that site.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
How can i retrieve the local machine ip address and hostname. I searched here at CP but didn't find proper article.
|
|
|
|
|
Close....but search this forum.
|
|
|
|
|
char name[256] = "";
int nRet = gethostname(name, sizeof(name));
if ( nRet == SOCKET_ERROR )
MessageBox("gethostname() failed");
else
{
struct hostent * host = gethostbyname(name);
if ( host == NULL )
MessageBox("gethostbyname() failed");
else
{
struct in_addr addr;
memcpy(&addr, host->h_addr_list[0], sizeof(addr));
CString m_strHost;
m_strHost.Format( "%s", inet_ntoa(addr));
}
}
|
|
|
|
|
thanks for the ideas, it works, but now i have another question. I's like to load two different script files and rund the scripts almoust the same time. What do i have to do when i'm using the ActiveX Scripting engine from Microsoft (IActiveScript)?
|
|
|
|
|
Hi all,
How to check if field value is NULL?
In my application i am using the code as follows to get the Recordset field value
while (VARIANT_FALSE == pRecordset->EndOfFile)
{ strTemp.Format("Test Column:%s",
(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Test")->Value);
AfxMessageBox(strTemp);
pRecordset->MoveNext();
}
while running the application if the Field value is NULL. I am getting Runtime Error
as "abnormal Programme termination".
please help me
anju
|
|
|
|
|
Consider query:
select nick from from mytable .
Suppose the value represented by nick can be NULL. So change the query as:
select isnull(nick, 'something') as nick from mytable
Here 'something' can be anything you desire. This can be a single space character also. Now when you collect value of nick from Recordset object, it'll not be null but the value supplied by you as a parmeter above. You can check it and treat as NULL
Imran Farooqui
World first Urdu Instant Messenger[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Java is a tool for creating applications that torture users with its awful speed and its ugly interfaces.
Daniel Turini commenting on this article
|
|
|
|
|
Hi Imran Farooqui,
Thanks for Your Reply.
Please need more help to me..............
Suppose i have to select entire table then how can i make all null fields in the table to 'Something'.
in my application i am opening the recordset as follows
pRecordset->Open("mytable",
_variant_t((IDispatch*)pConnection,true),
adOpenDynamic, adLockPessimistic,adCmdTable);
and i am getting all the fields
pRecordset->MoveFirst();
while (!pRecordset->EndOfFile)
{
strTemp.Format("Field1:%s",(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Field1")->Value);
AfxMessageBox(strTemp);
pRecordset->MoveNext();
}
anju
|
|
|
|
|
In your code, you'r opening a complete table using RecordSet object. I do not prefer this technique because you have no control over the selected records. Instead i prefer to explicitly open the table using SQL queries.
m_pRecordSet = m_pConnection->Execute("select * from mytable", &vRecsAffected, adOptionUnspecified);
Only if you are accessing the table in this way, you can use, isnull option.
Imran Farooqui
World first Urdu Instant Messenger[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Java is a tool for creating applications that torture users with its awful speed and its ugly interfaces.
Daniel Turini commenting on this article
|
|
|
|
|
You need to do something like this.
_variant_t vt = pRecordset->Fields->GetItem("Test")->Value;
if (vt.vt == VT_NULL)
{
AfxMessageBox("Field is NULL");
}
else
{
strTemp.Format("Test Column:%s",(LPSTR)(_bstr_t)vt);
AfxMessageBox(strTemp);
}
C# is fundamentally broken. - Christian Graus
|
|
|
|
|
This line:
<br />
(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Test")->Value); <br />
is very dangerous because of the following reasons:
If Fields fails, an exception will be thrown.
If GetItem fails, an exception will be thrown.
If Value cannot be converted to a _bstr_t, an exception will be thrown.
Segment your code a little better. Add exception handling, or use the raw_ methods of your smart pointers. Here is an example on how to improve your code (this is from memory):
<br />
IFieldPtr field;<br />
try<br />
{<br />
field = pRecordset->Fields->GetItem("Test");<br />
} <br />
catch(com_error e) <br />
{ <br />
field = NULL;<br />
}<br />
<br />
if(field != NULL)<br />
{<br />
_variant_t vtVal;<br />
try<br />
{<br />
vtVal = field->Value;<br />
} catch (_com_error e) {vtVal.vt = VT_ERROR; }<br />
<br />
_bstr_t bstrVal;<br />
if(vtVal.vt != VT_ERROR)<br />
{<br />
try{ bstrVal = (_bstr_t)vtVal; }<br />
catch(com_error e) {bstrVal = L"";}<br />
}<br />
<br />
AfxMessageBox((LPCTSTR)bstrVal);<br />
}<br />
<br />
--James
Drinking In The Sun
Forgot Password?
|
|
|
|
|
Hi Rama Krishna,
ThankQ this technique is work to me well
anju
|
|
|
|
|
Hi James Pullicino,
Thanks a lot..
I never thing about what u pointed.
now my code is changed as per your instructions.
once again thank to you
anju
|
|
|
|