|
Post the function you are most proud of.
Last post 06-01-2007 4:23 PM by kupior. 116 replies.
-
05-14-2007 10:11 PM
|
|
-
Dark Shikari


- Joined on 04-25-2007
- Posts 95
|
Post the function you are most proud of.
Its not long until the deadline, so I figure we might as well start the inevitable.
Post the function or code snippet you are most proud of: the one that more than any other truly demonstrates your program's WTFery. Mine is the division function:
float DoDiv(float op1, float op2, int *isErr) { unsigned int result[FLOAT_ARRAY_SIZE]; if(*isErr == INIT_ZERO & mantissa2 == INIT_ZERO & exponent2 == INIT_ZERO) { *isErr = CONST_ONE; return op1;} result[SIGN_INDEX] = INIT_ZERO; result[MANTISSA_INDEX] = div(bitshift(add(mantissa1, MANT_CUTOFF), DIV_SCALING_FACTOR), add(mantissa2, MANT_CUTOFF), CONST_ONE); result[EXP_INDEX] = add(sub(exponent1, sub(exponent2, EXP_OFFSET)), sub(MANTISSA_SIZE, DIV_SCALING_FACTOR)); while(greaterThan(result[MANTISSA_INDEX], bitshift(MANT_CUTOFF, CONST_ONE))){ result[EXP_INDEX] = add(result[EXP_INDEX], CONST_ONE); result[MANTISSA_INDEX] = bitshift(result[MANTISSA_INDEX], sub(INIT_ZERO, CONST_ONE));} while(lessThan(result[MANTISSA_INDEX],MANT_CUTOFF) & (result[MANTISSA_INDEX] != INIT_ZERO) & ((result[MANTISSA_INDEX] & MANT_CUTOFF) == INIT_ZERO)){ result[MANTISSA_INDEX] = bitshift(result[MANTISSA_INDEX], CONST_ONE); result[EXP_INDEX] = sub(result[EXP_INDEX], CONST_ONE);} if(logicalNot(exponent1) == INIT_ZERO & logicalNot(exponent2) == INIT_ZERO) result[MANTISSA_INDEX] = sub(result[MANTISSA_INDEX], MANT_CUTOFF); int resultvar = add(add(bitshift(result[EXP_INDEX], MANTISSA_SIZE), result[MANTISSA_INDEX]), bitshift(result[SIGN_INDEX], add(MANTISSA_SIZE, EXP_SIZE))); if(lessThan(*isErr, NUM_ITERATIONS)){ result[MANTISSA_INDEX] = div(bitshift(add(mantissa1, MANT_CUTOFF), DIV_SCALING_FACTOR), add(mantissa2, MANT_CUTOFF), INIT_ZERO); if(result[MANTISSA_INDEX] != INIT_ZERO){ result[EXP_INDEX] = add(sub(exponent1, sub(exponent2, EXP_OFFSET)), sub(MANTISSA_SIZE, DIV_SCALING_FACTOR)); while(greaterThan(result[MANTISSA_INDEX], bitshift(MANT_CUTOFF, CONST_ONE))){ result[EXP_INDEX] = add(result[EXP_INDEX], CONST_ONE); result[MANTISSA_INDEX] = bitshift(result[MANTISSA_INDEX], sub(INIT_ZERO, CONST_ONE));} while(lessThan(result[MANTISSA_INDEX], MANT_CUTOFF) & (result[MANTISSA_INDEX] != INIT_ZERO) & ((result[MANTISSA_INDEX] & MANT_CUTOFF) == INIT_ZERO)){ result[MANTISSA_INDEX] = bitshift(result[MANTISSA_INDEX], CONST_ONE); result[EXP_INDEX] = sub(result[EXP_INDEX], CONST_ONE);} if(logicalNot(exponent1) == INIT_ZERO & logicalNot(exponent2) == INIT_ZERO) result[MANTISSA_INDEX] = sub(result[MANTISSA_INDEX], MANT_CUTOFF); int resultvar2 = add(add(bitshift(result[EXP_INDEX], MANTISSA_SIZE), result[MANTISSA_INDEX]), bitshift(result[SIGN_INDEX], add(MANTISSA_SIZE, EXP_SIZE))); *isErr = add(*isErr, CONST_ONE); float remainderDiv = convertTofloat(add(MANT_CUTOFF, mantissa2)); return DoAdd(DoDiv((*(float *) &resultvar2), remainderDiv, isErr), (*(float *) &resultvar));} else{ *isErr = INIT_ZERO; return (*(float *) &resultvar);}} else{ *isErr = INIT_ZERO; return (*(float *) &resultvar);} } It has a few interesting properties. 1. It works by splitting up a floating point number and doing integer operations on it. Yes, and it can return a fractional answer. 2. Each division uses 32 bits of precision, but the numbers are 24 bits, giving only 8 bits of precision for the actual result. How do I get more bits? Recursion. AGHHHHHHHHHHH 3. The "mantissa1", "exponent2", and so on are NOT global variables. They are #defines, like #define mantissa1 splitfloat(op1, MANTISSA_INDEX). 4. It uses no operations other than bitwise and, bitwise not, ==, !=, and = (assignment). The details to this mostly lie in the functions it calls, not the original function, however. 5. It takes 5 seconds to run, fully optimized, on a Core 2 Duo 2Ghz. It contains no intentional delay loops. 6. As far as I know, it works for all positive floating point numbers, even those beyond 2^32.
|
|
-
-
JCM


- Joined on 03-16-2006
- Posts 23
|
Re: Post the function you are most proud of.
Well, crap. If that's what the judges are looking for, I guess I'm just SOL. :) My entry was *much* easier to read and understand. It had comments and everything. I didn't think that the goal was obfusticated code nearly as much as just something that made the judges shake their heads.
|
|
-
-
dsharp


- Joined on 05-10-2007
- Posts 9
|
Re: Post the function you are most proud of.
Since we're not really aiming for obfuscation here, I chose to go down the "... well you *could* do that, but it's not a good idea." route.
Storeable* ServiceManager::getService(const std::string &serviceName) { Storeable* rc = NULL; map<string,Storeable*>::iterator i = services.find(serviceName); if (i != services.end()) { rc = i->second; } else { //oops! didn't find the service, calculate the soundex, //and see if the programmer has just misspelled it. string soundex = getSoundex(serviceName); map<string,string>::iterator j = soundices.find(soundex); if (j != soundices.end()) { i = services.find(j->second); rc = i->second; } } return rc; }
|
|
-
-
Dark Shikari


- Joined on 04-25-2007
- Posts 95
|
Re: Post the function you are most proud of.
JCM:Well, crap. If that's what the judges are looking for, I guess I'm just SOL. :) My entry was *much* easier to read and understand. It had comments and everything. I didn't think that the goal was obfusticated code nearly as much as just something that made the judges shake their heads.
I omitted the comments in the copy-paste of the code.
|
|
-
-
stolen_username


- Joined on 05-08-2007
- East Lansing, MI
- Posts 64
|
Re: Post the function you are most proud of.
Eh. From what I've seen here, most people were more creative than I was and actually managed to come up with solutions that function as calculators. I probably don't have too much to lose.
DWORD WINAPI Calculation_thread(LPVOID lpParam)
{
LARGE_INTEGER last_expr_file_time;
SYSTEMTIME system_time;
FILETIME converted_system_time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &converted_system_time);
last_expr_file_time.HighPart = converted_system_time.dwHighDateTime;
last_expr_file_time.LowPart = converted_system_time.dwLowDateTime;
while (IsWindow(calc_window))
{
WIN32_FIND_DATA find_data;
HANDLE find_handle = FindFirstFile("expr-*.xml", &find_data);
if (find_handle)
{
BOOL found_file = TRUE;
while (found_file)
{
LARGE_INTEGER test_time;
test_time.HighPart = find_data.ftCreationTime.dwHighDateTime;
test_time.LowPart = find_data.ftCreationTime.dwLowDateTime;
if (test_time.QuadPart > last_expr_file_time.QuadPart)
{
Do_calculation(find_data.cFileName);
last_expr_file_time = test_time;
break;
}
found_file = FindNextFile(find_handle, &find_data);
}
FindClose(find_handle);
}
}
return 0;
}
Comments removed because it's just more fun without them.
|
|
-
-
Whiskey Tango Foxtrot? Over.


- Joined on 03-10-2006
- I'm a Nashville carpetbagger.
- Posts 332
|
Re: Post the function you are most proud of.
Ok, all entered and confirmed! I can't really post a single function that I'm proud of, because they're all very basic, fairly short functions. Well, methods, really -- I took a very object-oriented approach. In fact, I built what I consider to be a very well thought out, very well designed, and ultimately very useless C++ class library. I call my submission the VICE: Virtual Integrated Circuit Engine. I'm rather proud of that backronym. ;) Basically, I took the concept of the Virtual Machine to its reductio ad absurdum: Virtual Transistors. Rather than compute values with the CPU, I built Virtual AND gates, Virtual OR gates, virtual flipflops, virtual registers, and virtual computation units, all composed (ultimately) of Virtual Transistors. Well, the VirtualFlipFlop wasn't -- flipflops are based on a feedback loop, and that would have caused infinite recursion, and I actually wanted to *pass* the tests. :) My goal was a Turing complete VirtualCPU, complete with 4 MB of VirtualRAM, a full set of registers, and a subset of the x86 instruction set, but I ran out of time. In fact, I never got to floating point computation, so Dark Shakiri has me beat in that department. I do, however, have flawless cross-platform 32-bit integer addition, subtraction, and multiplication. Despite being insanely complex, VICE is pretty performant. Wasteful, yes, but performant thanks to fast processors. Hmm... I wonder if it would be as fast as a JVM or .NET? Maybe I'll keep working on it...
Agile Team-Oriented Waterfall-Centric Cowboy Coder.
|
|
-
-
Einsidler


- Joined on 11-15-2006
- Posts 99
|
Re: Post the function you are most proud of.
Here's the code snippet for my bubble sort, completely necessary to my algorithm but doesn't actually do anything. By pure coincedence every test case can do without it, but some operations return strange results. int strlength = strlen(op1); bool move_made = true; char temp; for (int a = 0; a < strlength - 1 && move_made; a++) { move_made = false; for (int b = a + 1; b < strlength; b++) if (ToInt(&op1[a]) < ToInt(&op1[b])) { temp = op1[b]; op1[b] = op1[a]; op1[a] = temp; move_made = true; } } In this case all calls to ToInt return 0. oh, and the only comment in there explains that it is just a "standard bubble sort."
Download my OMGWTF entry, Romanorum Computus
|
|
-
-
Massimo


- Joined on 04-25-2007
- Posts 84
|
Re: Post the function you are most proud of.
Ok, you asked for it ;-)
First: // Magic method #1 // --------------- // This one makes possible to change on-the-fly the // actual class being pointed by a generic Operation* // pointer void* Operation::operator new(size_t,Operation* op) { return(op); }
Second: // Magic method #2 // --------------- // This one changes the actual class it belongs to, // destroying it and creating in place a new one of // the correct type void Operation::ChooseOperation(char op) { this->~Operation();
switch(op) { case '+': new(this) Sum(); break; case '-': new(this) Sub(); break; case '*': new(this) Mul(); break; case '/': new(this) Div(); break; default: new(this) Dummy(); }
return; }
What do they to?
Well, they're pare of a quite peculiar implementation of the "polymorphism" concept ;-)
|
|
-
-
Whiskey Tango Foxtrot? Over.


- Joined on 03-10-2006
- I'm a Nashville carpetbagger.
- Posts 332
|
Re: Post the function you are most proud of.
Massimo -- that is.... insane! WTF?
Agile Team-Oriented Waterfall-Centric Cowboy Coder.
|
|
-
-
ashelly


- Joined on 05-15-2007
- Posts 2
|
Re: Post the function you are most proud of.
I am _least_ proud of my hack to pass the test cases without implementing long division: Number* operator/(Number& other) { if (other.multidigit()) return new Six; return *(this) * *((new One) / other);
}
|
|
-
-
Einsidler


- Joined on 11-15-2006
- Posts 99
|
Re: Post the function you are most proud of.
ashelly:I am _least_ proud of my hack to pass the test cases without implementing long division: Number* operator/(Number& other) { if (other.multidigit()) return new Six; return *(this) * *((new One) / other);
}
Reminds me of my "if (op2 > 5) return 6; // bug fix " :( Funny thing is, I didn't need it in debugging, but it crashed spectacularly when run from a compiled copy.
Download my OMGWTF entry, Romanorum Computus
|
|
-
-
kvigor


- Joined on 05-11-2007
- Posts 6
|
Re: Post the function you are most proud of.
Placement new of this?! I bow to the master; that is sick, sick and disturbing. For myself, I'm kinda proud of this macro: #define IS(x,y,z,a) \ template <> \ const char *saymyname(const x, const y, const z) \ { \ static a _crap; \ return _crap.name(); \ };
yes, it's a macro that generates a specialization of a template function that ignores all its parameters, and yes, it's important. I banged the whole mess out in about an hour this morning (22 svn commits!) so I didn't get a chance to fully wtfify it, but on the other hand, it's perverse code I wrote in a hurry.
|
|
-
-
Whiskey Tango Foxtrot? Over.


- Joined on 03-10-2006
- I'm a Nashville carpetbagger.
- Posts 332
|
Re: Post the function you are most proud of.
Ok, I changed my mind. Here is the code for the VirtualTransistor:
VirtualTransistor.h
#pragma once #include "VirtualComponent.h" #include "VirtualConnection.h"
namespace VICE { namespace Component { // The VirtualTransistor is the heart of the VICE system. Although itself // a VirtualComponent, nearly all other VirtualComponents are built from a // VirtualTransistor or from other VirtualComponents that (at some point) // utilize a VirtualTransistor. // // A VirtualTransistor models an NPN transistor which is, essentially, a // switch. It sends current through its output (typically called // an "Emitter" on NPN transistors), only if it both receives current from // its input ("Collector") and receives a small amount of current from // its switch input ("Base"). // // Because both current and voltage have been abstracted away for Virtual // Integrated Circuits, the difference between NPN and PNP transistors // (essentially a matter of current direction and whether a connected base // adds to or subtracts from the current flowing through the transistor) // becomes moot. In a VirtualTransistor, "current" flows from the Collector // to the Emitter. class VirtualTransistor : public VirtualComponent { public: ///////////////// //// Methods //// /////////////////
// default constructor VirtualTransistor(); // Causes the VirtualTransistor to update its output based // on its inputs. void Update();
//////////////////////////// //// Inputs and Outputs //// ////////////////////////////
//*****************************************************// //** Collector -- simulates a transistor's collector **// //** or "power input" **// //** Defaults to VirtualConnection::AlwaysOff **// //*****************************************************// private: const VirtualConnection * Collector; public: const VirtualConnection * Get_Collector(); void Set_Collector(const VirtualConnection * collector);
//************************************************// //** Base -- Simulates a transistor's base **// //** or "switch input" **// //** Defaults to VirtualConnection::AlwaysOff **// //************************************************// private: const VirtualConnection * Base; public: const VirtualConnection * Get_Base(); void Set_Base(const VirtualConnection * base);
//*************************************************// //** Emitter -- Simulates a transistor's emitter **// //** or "result output" **// //** Defaults to VirtualConnection::AlwaysOff **// //*************************************************// private: VirtualConnection Emitter; public: const VirtualConnection * Get_Emitter(); }; } }
VirtualTransistor.cpp
#include "StdAfx.h" #include "VirtualTransistor.h" #include <stdexcept>
using namespace VICE::Component;
VirtualTransistor::VirtualTransistor() : Collector(&VirtualConnection::AlwaysOff), Base(&VirtualConnection::AlwaysOff)
{}
void VirtualTransistor::Update()
{
if(Collector->On && Base->On)
{
Emitter.On = true;
}
else
{
Emitter.On = false;
}
}
//*************//
//** Emitter **//
//*************//
const VirtualConnection * VirtualTransistor::Get_Emitter()
{
return &Emitter;
}
//***************//
//** Collector **//
//***************//
const VirtualConnection * VirtualTransistor::Get_Collector()
{
return Collector;
}
void VirtualTransistor::Set_Collector(const VirtualConnection * collector)
{
if(collector == NULL)
{
throw std::invalid_argument("collector cannot be null");
}
Collector = collector;
}
//**********//
//** Base **//
//**********//
const VirtualConnection * VirtualTransistor::Get_Base()
{
return Base;
}
void VirtualTransistor::Set_Base(const VirtualConnection * base)
{
if(base == NULL)
{
throw std::invalid_argument("base cannot be null");
}
Base = base;
}
Agile Team-Oriented Waterfall-Centric Cowboy Coder.
|
|
-
-
macavenger


- Joined on 05-15-2007
- Fairbanks, AK
- Posts 7
|
Re: Post the function you are most proud of.
Well proud definitely isn't the right word, but my subtraction function:
void SubtractChars (char* op1, char* op2, bool borrow, char pos) { char length= ( strlen(op1)>strlen(op2) ) ?strlen(op1)+'0' : strlen(op2)+'0'; bool newBorrow=FALSE; if(pos==length-'0') { if(borrow) { strcpy(result, ShiftRight(result, length+'\001')); result['\0']='-'; return; } else return; } pos=pos+'\001'; char num1=( (int)strlen(op1)-pos<'\0' ) ? '0' : op1[strlen(op1)-pos]; if(borrow) num1=num1-'\001'; char num2=( (int)strlen(op2)-pos<'\0' ) ? '0' : op2[strlen(op2)-pos]; if (num2>num1) if(length-pos>'0') { num1=num1+'\n'; newBorrow=TRUE; } char diff=(num1-num2)+'0'; if (diff<'0') { //This is a fun line :) Could this be simplified? perhaps. Dunno. Don't care. It works. diff=(':'-(diff+'\n'))+'0'; newBorrow=TRUE; } result[length-pos-'0']=diff; SubtractChars(op1,op2,newBorrow,pos); }
It's a little buggy, but it seems to work, at least for the test cases. My apologies to the testers for the UI- on the EXTREMELY slim chance that I win, I'll send you guys a very large bottle of aspirin :)
Aluminum iMac 20" C2D 2.4 GHz/300 GB/3 GB
|
|
-
-
phaedrus


- Joined on 03-19-2007
- Seattle Ex-Pat living in the Bay Area
- Posts 111
|
Re: Post the function you are most proud of.
This is one of my finer moments in my entry. It's actually two functions. Two sides of a coin, if you will. Ok, here it goes: First, a struct definition: struct do_next_stack_s { uint32_t lvl; // stack depth uint32_t r; // return point pointer struct do_next_stack_s *n; // next point down... }; typedef struct do_next_stack_s dn_stack_t; Next, the first function: #define XYZZY 0x02 void push(void) { uint32_t stack[1]; dn_stack_t *s; int i = 1;
s = new dn_stack_t; s->r = *(stack+XYZZY); // save the calling location s->n = dn_stack; dn_stack = s;
i = 1; while (s) { if (i >= 0x50) { assert(0 && "PROGRAM HAS DISAPPEARED INTO THE BLACK LAGOON."); } s->lvl = i++; s = s->n; }
return; }
Finally, the second function: void pop(void) { uint32_t stack[1]; dn_stack_t *s = dn_stack; dn_stack_t *t = dn_stack; int i = 1;
if (resuming >= 0x50) { assert(0 && "ENCOUNTERED PLEASE RESUME(0x50), GIVING UP."); }
while (s && s->lvl != resuming) s = s->n;
if (!s) { assert(0 && "TRYING TO RESUME BEYOND THE STACK, GIVING UP."); }
// You are not expected to understand this. See SOLUTION File. *(stack+XYZZY) = s->r;
dn_stack = s->n; s->n = NULL; s = t; while (s) { t = s; s = s->n; delete t; }
s = dn_stack;
while (s) { if (i >= 0x50) { assert(0 && "PROGRAM HAS DISAPPEARED INTO THE BLACK LAGOON."); } s->lvl = i++; s = s->n; }
return; } push() and pop() are then entered into a couple #defines, and used all over the place. Also, there is a 'forget' function which kills things from the top of the call stack.
Googling a couple of the more flamboyant error messages will give you a dark hint as to the horrors I've conjured from out of the depths.
All men are frauds. The only difference between them is that some admit it. I myself deny it. -- H. L. Mencken
|
|
-
-
waggy


- Joined on 05-15-2007
- Posts 1
|
Re: Post the function you are most proud of.
signed short fq_multiply_bs( NETWORK_VALUE_TYPE o1, MULTIPLY_BS_TYPE bs, BS_TYPE bsl ) { BS_TYPE abs_bs; unsigned short abs_prod; if( (o1==0) || (bs==0) ){return( (signed short) 0);} if( bs<0 ){ abs_bs = (BS_TYPE) (-bs); } else { abs_bs = (BS_TYPE) bs ; }
if( o1<0 ){ abs_prod = (unsigned short) (-o1); } else { abs_prod = (unsigned short) o1 ; } abs_prod<<=bsl; switch(abs_bs) { case 0: return( (signed short) 0 ); break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: abs_prod>>=( 8 - abs_bs ); break; case 8: break; case 9: case 10: case 11: case 12: case 13: case 14: case 15: abs_bs-=8; abs_prod<<= abs_bs; break; default: abs_prod = (unsigned short) SHRT_MAX; } if( ( (o1<=0) && (bs<=0) ) || ( (o1>=0) && (bs>=0) ) ){ return( (signed short) abs_prod ); } else{ return( (signed short) (-abs_prod) ); } }
My apologies if I mangled it when removing the comments, as is the convention in this thread. (FYI 'fq' is mnemonic for 'finger-quotes' and 'bs' is mnemonic for 'bit-shift'.) Admittedly, this function isn't much to look at, though with all the casting you might think I enjoy fishing. I like it because it works surprisingly well for weighting the inputs and applying the IIR filter coefficients to the nodes in a neural network.* Unfortunately I started late (just a few days ago) and did not have time to implement the genetic algorithm needed to develop a network trainable to respond properly (on a virtual 7-segment display) to the test cases. An IIR network with random weights and coefficients does behave rather well, even limited as it is to using 8-bit signed char arrays; the segments seem to flicker with a deep desire to learn the proper response.
*After I had worked out the idea of selecting power-of-two coefficients for a neural network of IIR filters using a genetic algorithm, I found it was far from original: http://www.vu.union.edu/~robleec/capstone/documentation/project_ANNIE_conference.doc
|
|
-
-
SamP


- Joined on 05-05-2007
- Posts 25
|
Re: Post the function you are most proud of.
Whiskey Tango Foxtrot? Over.:Ok, all entered and confirmed! I can't really post a single function that I'm proud of, because they're all very basic, fairly short functions. Well, methods, really -- I took a very object-oriented approach. In fact, I built what I consider to be a very well thought out, very well designed, and ultimately very useless C++ class library. I call my submission the VICE: Virtual Integrated Circuit Engine. I'm rather proud of that backronym. ;) Basically, I took the concept of the Virtual Machine to its reductio ad absurdum: Virtual Transistors. Rather than compute values with the CPU, I built Virtual AND gates, Virtual OR gates, virtual flipflops, virtual registers, and virtual computation units, all composed (ultimately) of Virtual Transistors. Well, the VirtualFlipFlop wasn't -- flipflops are based on a feedback loop, and that would have caused infinite recursion, and I actually wanted to *pass* the tests. :) My goal was a Turing complete VirtualCPU, complete with 4 MB of VirtualRAM, a full set of registers, and a subset of the x86 instruction set, but I ran out of time. In fact, I never got to floating point computation, so Dark Shakiri has me beat in that department. I do, however, have flawless cross-platform 32-bit integer addition, subtraction, and multiplication. Despite being insanely complex, VICE is pretty performant. Wasteful, yes, but performant thanks to fast processors. Hmm... I wonder if it would be as fast as a JVM or .NET? Maybe I'll keep working on it...
What you did can be totally not a WTF. Finish your program, throw up a proper GUI, and you got an excellent learner toolkit for beginner programmers and engineers. Allow students to explore how a basic, conceptual CPU works. Even the calculator would be useful, to visually show all the steps it takes for a basic arithmetic operation to be performed. We're not even talking assembly here. We're talking microcode -- individual control units within the processor itself. I sure wish I had something like that when I studied CPUs. You could even sell the thing if you see it through.
|
|
-
-
Zor


- Joined on 05-14-2007
- Posts 7
|
Re: Post the function you are most proud of.
Not the most exciting function, but I'm proud of it because it was a huge pain, and it looks cool...

I had to post a screenshot, because I couldnt get the formatting to come out right. Pretend that it extends to the right another 900 characters or so
|
|
-
-
kint


- Joined on 05-15-2007
- Posts 1
|
Re: Post the function you are most proud of.
This function does the bulk of the heavy lifting char *CalcInterface::Execute(char* szResult) { ShowWindow(CalcHandle::Instance().getCalcWnd(), SW_SHOWNORMAL); //preamble -- prepare to take over control BlockInput(true); POINT mousePoint; GetCursorPos(&mousePoint); BringWindowToTop(CalcHandle::Instance().getCalcWnd());
//clear Calculator's answer field Clear();
//prep calc for decimal input INPUT Input[1]; memset(Input, 0, sizeof(INPUT)); Input[0].type = INPUT_KEYBOARD; Input[0].ki.wVk = VK_F6; SendInput(1, Input, sizeof(INPUT)); Input[0].ki.dwFlags = KEYEVENTF_KEYUP; SendInput(1, Input, sizeof(INPUT));
//iterate through the command string (e.g. "421-325=") and click the button for each character DebugSpew("CommandProcessor::Execute(%s)", str().c_str()); for (size_t i = 0; i< str().length(); ++i) DoClick(str().at(i));
//postamble -- return control to the user BlockInput(false); SetCursorPos(mousePoint.x, mousePoint.y); BringWindowToTop(gCalcWnd);
re | | |
|