|
I have stumbled up against a wall with this one and am hoping that someone else has already handled this. I am qualifying code that presently works on WinNT to ensure that it works the same on Win2K. For an owner draw combo box, the following code in the DrawItem method fails on Win2K, but only when the display option for 'transition effects in menus and tooltips' is turned on.
CDC* DeviceContextPointer = CDC::FromHandle(lpDrawItemStruct->hDC);
CWnd* DropDownWindowPointer = DeviceContextPointer->GetWindow();
When the option is turned off, the CWnd pointer has a non null value and points to a real honest to goodness window. When the option is turned on however, the CWnd pointer is NULL and rightly so because with the option turned on, the DrawItem method is invoked without a real honest to goodness window available to draw in. I think that part of the trouble is that the 'architecture' for owner draw stuff has changed and I need to jack around the code to reflect that. Any ideas or comments are appreciated. Thanks.
Chris Meech
|
|
|
|
|
I'm having problems with an array tacking a bunch of sludge on to the end of a array of random characters. It needs to generate an array of 64 random bytes for use inan encryption routine. I'm getting the 64 bytes of information that I want at the front end of the array, BUT..it's also tacking on the contents of the original array that I filled with a sequence from ASCII 32 to ASCII 127 character values. My question is how to get the sludge off the end of the array so it consists of just teh 64 random byte values. Source Code Follows:
srand(GetTickCount());
int nElementCount = 0;
int nElementValue = 32;
char szStringArray[95] = "";
char szRandomBytes[64] = "";
while ( nElementCount <= 94 )
{
szStringArray[nElementCount] = nElementValue;
nElementCount++;
nElementValue++;
}
nElementCount = 0;
while (nElementCount <=63)
{
int nRandomNumber = rand();
while (nRandomNumber >= 95)
{
nRandomNumber = nRandomNumber / 2;
}
szRandomBytes[nElementCount] = szStringArray[nRandomNumber];
nElementCount++;
}
MessageBox(NULL, szRandomBytes, "Random String From Array", MB_OK);
It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now...
[Shog9 on Kid Programmers]
|
|
|
|
|
Put a terminating character at teh end of your string. The last character in your array should be '\0'. You are trying to display a string in your MessageBox by putting the array of char but are not giving your array of char a termination indicating this is where the string ends.
|
|
|
|
|
char szStringArray[95] = "";
char szRandomBytes[64] = "";
memset(szStringArray,0,95);
memset(szRandomBytes,0,64);
And off u go
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
i'm converting some of my console apps to Unicode (long story). but, i've noticed that i can't write a Unicode string using cout, i just get a memory address out ("0x00faade2" or whatever).
my question is: is this true on non-US versions of Windows, too? do i have to output only ANSI to the console?
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
In my experiences, it seems that - with the exception of DBCS languages - if something fails like that on English, it'll fail in other languages, too.
Have you tried using wcout instead of cout ?
Even if you win the rat race, you're still a rat.
|
|
|
|
|
wcout... yeah. there's an idea.
thanks.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
You have to use the wide character version (wcout) to print unicode strings. However, I have noticed that internally everything is just converted to ANSI before the buffer is put out (via WriteFile() ) to the console. So if you are using "fancy" charsets this may fail
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
Does anyone know how to get the title bar font for a CFrameWindow?
Thanks,
David.
|
|
|
|
|
|
|
Look into the SystemParametersInfo() API with uiAction set to SPI_GETNONCLIENTMETRICS .
Jeremy Falcon
Imputek
<nobr>"..." - Paul Watson 07-17
|
|
|
|
|
I saw some of the trayclock utility can fix the appearance of systemclock. I suppose they got the HWND and did some thing under it.
I tried and successful added my text in the TrayClock. but the problem is how can I fix the width of trayclock? its width is related with left side iconbar. I want the changing of trayclock can automatically affect on iconbar even TrayNotify(the parent form of trayclock). how to get it?
|
|
|
|
|
I want my app to show up blank if there is no database name in the registry, but popup a CFileDialog OPen. I query the registry in oninitialupdate of the view, and at the very last statement, if there was no dbname in the regsitry I sendmessage to trigger the "Open Database" menu item. When the app runs, (no dbname in regsitry), the first thing that pops up is the OPen dlg, not my blank view!!!! I tried sending the msg in a function calledin oninitial update - same result. How can I get my blank view to show up first, with the CFileDialog Open dlg over it? If I dont send the msg, and exit the oninitial update I get the UI as expected. But then where would I send the message?
I am quite puzzled. Any suggestions?
|
|
|
|
|
ns wrote:
I sendmessage to trigger the "Open Database" menu item
Use PostMessage() instead. This will allow your (empty) view to open properly, after which the "Open Database" command will be executed.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
That was so cool! SOmeone had told me I needed to go the route of timers and killtimer etc so I was starting to look into that. PostMessage is perfect!
Many many thanks,
ns
|
|
|
|
|
Yooooou're welcome!
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
hi,
Here is my code:
char buffer[10];
strcpy(buffer, "ABCDEFGHIJ");
cout << buffer << endl;
strcpy(buffer, "");
buffer[0] = 'X';
cout << buffer << endl;
And the output would be:
ABCDEFGHIJ
XBCDEFGHIJ <======= should be "X" only...right?
I think I've initialized the buffer, but why i can have this strange result after i put 'X' in the first character of buffer.
Thank you!!!!!
|
|
|
|
|
buffer[0] = 'X'; This sentence owerwrites the previous value of buffer[0] , which was the terminating null character from strcpy(buffer, ""); As you haven't added any additional terminating character, the remains of the first string appears, hence the output. To get the result you're after, write:
buffer[0] = 'X';
buffer[1]=0; Unless you're doing this for fun or learning purposes, it is strongly advisable that you leave this char manipulation stuff in favor of more robust alternatives like std::string .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
ChiYung wrote:
strcpy(buffer, "");
buffer[0] = 'X';
cout << buffer << endl;
strcpy does not delete or null any of the characters inside of the buffer. Therefore passing in an empty string copies zero (0) characters and leaves the string untouched. If you want the string to be only 'X' you need to do something like:
buffer[0] = 'X';
buffer[1] = '\0';
The second character is the null character (the slash means it is an escape character); which in C means the end of the string. Character strings in C are always string length + 1. Example:
The string literal, "Hello World!", is actually 13 characters long, the 12 visible characters plus 1 for the null.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I have a quite enerving way to initialize a strin array, i always do:
char buffer[10];
memset(buffer , 0 , 10 );
PS: u can use : sizeof(buffer)
each time i want to initialize
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
ChiYung wrote:
char buffer[10];
strcpy(buffer, "ABCDEFGHIJ");
You have a more serious problem in that this code overruns the array. "ABCDEFGHIJ" is an 11 character string, 10 letters and the terminating 0 character.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
One other point - your char array is 10 elements - you need an extra element to hold the terminating null.
So far when you've run there has been a null anyway but at some point you could end up with a string several MB long !
We've all done it when starting out.
Elaine (Trollslayer)
|
|
|
|
|
I'm beginning work on an NT service (only in the early design phase right now) that will need to respond to network requests. I've done work with networking before, but this will be my first service. What I'm finding already is that there doesn't seem to be an easy way to handle networking. At least not as intuitive as through CSocket with MFC. What type of system does everyone else use for a service? I know I can setup a thread that continually tries to receive, and that might work. I've also looked into using the MFC service classes out there (PJ Naughter's in particular) so that I can use CSocket again. Both seem to have there up's and down's. Is there an easy way that I'm not seeing?
Also, as a second question. How do you control a service? I understand how to start, stop, and pause them. But how do I grab it and call a function? Or can I? Basically, if I write a control panel applet for example, how do I adjust the service in realtime? I could always write adjustments to the registry, but then I would also have to have a thread watching for changes and that doesn't seem very logical either. Again, is there an easy way that I'm just not seeing?
"Go Confidently in the direction of your dreams. Live the life you've imagined." - Thoreau
|
|
|
|
|
To write your very first service is always a bit of hard work. However, it is not that difficult as it looks like:
1) To really work with a service you need some kind of inter-process-communication (IPC). IPC is the way to communicate with your service. Sockets are one example for IPC, I usually prefer NamedPipes or RPC (because they integrate well into the NT security modell), but one may also use shared memory, sockets, NetBIOS and so on.
2) Even if possible I recommend not using MFC in a service. For things like CString or CArray it is you can use the ATL/WTL classes that provide a compatible interface. Or use STL. Especially CSocket is a no-no. It is integreated to much into "windowing applications".
3) To control a service a CPL or MMC snap-in is a really good solution. You can monitor the registry as you suggested, but you could also inform the service about changes via a Win32 event object, IPC or a user defined service control code. The last one is elegant because you don't need an own watcher thread.
4) Debugging a service is a bit hard, because it is not possible to run it directly under the debugger. However, you could connect your debugger later on to the service (via task manager). To debug service startup code a hardcoded breakpoint works best.
// some code
_asm int 3 // Program will break here
// some more code
If the code reaches the hardcoded breakpoint, the usual "unhandled exception" dialog box will appear and give you the chance to attach the debugger.
Hope that helps for the moment
--
Daniel Lohmann
http://www.losoft.de/
|
|
|
|