|
Hi to all,
Can u help me in How to disable a Menu Item. i am trying this code but not getting.
CMenu menu;
menu = AfxGetMainWnd()->GetMenu();
menu->EnableMenuItem(ID,MF_BYCOMMAND|MF_DISABLED);
|
|
|
|
|
From MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wcemfc4/html/aflrfcmenucolcolenablemenuitem.asp[^])
This method either enables or disables and dims a menu item.
UINT EnableMenuItem (
UINT nIDEnableItem,
UINT nEnable );
Parameters
nIDEnableItem
Specifies the menu item to be enabled, as determined by nEnable. This parameter can specify pop-up menu items as well as standard menu items.
nEnable
Specifies the action to take. It can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by using the bitwise OR operator. These values have the following meanings:
MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.
MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position zero.
MF_DISABLED Disables the menu item so that it cannot be selected but does not dim it.
MF_ENABLED Enables the menu item so that it can be selected and restores it from its dimmed state.
MF_GRAYED Disables the menu item so that it cannot be selected and dims it.
Return Value
Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED) or –1 if not valid.
So, try MF_GRAYED. The the menu item will be both disabled and grayed.
-- modified at 8:56 Wednesday 14th September, 2005
|
|
|
|
|
doh: I use WMI to set Ip Address for my local computer.
every function works well. but nothing changed.
Why?? I use vc6,xp OS. For some header files,you can found them from vc7, just copy them to the Include directory for vc6.
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
for a test,the above line must be modified.replace "MyComputerName" with your own computer name.
I paste all the code here. A win32 console app.
Thank you everyone.
#define _WIN32_DCOM
#include
#pragma comment(lib,"Wbemuuid.lib")
#include
//#include "wbemcli.h"
#include "objbase.h"
#include
#include
#pragma comment(lib, "comsupp.lib")
void CreateOneElementBstrArray(VARIANT* v, LPCWSTR s)
{
SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
// Determine number of bytes to be allocated for ANSI string. An
// ANSI string can have at most 2 bytes per character (for Double
// Byte Character Strings.)
cbAnsi = cCharacters*2;
// Use of the OLE allocator is not required because the resultant
// ANSI string will never be passed to another COM component. You
// can use your own allocator.
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
// Convert to ANSI.
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
void PrintWMIError(HRESULT hr)
{
IWbemStatusCodeText * pStatus = NULL;
HRESULT hres = CoCreateInstance(CLSID_WbemStatusCodeText, 0,
CLSCTX_INPROC_SERVER,IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
if(S_OK == hres)
{
BSTR bstrError;
hres = pStatus->GetErrorCodeText(hr, 0, 0, &bstrError);
if(S_OK != hres)
bstrError = SysAllocString(L"Get last error failed");
LPSTR pszStatusTextA;
UnicodeToAnsi(bstrError, &pszStatusTextA);
printf("%s\n",pszStatusTextA);
CoTaskMemFree(pszStatusTextA);
pStatus->Release();
SysFreeString(bstrError);
}
}
HRESULT ConfigNet()
{
IWbemLocator *pLocator=NULL;
IWbemServices *pNamespace=NULL;
IWbemClassObject *pClass=NULL;
IWbemClassObject *pInputParamClass=NULL;
IWbemClassObject *pInputParamInstance=NULL;
IWbemClassObject * pOutInst = NULL;
BSTR InstancePath = SysAllocString(L"Win32_NetworkAdapterConfiguration=2");
HRESULT hr;
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IPAddress";
VARIANT var1;
LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
__try
{
CreateOneElementBstrArray(&var1, L"10.0.0.101");
CreateOneElementBstrArray(&var2, L"255.255.255.0");
CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLocator);
hr = pLocator->ConnectServer(Path,NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
hr = CoSetProxyBlanket( pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pClass->GetMethod(MethodName, 0, &pInputParamClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamClass->SpawnInstance(0, &pInputParamInstance);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg1Name, 0, &var1, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg2Name, 0, &var2, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL,
pInputParamInstance, &pOutInst, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
}
__finally
{
if(pInputParamInstance)
pInputParamInstance->Release();
if(pInputParamClass)
pInputParamClass->Release();
if(pClass)
pClass->Release();
if(pNamespace)
pNamespace->Release();
if(pLocator)
pLocator->Release();
}
return hr;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ConfigNet();
CoUninitialize();
printf("Program end\n");
return 0;
}
|
|
|
|
|
for my computer Win32_NetworkAdapterConfiguration.Index=2
for which IPEnabled=TRUE.
The value of the index may be different for your computer.
|
|
|
|
|
unreadable
and where are you going with this title ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
and where are you going with this title ?
I think it has something to do with the same question having gone unanswered at least three other times in the past week or so.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
not surprising if he still ask the point the same awful way...
same question, same answers...
personnaly, when i saw the post, i just closed it !
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Oh,do you think it is awful?
but how could I do much better?
since there isn't much code , I just post all.\
I have no other way
I'm so sorry
|
|
|
|
|
Tcpip2005 wrote:
but how could I do much better?
by writing a bit more clearly, more spaced... using <pre></pre> around your code why not ?!
Tcpip2005 wrote:
since there isn't much code
and you would post much more again ?????
don't you think it's enough already ?
would you be happy one overload your servers that way for 'unansweredable' question ?
didn't you wonder that if anybody was answering, it could be just the simple fact that nobody knows the answer to your problem... ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I'm so sorry.
I have post the code again
Thank you very much!
|
|
|
|
|
I'm sorry.
I haven't see the words just now.
sorry. this is my last time to post this question here.
last time, I will never post this again.
I'm so sorry.
god forgives me
|
|
|
|
|
Yes,you are right.
I have pasted the same qustion here for three time until now.
I am so sad. I can't fix it until now . So sad.
there is a C# writen program on codeproject. but I have to use vc6,not .Net Framework.
please! give me a help.
|
|
|
|
|
#define _WIN32_DCOM
#include <Wbemidl.h>
#pragma comment(lib,"Wbemuuid.lib")
#include <atlbase.h>
#include "objbase.h"
#include <windows.h>
#include <comutil.h>
#pragma comment(lib, "comsupp.lib")
void CreateOneElementBstrArray(VARIANT* v, LPCWSTR s)
{
SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
cbAnsi = cCharacters*2;
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
void PrintWMIError(HRESULT hr)
{
IWbemStatusCodeText * pStatus = NULL;
HRESULT hres = CoCreateInstance(CLSID_WbemStatusCodeText, 0,
CLSCTX_INPROC_SERVER,IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
if(S_OK == hres)
{
BSTR bstrError;
hres = pStatus->GetErrorCodeText(hr, 0, 0, &bstrError);
if(S_OK != hres)
bstrError = SysAllocString(L"Get last error failed");
LPSTR pszStatusTextA;
UnicodeToAnsi(bstrError, &pszStatusTextA);
printf("%s\n",pszStatusTextA);
CoTaskMemFree(pszStatusTextA);
pStatus->Release();
SysFreeString(bstrError);
}
}
HRESULT ConfigNet()
{
IWbemLocator *pLocator=NULL;
IWbemServices *pNamespace=NULL;
IWbemClassObject *pClass=NULL;
IWbemClassObject *pInputParamClass=NULL;
IWbemClassObject *pInputParamInstance=NULL;
IWbemClassObject * pOutInst = NULL;
BSTR InstancePath = SysAllocString(L"Win32_NetworkAdapterConfiguration=2");
HRESULT hr;
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IPAddress";
VARIANT var1;
LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
__try
{
CreateOneElementBstrArray(&var1, L"19.9.20.19");
CreateOneElementBstrArray(&var2, L"255.255.0.0");
CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (void**)&pLocator);
hr = pLocator->ConnectServer(Path,NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
hr = CoSetProxyBlanket( pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pClass->GetMethod(MethodName, 0, &pInputParamClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamClass->SpawnInstance(0, &pInputParamInstance);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg1Name, 0, &var1, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg2Name, 0, &var2, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL,
pInputParamInstance, &pOutInst, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
}
__finally
{
if(pInputParamInstance)
pInputParamInstance->Release();
if(pInputParamClass)
pInputParamClass->Release();
if(pClass)
pClass->Release();
if(pNamespace)
pNamespace->Release();
if(pLocator)
pLocator->Release();
}
return hr;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ConfigNet();
CoUninitialize();
printf("Program end\n");
return 0;
}
|
|
|
|
|
|
Hello Tcpip2005, How are you doing? when ever you are trying to copy code in code project, then just try to use html tags. like this.
< is used for less than symbol. = "<"
> is used for grater than symbol. = ">"
Then your code can be readable.
Or check the Check Box(Do not treat <'s as HTML tags) when ever you post question?
Nice talking to you.
|
|
|
|
|
Ok the situation is this, Im doing some applications , the first one is an application with 3 buttons that also has an Ip control with that application I put the Ip adress of the application (Server) that is an audio application that capture Audio.
with the first application (the one with the 3 buttons, starting, stoping and exit button, I send one character to the audio application)
I took one audio capture application from the codeproject to use it on my project, the problem is that I dont know how to put support to windows sockets, the audio application is made it in Visual C++ in a MFC, somebody knows how to paste the code to give support to the sockets.
something like the wizzard does when you are generating the MFC application that you can add support to 3d buttons, and sockets.
and also, somebofy knows about another audio capture application that I could use to my project.
another question that I have, if somebody can help me, is that Im just starting in the world of the code, and the POO,
so I need to take this data ( the buffer of the captured audio and send it through the socket, but I dont know how to do it.
can I use the function RECV(s2, &buffer,1,0)
where s2 is the socket that Im using, but I dont know what to put in the other params)
if somebody could help me,
GOD BLESS YOU
my email is
rubencia@yahoo.com
thanx again to everybody
SHALOM
|
|
|
|
|
REU,
Is this homework? Be honest...
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
Hi!Dear,
when building my project on vc++6.0,i got a link error.
It says:
"strmbasd.lib(wxdebug.obj):error LNK2001:unresolved symbol_imp_strrchr"
so,how to settle this problem?
thanks!
|
|
|
|
|
try using any of these LIBC.LIB or LIBCMT.LIB or MSVCRT.LIB ,make sure it is linked before strmbasd.lib
|
|
|
|
|
Hello,
I would to have an Dialog with PassQuerry...
The User shouldn't leave the Dialog and Click anything else on Desktop..
The Windowskey or STRG-ALT-ENTF, STRG-TAB and other Keys must be Inactive...
The User should Interact with the Dialog ONLY....
What's the answer???
Thanx,
Dachs
|
|
|
|
|
make that dialog system modal by checking system modal property.
I'm not sure about second point but, you can definitely trap those messages
|
|
|
|
|
prasad_som wrote:
make that dialog system modal by checking system modal property.
AFAIK, System Modal dialog no longer work in NT based System...
Sorry for correcting you again....
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
|
Ok the situation is this, Im doing some applications , the first one is an application with 3 buttons that also has an Ip control with that application I put the Ip adress of the application (Server) that is an audio application that capture Audio.
with the first application (the one with the 3 buttons, starting, stoping and exit button, I send one character to the audio application)
I took one audio capture application from the codeproject to use it on my project, the problem is that I dont know how to put support to windows sockets, the audio application is made it in Visual C++ in a MFC, somebody knows how to paste the code to give support to the sockets.
something like the wizzard does when you are generating the MFC application that you can add support to 3d buttons, and sockets.
and also, somebofy knows about another audio capture application that I could use to my project.
another question that I have, if somebody can help me, is that Im just starting in the world of the code, and the POO,
so I need to take this data ( the buffer of the captured audio and send it through the socket, but I dont know how to do it.
can I use the function RECV(s2, &buffer,1,0)
where s2 is the socket that Im using, but I dont know what to put in the other params)
if somebody could help me,
GOD BLESS YOU
my email is
rubencia@yahoo.com
thanx again to everybody
SHALOM
REUBEN JAIM
|
|
|
|
|
I have referred to the FAQ but the answer does not solve the problem actually...
Below is my code of creating srevice:
--------------------------------------------------------------------------------------------------
SC_HANDLE hService =
::CreateService(
handle, // handle to SCM database
servicename.c_str(), // name of the service to install
servicename.c_str(), // name that is displayed on SCM
SERVICE_ALL_ACCESS, // can be accessed only by administrators
SERVICE_WIN32_OWN_PROCESS, // service runs its own process
SERVICE_AUTO_START, // started by SCM when StartService() is called
SERVICE_ERROR_IGNORE, // error logged but service started
ss, // pathname of the executable
NULL, // service does not belong to any group
NULL, // service does not use a tag
NULL, // requires NtLmsSp and EventLog service to be running
".\\Administrator", // user name to log on
"s" // password
);
--------------------------------------------------------------------------------------------------
|
|
|
|
|