re: Diversion: Generating a random color from JavaScript
@The MAZZTer has it right, don't bother with trying to make a hex number and just write out an rgb()-style color triplet. They're supported by every browser (even IE6!) to there's no real drawback to...
View Articlere: Diversion: Generating a random color from JavaScript
@AndyCadley. Yup. And that's probably the shortest and most time efficient way of generating a random number on the client computer. The only problem is that it fails to perform very well for more than...
View Articlere: Diversion: Generating a random color from JavaScript
function randomColor() { return "#" + Math.random().toString(16).substr(-6); } Note: negative start numbers in substr() requires IE9 or later.
View Articlere: How do you come up with new shortcut keys?
There are system-wide shortcuts for which there must be a more formalized process for choosing them, as it is very easy to come up with shortcuts that would conflict with existing application...
View Articlere: Diversion: Generating a random color from JavaScript
Tod, you're on The Old New Thing, not The Daily Worse Than Failure.
View Articlere: Diversion: Generating a random color from JavaScript
and while the original version was easily understandable ven for the layman the final version needs an added comment so you know why it works. As if JS wasn't easily enough obfuscated without even...
View Articlere: Diversion: Generating a random color from JavaScript
I agree, simplicity is the key to success. ;-)
View Articlere: How do you come up with new shortcut keys?
["Alt+R" was shorthand for "invoking the keyboard accelerator in the appropriate manner to execute the item where the R is underlined, either pressing a plain R if invoked directly as a pop-up context...
View Articlere: Diversion: Generating a random color from JavaScript
You could replace(!) "#" + str.substr(1) with str.replace(/./, "#").
View Articlere: Diversion: Generating a random color from JavaScript
@Henry That won't work. The random number could be "0.1"
View Articlere: Using WM_COPYDATA to marshal message parameters since the window manager...
OK... now I just learned about some re-entrancy implications that I hadn't really thought about before! Ouch.
View Articlere: You can't use the WM_USER message in a dialog box
Or just use RegisterWindowMessage and never worry about a conflict... [That's using a global solution to a local problem. There is a limited number of registered messages (and they can never be freed...
View Articlere: Diversion: Generating a random color from JavaScript
Just for fun I looked up the ECMAScript specification for Math.random(): -- begin quote -- 15.8.2.14 random ( ) Returns a Number value with positive sign, greater than or equal to 0 but less than 1,...
View Articlere: You can't use the WM_USER message in a dialog box
Wow, dialog boxes really shouldn't hog the whole WM_USER range. There should be some constant (say around 0x4000) where the rest of the WM_USER range can be used by the specific dialog box.
View Articlere: You can't use the WM_USER message in a dialog box
@Joshua: The range you seek does exist! It's just at 0x8000 instead of 0x4000. As Raymond would say, I can't believe I had to write that.
View Articlere: You can't use the WM_USER message in a dialog box
@Raymond: RegisterWindowMessage "return value is a message identifier in the range 0xC000 through 0xFFFF". That's 16384 possibilities. The applications I've done this with register a maximum of...
View Articlere: You can't use the WM_USER message in a dialog box
Oh - it seems the developers of .NET Framework use a similar technique for marshaling from a background thread to the user interface thread (which is one of the things I was needing a special message...
View Articlere: You can't use the WM_USER message in a dialog box
Interesting comment, James. I suspect that Winforms is using the RegisterWindowMessage technique because it's a library. It can't possibly know what hard-coded window message numbers the host app...
View Articlere: Diversion: Generating a random color from JavaScript
@sugendran: Dang you, I followed the link you gave to the Wikipedia article, then followed its footnotes to some fascinating documents that I skimmed and downloaded to read later. More stuff to do....
View Articlere: You can't use the WM_USER message in a dialog box
@ChrisR: See Dialog Box in DLL. Forum keeps losing my post. [It's not losing the post. It's blocking it because it looks like spam (too short). -Raymond]
View Article