|
Thanks its done.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
You are welcome...
- ns ami -
|
|
|
|
|
Create a button class, say CButtonEx, derived from CButton and map the ON_WM_KILLFOCUS message.
Change the class of the button control that you have to CButtonEx.
aks
|
|
|
|
|
Hi All,
In my MFC application,iam getting the values from equipment.It returns the string value with special character like READ with special character.That value is 0x17.
How to remove that special character in CString?
Pls help me..............
Thanks & Regards,
Anitha
|
|
|
|
|
You can use Remove()
See this[^]
- ns ami -
|
|
|
|
|
Hi,
how can i detect if the LAN cable is unlplugged, can i check the status of the connection?
what is the maximum number of sockets i can use in one application.
Thanks..
pramod
|
|
|
|
|
|
- how can i detect if the LAN cable is unlplugged, can i check the status of the connection?
try IsNetworkAlive() API
aks
|
|
|
|
|
There are alot of ways of determining the status of a network connection! All of the functions below will tell you the status of a network connection. Microsoft has provided us with many alternatives.
You could also use the IP Helper[^] tools to query the status something like this:
#include "Iphlpapi.h"
#pragma comment(lib, "iphlpapi.lib")
VOID PrintOperationalEthernet()
{
BYTE *pBuf=NULL;
DWORD dwSize=0;
DWORD dwResult=0;
BOOL bConnected=FALSE;
PMIB_IFTABLE pMIBTable;
CString str;
GetIfTable(NULL,&dwSize,FALSE);
pBuf=new BYTE[dwSize];
pMIBTable=reinterpret_cast<PMIB_IFTABLE>(pBuf);
if(NO_ERROR == GetIfTable(pMIBTable,&dwSize,FALSE))
{
for(UINT i=0; i < pMIBTable->dwNumEntries; ++i)
{
if(MIB_IF_TYPE_ETHERNET == pMIBTable->table[i].dwType)
{
bConnected = MIB_IF_OPER_STATUS_OPERATIONAL == pMIBTable->table[i].dwOperStatus;
char szBuf[MAX_PATH];
sprintf(szBuf,"%s is %s\n",pMIBTable->table[i].bDescr,
TRUE == bConnected?"Connected":"Offline");
TRACE(szBuf);
}
}
}
delete []pBuf;
}
You could also use the lower level DeviceIOControl[^] to query the device status directly from the network card like this:
#include <winioctl.h>
typedef ULONG NDIS_OID, *PNDIS_OID;
#define _NDIS_CONTROL_CODE(request,method) CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS)
#define IOCTL_NDIS_QUERY_GLOBAL_STATS _NDIS_CONTROL_CODE(0,METHOD_OUT_DIRECT)
#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114
typedef enum _NDIS_MEDIA_STATE
{
NdisMediaStateConnected,
NdisMediaStateDisconnected
} NDIS_MEDIA_STATE,*PNDIS_MEDIA_STATE;
VOID PrintOperationalEthernet()
{
int index =0;
DWORD dwType =0;
HKEY key;
HKEY cardkey;
CString str;
HANDLE hDevice;
NDIS_OID OidCode = OID_GEN_MEDIA_CONNECT_STATUS;
ULONG status=0;
ULONG dwRet=0;
TCHAR szCardVal[CHAR_MAX];
TCHAR szDescription[MAX_PATH];
TCHAR szDevice[MAX_PATH];
str.Format(_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\"));
if(ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,str,&key))
{
while(ERROR_SUCCESS == RegEnumKey(key,index++,szCardVal,CHAR_MAX))
{
str.Format(_T("%s\\%d"),str,_ttoi(szCardVal));
if(ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,str,&cardkey))
{
str = str.Left(str.ReverseFind('\\'));
DWORD dwLen = CHAR_MAX * sizeof(TCHAR);
if(ERROR_SUCCESS == RegQueryValueEx(cardkey,_T("ServiceName"),NULL,
&dwType,(LPBYTE)szCardVal,&dwLen))
{
RegQueryValueEx(cardkey,_T("Description"),NULL,
&dwType,(LPBYTE)szDescription,&dwLen);
_stprintf(szDevice,_T("\\\\.\\%s"),szCardVal);
hDevice = CreateFile(szDevice,GENERIC_READ,FILE_SHARE_READ|
FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0);
if(DeviceIoControl(hDevice,IOCTL_NDIS_QUERY_GLOBAL_STATS,
&OidCode,sizeof(NDIS_OID),&status,
sizeof(ULONG),&dwRet,NULL))
{
TCHAR szBuf[MAX_PATH];
_stprintf(szBuf,_T("%s is %s\n"),szCardVal,
NdisMediaStateConnected == status?_T("Connected"):_T("Offline"));
TRACE(szBuf);
CloseHandle(hDevice);
}
RegCloseKey(cardkey);
}
}
}
RegCloseKey(key);
}
}
You could also use the Internet Connection Firewall API[^] to determine the status of the network card such as below:
#include <netcon.h>
#define _WIN32_DCOM 1
typedef void(__stdcall *LPNcFreeNetconProperties)(NETCON_PROPERTIES *pProps);
VOID PrintOperationalEthernet()
{
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IDENTIFY,
NULL, EOAC_NONE, 0
);
HMODULE hmod=LoadLibrary(_T("netshell.dll"));
if(hmod)
{
LPNcFreeNetconProperties NcFreeNetconProperties=(LPNcFreeNetconProperties)\
GetProcAddress(hmod,"NcFreeNetconProperties");
INetConnectionManager *pMan=0;
HRESULT hres=CoCreateInstance(CLSID_ConnectionManager,0,CLSCTX_ALL,\
__uuidof(INetConnectionManager),(void **) &pMan);
if(SUCCEEDED(hres))
{
IEnumNetConnection *pEnum=0;
HRESULT hres=pMan->EnumConnections(NCME_DEFAULT,&pEnum);
if(SUCCEEDED(hres))
{
INetConnection *pCon=0;
ULONG count;
bool done=FALSE;
while(pEnum->Next(1,&pCon,&count) == S_OK && !done)
{
NETCON_PROPERTIES *pProps=0;
hres=pCon->GetProperties(&pProps);
if(SUCCEEDED(hres))
{
wchar_t wszBuf[MAX_PATH];
wsprintf(wszBuf,_T("%s is %s\n"),pProps->pszwName,
NCS_CONNECTED == pProps->Status?_T("Connected"):_T("Offline"));
TRACE(wszBuf);
NcFreeNetconProperties(pProps);
}
pCon->Release();
}
pEnum->Release();
}
pMan->Release();
}
FreeLibrary(hmod);
}
CoUninitialize();
}
As was previously mentioned the WMI Win32_NetworkAdapter Class[^] can be used to determine device state by checking the NetConnectionStatus member. Sorry... no WMI sample... I absolutely hate WMI.
Best Wishes,
David Delaune
|
|
|
|
|
If you've just typed all that, I'm impressed! (And skeptical!)
Good little batches of code.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote:
If you've just typed all that, I'm impressed!
I actually created all three functions last night specifically for the reply. I typed them in VC2008 and then pasted them here. It is easier with intellisense and guarantees that the code is correct and compiles.
Best Wishes,
-David Delaune
|
|
|
|
|
best posts as always. Good work, keep it up
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi,
Can some one provide me sample example for storing/retriving object of class from storage medium(i.e file)?
Mike.
|
|
|
|
|
|
I have a CString CString str= 104032;
how can i get substrings like 4032 or 32 or 04032 in vc++
thanks & regards
|
|
|
|
|
You can use Mid()of CString.
- ns ami -
|
|
|
|
|
l_d wrote: how can i get substrings like 4032 or 32 or 04032 in vc++
By reading here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
You can use Find().It will return the postion of the first character then use Mid()to extract that
Thanks & Regards
VIJITH VIJAYAN
|
|
|
|
|
Hi,
I have a pushbutton "Cancel" in my DialogBox that for some reason the Code doesn't get activated when I click on it
Actually the appearence seems give a hint of what the problem might be
When the Dialog comes up the button seems to have a perferation around it as if it is in a depressed state
I coded the DEFPUSHBUTTON as I have others but it does respond the same way below is the code for the Dialog
IDD_DIALOG6 DIALOGEX 0, 0, 316, 180
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Storage View"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
--> DEFPUSHBUTTON "Cancel",IDCANCEL1,205,159,50,14 <-- BUTTON IN QUESTION
CONTROL "",IDC_RICHEDIT21,"RichEdit20A",ES_MULTILINE | ES_WANTRETURN,80,28,180,105
LTEXT "Storage",IDC_STATIC,30,28,30,8
END
|
|
|
|
|
Did you override OnCancel() in your dialog class.
«_Superman_»
|
|
|
|
|
I am using plain old Win32 SDK
|
|
|
|
|
I just want you to check if you have mapped IDCANCEL and not destroying the dialog.
«_Superman_»
|
|
|
|
|
This the entire Dialog Code right below WM_INITDIALOG is the IDCANCEL1 case
I think the problem is the the Cancel button appears to be disabled meaning as if it has aleady been depressed (perferation around the button) Which is why in the INITDIALOG I do a BM_SETSTATE meesage
thankx again
case WM_INITDIALOG:
{
RichWindow = GetDlgItem(hwndDlg,IDC_RICHEDIT21);
SetFocus(RichWindow);
SendDlgItemMessage(hwndDlg, IDCANCEL1, BM_SETSTATE,0,0);
strncpy(&stor_start[0],&command[2],8); // copy command buffer
stor_start[8] = 0x00; // null mark
start_stor = atoi((const char *) &stor_start[0]); // convert to decimal
strncpy(&stor_end[0],&command[11],8); // copy over buffer
stor_end[8] = 0x00; // mark ens
end_stor = atoi((const char *) &stor_end[0]);
SendDlgItemMessage(hwndDlg, IDC_RICHEDIT21, EM_SETWORDBREAKPROC, 0, (LPSTR) EditWordBreakProc);
strcpy(&stor_char[0],&stor_start); // start at the begining
strncpy(&stor_buffer[0],&stor_start[0],8);
for (stor_count = start_stor; stor_count < end_stor; stor_count +=16)
{
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
cr.cpMin = 1;
cr.cpMax = 7;
SendDlgItemMessage(hwndDlg, IDC_RICHEDIT21, EM_EXSETSEL,0,&cr); // Set the Seelction
SendDlgItemMessage( hwndDlg, IDC_RICHEDIT21, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
strncpy(&stor_buffer[10],&buffer[buff_count],4);
buff_count+=4;
strncpy(&stor_buffer[15],&buffer[buff_count],4);
buff_count+=4;
strncpy(&stor_buffer[21],&buffer[buff_count],4);
buff_count+=4;
strncpy(&stor_buffer[26],&buffer[buff_count],4);
buff_count+=4;
stor_buffer[32]= '/r';
SendDlgItemMessage(hwndDlg, IDC_RICHEDIT21, WM_SETTEXT,0, (LPARAM) &stor_buffer[0]);
mysettext.flags = ST_DEFAULT;
mysettext.codepage = CP_ACP;
SendMessage(Stor_edit,EM_SETTEXTEX,&mysettext,(LPSTR) &stor_buffer[0]);
}
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
switch (LOWORD (wParam))
{
case IDCANCEL1:
DestroyWindow(hwndDlg);
hwndDlg = NULL;
break;
}
}
default:
return FALSE;
}
}
|
|
|
|
|
ForNow wrote: case WM_COMMAND:
switch (LOWORD(wParam))
{
switch (LOWORD (wParam))
{
case IDCANCEL1:
DestroyWindow(hwndDlg);
hwndDlg = NULL;
break;
}
}
If this is not a cut/paste error, remove one of these switch statements so that you have:
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDCANCEL1:
DestroyWindow(hwndDlg);
hwndDlg = NULL;
break;
}
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I am going to look at my code at home as I when I got the a Answer to my post
I was on my way to work (rushed) but I beleive I only have one switch
thankz again
|
|
|
|
|