|
Trollslayer wrote:
No, callbacks cannot be in classes
Callbacks can be in classes as long as the function is static . By making the function static you are effectivly making the function global.
As for member functions check out:
http://www.codeproject.com/cpp/FastDelegate.asp
This will give you a good idea of how member function pointers (which are my determination callbacks anyway) work.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Uff, a lot to read in the article about the member function pointers...
But I think this is exactly what I was searching for! Thanks a lot.
Kind regards,
Roland
|
|
|
|
|
|
Hi,
I used property sheets to display some texts. When I click the OK button then the function is normal - i.e. the dialog box closes normally. However if I press 'Enter' key to close the dialog box, I notice that the dialog box closes, but also sends a WM_KEYUP message. Is there any way I can avoid this?
I want even the 'Enter key' to function like clicking the 'OK' button.
Also I would like to know if there is any method to trace the messages? Everytime I try to it goes to the MFC source program which i dont desire.. I want to trace in my program itself.. is it possible?
Thanks.
ani
|
|
|
|
|
How would a WM_KEYUP message affect the scheme of things? Also note that when you click the OK button you do get the WM_LBUTTONDOWN and WM_LBUTTONUP messages.
|
|
|
|
|
Hi,
then what is the difference between clicking OK button and pressing the ENTER key? In the sense, I call this property sheet from a parent window. So after clicking OK or CANCEL in the property sheet, it closes and returns back to the parent window. Does it still carry the WM_LBUTTONDOWN OR WM_LBUTTONUP to the parent window? Also, what message is sent when pressing the ENTER key instead of clicking OK button directly? bcos these two seem to call different procedures in my case..
Thanks
ani
|
|
|
|
|
By default, pressing the enter key has the effect of clicking the OK button. You needn't worry about the mouse/keyboard messages that are sent. Similarly, clicking the ESC key has the effect of clicking the Cancel button.
|
|
|
|
|
Add OnOK and OnCancel Handlers in the dialogs (propertypages) to call the OnOK and OnCancel of their parent ( i.e. the PropertySheet ).
Rahim Rattani
|
|
|
|
|
In my property page, I call PropertyPage::OnOK() in its OnOk() function. I guess this will take care of the Property sheet onok?
Is there any method where I can prevent VK_RETURN to be passed on to the active window after the dialog box closes? This happens when i press Enter key to activate the OnOK() of the property sheet/page.
Since this VK_RETURN message is also passed on to the active window after destroying the property sheet, the data in the active window gets disrupted as though someone had pressed an enter key there- though they havent actually....
Any solution?
ani
|
|
|
|
|
does anybody know how to convert from "CString" to "LPCWSTR" ?
i am using BITS in my program and the "IBackgroundCopyJob::AddFile" function takes input only as
HRESULT AddFile(LPCWSTR pRemoteName,LPCWSTR pLocalName);
i wish to pass CString taken from the user interface to the BITS function. didn't get much help from MSDN
|
|
|
|
|
I found MSDN to be quite informative.[^] Don't forget to call ReleaseBuffer when you finish with it.
I take it back, you're trying to create a wide string. Try this[^] instead.
A _bstr_t will convert between narrow and wide strings for you ( by using these macros ), but is not of much use otherwise.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
The easiest way would be to compile you program to use UNICODE strings.
In Project - Settings - C/C++ : Preprocessor definitions
make sure _UNICODE is defined and not _ANSI or _MBCS.
This will make CString use wide chars and allow an auto cast down to LPCWSTR.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I tried to install opengl and glut on Visual C++ on dotnrt 7.1. I searched the net and did exact;y what they said, but seems like it is not working . It is really frustrating, anyone has any idea what is going on and how I should install it?
|
|
|
|
|
Hi everybody. Here's an easy question for anybody that started learning Visual C++ correctly, from bottom to top (not like I did). I want to use GetSystemTime to create a string nicely formatted with the current hour. Unfortunately, I'm totally wasted with Visual C++ string manipulation routines. Maybe you can give me a hand. I want to use chars. Here's what I got so far.
SYSTEMTIME cmTime;<br />
char *a = (char *) malloc(256);<br />
char *b = (char *) malloc(256);<br />
char *c = (char *) malloc(256);<br />
GetSystemTime(&cmTime);
I presume I could use strcat or some function to concatenate the members of the cmTime SYSTEMTIME structure in a nice string. But so far my attempts resulted only in critical errors and program crashes : D. I suppose this could be done easier using the CString class, but I want to try with this because I could learn more. Also, I think one or two char variables are enough. If you can do this with only 2 of the variables declared, it would be even better.
I would want to do something like this: "HH:MM:SS DD MM". That kind of time format. Anyway, even HH:MM is good, I'll figure the rest out. I just need to know how to work with these strings. Pf. Hard for me, I don't know where to start!
|
|
|
|
|
Axonn Echysttas wrote:
char *a = (char *) malloc(256);
char *b = (char *) malloc(256);
char *c = (char *) malloc(256);
I thought you said you were using C++ ? This is C.
In any case, the right place to start is sprintf, if you are using C. If you're using C++, I'd use a strstream, or CString.Format.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christian. Well, I presume it might be C. But I don't even know that well the difference between C and C++.... I would like to know how to use strcat and then a messagebox to display the string. I wrote that in Visual C++. But it crashes when I try to display the result.
For example, this crashes.
a = (LPSTR)cmTime.wHour;<br />
MessageBox(0, a, "Test", 0);
And this too.
a = (LPSTR)cmTime.wHour;<br />
b = strcat(a, (LPSTR)cmTime.wMinute);
I'm really a beginner in working with strings but I would really appreciate some help. And even if this is C, I want to know how it's done in C. This is probably the hardest. If I get it like this, I'll understand more later.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote:
But I don't even know that well the difference between C and C++....
Well, suffice it to say that it looks like you're reading a book on C, which means you're learning a lot of bad habits, if you intend to program C++. malloc and free are C, new and delete are C++. You should never mix them, so the easiest thing is to always use new and delete.
Axonn Echysttas wrote:
a = (LPSTR)cmTime.wHour;
You can't just cast a number to a string. If you must use C functions/want to do things the hard way, then sprintf is what you want, as I said.
Axonn Echysttas wrote:
I'm really a beginner in working with strings but I would really appreciate some help.
The core issues regarding strings:
A string is a pointer, not a single intrinsic type. As such, you need to write memory management code to create and dispose of strings.
You cannot turn something into a string by casting it.
My main beef with the way C++ is taught is that people are taught to do exactly what you're doing, hack around with functions you'll never use again, because you will use CString or ( even better most of the time ) std::string.
Oh, one more - strings are null terminated, so you need a string length of 10 to store a nine character string ( you need room for the null at the end ).
This doesn't even begin to address Unicode strings, etc. I'm just talking about a basic char * here.
Axonn Echysttas wrote:
And even if this is C, I want to know how it's done in C.
Yes, unless what you've written is in a class, everything you're doing is C, as well as being valid C++.
The core answer was in my first post - you need sprintf. I think it's a good thing for you to do it the hard way at some point, just like I think you should write your own list class before using std::list. But it's a tool for learning how stuff works, you won't write production code this way. If I had to do this in the real world, I'd write a SYSTEMTIME inserter for iostreams. But that doesn't mean you're doing anything wrong, you need to walk before you crawl. It's just that I recommend learning C++ first, with the string class, then going back later when you understand the rest to understand what the string class does for you ( because string handling is the major hump in early C++ understanding IMO )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Axonn Echysttas wrote:
But I don't even know that well the difference between C and C++....
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
First of all, the members of the SYSTEMTIME structure are the actual values, not strings. The following will construct a string according to the format you requested ("HH:MM:SS DD MM"):
char string[32];
SYSTEMTIME cmTime;
GetSystemTime(&cmTime);
sprintf(string,"%02hu:%02hu:%02hu %02hu %02hu",
cmTime.wHour,
cmTime.wMinute,
cmTime.wSecond,
cmTime.wDay,
cmTime.wMonth); You can do the same thing with CString :
CString string;
SYSTEMTIME cmTime;
GetSystemTime(&cmTime);
string.Format("%02hu:%02hu:%02hu %02hu %02hu",
cmTime.wHour,
cmTime.wMinute,
cmTime.wSecond,
cmTime.wDay,
cmTime.wMonth); Note the format: %02hu produces a 2 digit value from a WORD argument (which is unsigned, hence the 'u').
Software Zen: delete this;
|
|
|
|
|
|
Thank you Christian, Gary and Alok. Your advices are exactly what I needed to understand the issue. Gary's code is a perfect example and Alok's links will undoubtely shed light in these matters.
Christian, I knew that strings are pointers. I'm not *THAT* much of a beginner : ). There is a reason why I was doing this the C hard way. I would like to keep my Application as portable as possible. As far as I know CString is a class related to MFC right? Or do Linux versions of C++ also have this class implemented?
Nevertheless, I did do some mistakes and confusions for sure. Thank you for showing me the way.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I am a relatively competent, mildly skilled programmer, but I have always programmed things in the UNIX/Linux environment, so needless to say I've never used visual C++ or Visual Studio before, and trying to learn it is almost like starting to learn everything all over again. Anyway, I'm writing a program which has to interface with several different devices in order to control them. It just so happens that one of the devices is an intelligent power controller which connects to the computer's COM port and is controlled by simple ASCII commands which are transmitted to the device using the VT100 protocol. The program I'm writing has certain modes which would need different devices to be turned on or off and I would like to be able to send commands to the IPC when needed based upon the status of the program. I have been able to successfully open and close and diagnose the status of all of the COM ports on the computer, I'm just having trouble trying to figure out how to send commands to the IPC and recieve the output using the VT100 protocol. I have some basic communication functions already, but they do not encode the transmission using VT100 or depend on the input/output status of the port. Is there some library in Windows I can use which contains conversion functions or are the only options to either write those myself or buy a software package containing them? If there's anyone out there who has any ideas which could point me in the right direction, I would be very appreciative. Also, if anyone needs more specific information or code, just ask and I'll be happy to post it. Thanks in advance for your help guys!
|
|
|
|
|
As far as I know, there isn't a 'VT100 protocol', per se. The VT100 was a serial computer terminal sold by the late lamented Digital Equipment Corporation many years ago. It was used to communicate with minicomputers over an RS-232 line at a whopping 9600 or 19,200 baud.
That said, you need to find documentation that describes the command set for your IPC. This will tell you what you'll be sending and receiving over the serial port.
As to how, try looking here[^] in the MSDN. While the topic is 'Communication Resources', it includes serial communications.
BTW, since you're coming from the dark side (e.g. *nix), you'll really want to become acquainted with the Microsoft Developer Network[^], or MSDN. It's the second-best resource on the web for Windows programming (first-best, of course, is Code Project[^]!).
Software Zen: delete this;
|
|
|
|
|
I have a service that runs under the system account, not interacting with the desktop. I want it to be able to do something (use the Service Manager to stop a service on another computer) that apparently requires me to be Administrator. I could run my service as Administrator, but I'd rather not do that since it prevents me from changing my mind and making it interact with the desktop, at least for debugging.
Where can I go to learn how my service can impersonate Administrator (the service has access to the login information) while interacting with the Service Manager? I'd appreciate any information. This service is implemented in MFC. Using C# is not an option, nor is learning a lot of COM.
Thanks
|
|
|
|
|