|
Ian Bowler wrote: If so, I don't think that will work because I'm not using CDialog.
MFC is not an issue here. It is a standard Windows message that you can send to a control.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
u can set up a default button
right click the button in
the resource editor , click on property,
go to the style tab , check mark the
Set default check box,
I think that willl solve ur problem
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Ian Bowler wrote:
I need to set a button as a default button (get's pressed when ENTER is pressed). I'm not using CDialog, so SetDefID is out.
are you dynamically creating the Button then use BS_DEFPUSHBUTTON while creating the button otherwise use technique mention by Vikas
"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
|
|
|
|
|
Yes, I am dynamically creating the button. I tried using the BS_DEFPUSHBUTTON style but that did not work. The button that I'm wanting to set as the default is in a hosted ActiveX control. Could that be part of the problem? The hosted ActiveX control's UI is built on CView-derived class. This class owns a CWnd-derived class, which owns the CButton that I want to make default. When the CWnd-derived object or one of its child objects has the focus, I want the ENTER key to activate the CButton.
Here is a diagram that I hope will help:
--------------------------------------------------------------------------------------
Application
------------------------------------------------------
| ActiveX control
| ------------------------------------------
| | CView
| | ---------------------------------
| | | CWnd
| | | ---------- When this CWnd-derive class or any of its child MFC
| | | |CButton | controls have focus, I want the CButton to get
| | | ---------- pushed when the ENTER key is pressed.
| | ---------------------------------
| |
| ------------------------------------------
|
------------------------------------------------------
--------------------------------------------------------------------------------------
Thanks again for taking the time to help!
-- modified at 11:27 Thursday 13th October, 2005
|
|
|
|
|
Hello,
I have the following problem. I want to create a temporary object that is transparent to the caller of the function which creates the temporary. We all know that values returned by value from a function, the temporary is created on the stack until it is no longer needed.
I wan't to use this property of the temporary to create a locking / unlocking mechanism for an object. See the following code for details
class CArbitraryClass
{
public:
void DoFoo() {}
};
class CWrapperClass
{
public:
CInvisibleTemporary operator->()
{
return CInvisibleTemporary::CInvisibleTemporary();
}
};
class CInvisibleTemporary
{
public:
CArbitraryClass& operator->() { return m_ArbitraryObject; }
private:
CArbitraryClass m_ArbitraryObject;
};
So the code should look like the following statements:
CWrapperClass Wrapper;<br />
Wrapper->DoFoo();
But it looks like:
CWrapperClass Wrapper;<br />
Wrapper.operator ->().operator ->().DoFoo();
Am I trying to do something impossible?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I can't figure this out, Please Help!!!! I would appreciate any remarks
or opinions or help about the code below.
A you can see I am writing and reading from the serial port, that is
going OK MOST of the time. My big problem is when I want to break the
while loop. I am expecting a message in HEX to come in from the serial
port. for instance "0004 600A", which I get most of the time, sometimes
I just get random ASCII chars, anyway to the point
Question #1 is the way I am storing the read return(it seems to work
alright) the best way to do it, char in[13] ?
Question #2 I need to test the response in terms of binary?
0000 0000 0000 0100 0110 0000 0000 1010
I can manage to test the bit that I am interested in but how to get to
this point I am not to sure about.
Lastly, any remarks or bug fixes on the general structure of the my
code would be great
//************************************************************************************************************//
int _tmain(int argc, _TCHAR* argv[])
{
CSerial serial;
//CSyncSerialComm serial2("COM1");
char in[13];
char command[20];
DWORD bytesRead;
int value=1000;
int end;
int test;
serial.Open(1, 9600);
//serial.HomePosition(4);
while(1)
{
printf("\nEnter Command >>");
scanf("%d", &value);
sprintf(command, "4 lr %d\r4 m\r4 st\r", value);
serial.SendData(command, sizeof(command));
end = serial.ReadData(&in,20);
in[end] = '\0';
printf("value = %s",in);
if((int)in[7] > 4)
break;
}
serial.Close();
getchar();
return(0);
}
//***************************************Writing
Data**************************************//
bool CSerial::WriteCommByte( unsigned char ucByte )
{
bool bWriteStat;
DWORD dwBytesWritten;
bWriteStat = WriteFile( m_hIDComDev, (LPSTR) &ucByte, 1,
&dwBytesWritten, &m_OverlappedWrite );
if( !bWriteStat && ( GetLastError() == ERROR_IO_PENDING ) ){
if( WaitForSingleObject( m_OverlappedWrite.hEvent, 1000 ) )
dwBytesWritten = 0;
else{
GetOverlappedResult( m_hIDComDev, &m_OverlappedWrite,
&dwBytesWritten, FALSE );
m_OverlappedWrite.Offset += dwBytesWritten;
}
}
return( TRUE );
}
int CSerial::SendData( const char *buffer, int size )
{
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
DWORD dwBytesWritten = 0;
int i;
for( i=0; i
|
|
|
|
|
bigjrags wrote:
Question #1 is the way I am storing the read return(it seems to work
alright) the best way to do it, char in[13] ?
This code snippet makes me doubt:
end = serial.ReadData(&in,20);
I do not know about the CSerial class, and therefore do not know what ReadData needs as parameters, but something tells me that the fact that 20 is greater than 13 is no good
This
while(1)
{
..
if((int)in[7] > 4)
break;
}
is a good way to get your application hang in case the expected break value never gets sent, or wrongly received. A condition where the user could interrupt the reading is much better than (1) .
bigjrags wrote:
I need to test the response in terms of binary?
What do you mean: Are you asking how to do it, or if you have to do it ?
~RaGE();
|
|
|
|
|
WebConn error LNK2019: unresolved external symbol __imp__InternetOpenA@20 referenced in function _main
My program "WebConn" keeps getting this error when ever I use items in the wininet.h class.
I'm using Visual Studio .Net 2003, C++.
Any help would be great!
Brad
#define WINVER 0x0400
#include "stdafx.h"
#include
#include
int main()
{
HINTERNET hInternetRoot;
hInternetRoot = InternetOpen("My Agent", INTERNET_OPEN_TYPE_PROXY, "127.0.0.1", "",0);
return 0;
}
|
|
|
|
|
go to properties-->Linker-->Input-->Additional dependencies add wininet.lib there
|
|
|
|
|
Hello,
I'm currently working on a project to "do away" with a given .ocx and bring that functionality into the application that used to use the ocx. I'm trying to alter the main part of the ocx from a Control to a View. That's where I'm having problems.
I've tried to use CCtrlView to take the Control and give it View properties, but I'm having trouble registering the Control class in order to use CCtrlView properly.
Any help with this would be much appreciated. Thanks.
|
|
|
|
|
Hi,
I was wondering if its possible to create, for example, a Critical Section in a multithreaded environment. In other words, I know that you may not call InitializeCriticalSection more than once with the same pointer before you call DeleteCriticalSection. Anyway I want to know if there's a way to serialize calls to InitializeCriticalSection without using another critical section/mutex/semaphore (using it would be delaying the problem) or if you always need a method that's executed by one and only one thread to initialize all the syncronization objects in a process. This would not be a problem if initialization could be done statically.
I would really appreciate your answer,
Federico
|
|
|
|
|
Federico Milano wrote:
I was wondering if its possible to create, for example, a Critical Section in a multithreaded environment.
This is confusing. Why would you want to do this, meaning what do you want to achieve ultimately ? It seems like you have a problem, thought of a solution which brought you to this question. Forget the solution you have in mind, and post your problem, maybe we can solve your problem with a different approach ...
~RaGE();
|
|
|
|
|
Actually, it's almost a purely theoretical point. I'm studing pthreads synchronization objects and I realized that using posix threads you can initialize a critical section statically assigning a value to a variable (the critical section is initialized in the data segment, by compiler generated code). In posix you also have a dynamic method to initialize a critical section, just like the win32 initializeCriticalSection. So, my question is: is there a way to initizalize a critical section statically in win32? And if it's not, what are the consecuences?: do I always need a procedure/function/method/piece of code in my process that it's executed by only one thread (for example, DllMain) to initialize a critical section by a call to InitializeCriticalSection? or there's another API function that initializes the critical section the first time a thread executes it and that in the subsequent executions for the same critical section doesn't do anything?
I know that it's hard to read my english because I'm not a native speaker. I really appreciate your effort and I would be really pleased of getting anwers, suggestions, comments...
Thanks,
Federico
|
|
|
|
|
No, the only way to initialize is with the function call.
There are only two instances where the critical section needs to be iniialized, and it would be safe anyways:
1. In your main application's startup code before any other threads are started.
2. In the DLL_PROCESS_ATTACH of a DLL, in which case no other threads are executing code in the DLL anyway, so it is safe to initialize the critical sections there.
So, in essence, it is NOT ever a problem that you can't 'statically initialize' a critical section in Windows applications, because there are two safe well-known locations to do the initialization.
|
|
|
|
|
Thanks Blake!
I'm programming a library and I need to link it statically to other applications. So I don't have a DllMain with DLL_PROCESS_ATTACH, and I don't have a method that I know it will be called by just one thread, at least I require the library's user to call an initialization method only once and before any other call to the library. Is this the only way it would work for statically linked libraries?, because I would like to avoid that burden for my library's users.
Thanks,
Federico
|
|
|
|
|
If your library is written in C++, you could declare a global instance of a singleton class. The constructor of that class could initialize the critical section and the destructor would delete it. I am pretty sure the constructor of this class would be called before your progrma is 'running' or at least before most of your other code had a chane to get into trouble.
|
|
|
|
|
Hello all,
I am a C++ newbie, and have what I feel is a fairly simple question....
Basically I have a string of code that when executed in the console gives a list of user id numbers. What I want to do is make a an executable file that will give me a list of the actual user names (found in a lookup table) instead of the user id numbers.
If anyone can give me some advice or point me in the right direction, I would appreciate it. I have tried looking at some articles on this site (Execute a Console Application From VC++) but don't really understand it. Thanks in advance!
Shaun
|
|
|
|
|
What exactly is it that you are wanting to do: 1) execute a console application from VC++ and capture its output, or 2) create an application that will return a name given an id? These are two different things.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Okay, basically I'm sharing a floating license for matlab, and want to get a readout of the current user names.
Currently if I open the command prompt and type in a string 'lmutil ... blah blah', it returns a list of user id numbers that are currently using matlab....
What I want to do, is change it to return user names instead of the id numbers. So I thought I could just capture the information from the matlab license checking program (which runs at the command prompt) to retrieve the id number, and then output the cooresponding user names instead.
I wanted to just click on an executable (or batch) file and have it spit out the desired output.
I hope this cleared any confusion, thanks again!
|
|
|
|
|
Two ways to do that:
1.Launch a process that calls your "lmutil ... blah blah" command and that saves the output to a text (Check ShellExecute or CreateProcess in the MSDN or here on CodeProject).
Read the text, and do the substitution.
OR
2.Launch a process that calls your "lmutil ... blah blah" command and that captures the output into a String. [This part is not easy].
Do the substitution in the String.
Have a look at this article[^] to get a start with capturing the output of a process.
Hope this helps
~RaGE();
|
|
|
|
|
|
Dear all,
I'm writing a C++ (.NET 2003 with MFC) application that needs to query several data through WMI. I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class.
It is stored as a string array, the first Get returns me this information, but I did not found any issue on how to get the array.
bool CMyDoc::GetWMIItemValue( IWbemClassObject *pInstance,
LPCWSTR pItemName,
CStringArray& strArray)
{
VARIANT val;
LONG lFlavour;
HRESULT hGet;
CIMTYPE cimType;
VariantInit(&val);
strArray.RemoveAll();
hGet = pInstance->Get( pItemName,
0,
&val, // val cannot hold the result
&cimType, // returns 2008 = string array
&lFlavour); // returns 0
if (hGet == WBEM_S_NO_ERROR)
{
if (cimType == (CIM_STRING | CIM_FLAG_ARRAY))
{
// val holds 0x2008 too, unusable
// how can I access the array?
}
}
Thank you for you help...
PS: Using C# is a piece of cake, but my application has been developed in C++ and I cannot convert it.
Daniele
|
|
|
|
|
qrverona wrote:
I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class.
I would employ something like:
HRESULT hr;
_variant_t v;
ULONG ulReturned;
DWORD dwAuthLevel;
IWbemLocator *pLocator;
IWbemServices *pService = NULL;
IEnumWbemClassObject *pEnum = NULL;
IWbemClassObject *pClass;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
if (S_OK == hr)
{
hr = pLocator->ConnectServer(_bstr_t(L"root\\cimv2"), NULL, NULL, NULL, NULL, 0, NULL, &pService);
if (WBEM_S_NO_ERROR == hr)
{
hr = CoQueryProxyBlanket(pService, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL);
hr = CoSetProxyBlanket(pService,
RPC_C_AUTHN_DEFAULT,
RPC_C_AUTHZ_NONE,
NULL,
dwAuthLevel,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
hr = pService->CreateInstanceEnum(_bstr_t("Win32_NetworkAdapterConfiguration"),
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
NULL,
&pEnum);
if (WBEM_S_NO_ERROR == hr)
{
do
{
hr = pEnum->Next(WBEM_INFINITE, 1, &pClass, &ulReturned);
if (WBEM_S_NO_ERROR == hr)
{
hr = pClass->Get(L"IPAddress", 0, &v, NULL, NULL);
if (v.vt != VT_NULL)
...
pClass->Release();
}
} while (WBEM_S_NO_ERROR == hr);
}
}
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi
I have a simple dialog based MFC application which I have developed using CBannerStatic project available here at "http://www.codeproject.com/staticctrl/bannerstatic2.asp#xxxx"
Here when I make my font size very big, the banner gets very slow and stucks sometime when I have more load on my CPU by some other application running
Is there a way to give some amount of CPU to only my Banner application or is there a way to assign some value through which Banner doesn't gets affected because other running application ?
Thanking you.
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Please quit posting the same question in the wrong forum multiple times.
John
|
|
|
|
|