Comment On Pragmatically Registering

Even if you're pretty certain that your way isn't the best way, sometimes it's just easier to go with what you know instead of struggling with something new. I'm pretty sure that's what the author of today's code (found in the Sidebar) was thinking. He knew that to register a OCX library, you click the Start Button, then press R (for Run), then type in -- well, you get the idea. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Pragmatically Registering

2005-12-27 14:07 • by dshiznit
Noooooooooooooooooooooooooooooooooooo!

That's all I have to say about that!

Re: Pragmatically Registering

2005-12-27 14:10 • by Kippesoep
Om my God! That is horrendous. I wonder what it would do on my system where the taskbar is at the top of the screen. Can't be good...

Re: Pragmatically Registering

2005-12-27 14:12 • by Gene Wirchenko
Alex Papadimoulis:
Even if you're pretty certain that your way isn't the best way, sometimes it's just easier to go with what you know instead of struggling with something new. I'm pretty sure that's what the author of today's code (found in the Sidebar) was thinking. He knew that to register a OCX library, you click the Start Button, then press R (for Run), then type in -- well, you get the idea.


Let us get tied into (knots with) the UI.

I wonder if it occurred to him that there could be a better way.  Considering what he did know, it ought to be a reasonable conclusion that there is probably a better way that is easy.

Sincerely,

Gene Wirchenko

Re: Pragmatically Registering

2005-12-27 14:12 • by Wilbur
I call shenanigans!

This can't really be true?!@?#?$

*cry*

-- W

Re: Pragmatically Registering

2005-12-27 14:16 • by Scott
54681 in reply to 54680
Hey that sounds a lot like this:
http://blogs.msdn.com/oldnewthing/archive/2005/08/16/452141.aspx

(the story in the last paragraph)

Re: Pragmatically Registering

2005-12-27 14:17 • by limelight
Another quality piece of code from the VB community.

Re: Pragmatically Registering

2005-12-27 14:18 • by mlathe
54683 in reply to 54680
I have two rows in my task bar (you can open lots of windows)... Therefore in my case i'd guess that he'd miss my start button! oops... too bad it doesn't error with an "Aaaarrrrrgggghhh" msg

Re: Pragmatically Registering

2005-12-27 14:18 • by scooter
What happens when a user moves their taskbar to the right hand side of the screen?



I would suggest that this programmer make sweeps across the screen,
examining 20x20 px squares looking for a portion of the word
"Start".  This would be a much more robust solution for locating
the start menu than just assuming that Screen.Height / 15 - 10 will work.

Re: Pragmatically Registering

2005-12-27 14:18 • by leo

Thankfully, "run" is the only thing in the Start menu that could possibly start with an "R"... [8-)]

Re: Pragmatically Registering

2005-12-27 14:22 • by cconroy
54686 in reply to 54685
Holy mother of Bob.



Re: Pragmatically Registering

2005-12-27 14:23 • by mlathe
Alex Papadimoulis:

Screen.Height / 15 - 10


Anyone want to comment on what this does? is he assuming that the start menu height is 1/15th of the screen height, and that he can just subtract 10 to land in the middle? What if your screen is really big?

Re: Pragmatically Registering

2005-12-27 14:24 • by scooter
54688 in reply to 54684
Better yet, what do you think happens when this guy wants to call
another executable?  I'll bet it goes something like this:




  1. Use Windows API calls to move the mouse to the taskbar

  2. (hope that there's nothing but blank taskbar under the mouse)

  3. Use Windows API calls to right click

  4. Use Windows API calls to move the mouse up to "Show the Desktop"

  5. (hope that the user is running XP -- earlier versions said something like "Minimize All Windows")

  6. Use Windows API calls to release the mouse

  7. Use Windows API calls to move the mouse to the default location for "My Computer"

  8. (hope that the user has not moved any desktop icons)

  9. ...... you get the picture .....



Re: Pragmatically Registering

2005-12-27 14:28 • by Sweets
GET OUT!!!!

Re: Pragmatically Registering

2005-12-27 14:31 • by Makli
54690 in reply to 54685
Anonymous:

Thankfully, "run" is the only thing in the Start menu that could possibly start with an "R"... [8-)]



The other problem is that it's 'R' only on the english version on Windows. In my czech version it would be 'T'.

Re: Pragmatically Registering

2005-12-27 14:32 • by ferrengi
Wow,

If you can send me the executable for this "program", I would love to
run it on my machine and watch this monstrosity in action. I never
cease to be amazed how people are willing to spend the time and effort
to do this kind of stuff and not give up until they get the darn thing
working using their WTF solution.

I am much too lazy to get this kind of junk to work.



All I can say is good job!

Re: Pragmatically Registering

2005-12-27 14:33 • by uncool
54692 in reply to 54689

hell yeah!


i'm reminded of old windows and record macro thinggy ... that caused me all kinds of problems

Re: Pragmatically Registering

2005-12-27 14:36 • by Gene Wirchenko
54693 in reply to 54678
Kippesoep:
Om my God! That is horrendous. I wonder what it would do on my system where the taskbar is at the top of the screen. Can't be good...


Ah, someone else who likes the taskbar at the top.

I have seen a number of programs, ah, not do well, when the taskbar is at the top of the screen.  Is there a series of WTFs on assuming default setups?

Sincerely,

Gene Wirchenko

Re: Pragmatically Registering

2005-12-27 14:38 • by Gene Wirchenko
54694 in reply to 54685
Anonymous:
Thankfully, "run" is the only thing in the Start menu that could possibly start with an "R"... [8-)]


I once had a finger slip on one command and so typed "ruin" for "run".

Sincerely,

Gene Wirchenko

Re: Pragmatically Registering

2005-12-27 14:45 • by Datheron
54696 in reply to 54693
Since Windows NT, I believe, Windows has provided functions that



i. return the screen resolution (e.g. 1024x768)

ii. return a RECT of the available screen real estate minus the space
taken up by the taskbar (e.g. 0, 0, 1024, 700 if your taskbar is on the
bottom; 80, 0, 1024, 768 if your taskbar is on the left, etc.)



Far too often programs assume that the upper-left corner of the screen
is (0,0), so taskbar positions that mess with that cause all sorts of
havoc.

Re: Pragmatically Registering

2005-12-27 14:50 • by crackel
Yet another shining example of the typical quality of a Visual Basic developer's code.

Re: Pragmatically Registering

2005-12-27 14:53 • by foxyshadis
My favorite part is that he uses sendkeys, but the idea of using sendkeys to send the "windows" key, which pops up the start menu! (Unless you have some wicked wild key remapping going on.)

Re: Pragmatically Registering

2005-12-27 14:55 • by Franky Pelvis
I'm not sure if people are joking or not with some of the responses to
this WTF.  Their is no good way to do this using screen
geometry.  As a hack you might be able to send WINDOWS+R to
duplicate the Start->Run monstrosity. However, the correct way to do
this sort of thing in VB is probably with Shell() or CreateProcess()
depending on whether or not you need to capture output, and if you need
to wait for the process to exit before continuing.  That's as of
VB6, I haven't used VB.Net.

Re: Pragmatically Registering

2005-12-27 14:58 • by limelight
Alex Papadimoulis:


  SetCursorPos 32, Screen.Height / 15 - 10

mouse_event MOUSEEVENTF_ABSOLUTE, 32, Screen.Height / 15 - 10, 1, 1
mouse_event MOUSEEVENTF_LEFTDOWN, 32, Screen.Height / 15 - 10, 1, 1
mouse_event MOUSEEVENTF_LEFTUP, 32, Screen.Height / 15 - 10, 1, 1

Alright, I had to look into this as I just couldn't figure out what Screen.Height / 15 - 10 was suppose to do. Screen.Height returns the height of the screen measured in twips. After trying to figure out how this factored in, I decided to take my screen height in twips (11520) and divide it by my screen height as measured by the control panel display applet in pixels (768) and ... you guessed it ... the answer if 15. The author was apparantly trying to convert from twips to screen coordinates. I really don't see how this calculation helps, however, as the API does not take the measurement in pixels, but in normalized absolute coordinates:


 "dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner" (from the MSDN documentation).


Also, he passes in a value of 1 for the parameter dwData, which only applies for wheel data or X buttons. To quote the documentation:

"If dwFlags is not MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then dwData should be zero. "

Re: Pragmatically Registering

2005-12-27 15:00 • by GoatCheez
54702 in reply to 54701
The CORRECT way is to use LoadLibrary, then GetProcAddress (to get the address of the function DllRegisterServer) and then use that address to call DllRegisterServer. I'm still surprised the dude didn't send WindowsKey+R for the run menu.

Re: Pragmatically Registering

2005-12-27 15:01 • by scooter
54704 in reply to 54700
Anonymous:
I'm not sure if people are joking or not with some of the responses to
this WTF.  Their is no good way to do this using screen
geometry.




You obviously have no sense of adventure...  Real Windows UI programmers don't rely on those flaky events like Button.Click(). 
If you are at all serious about quality programs, capture the Click
event and use the Windows SendKey() method to hop the tab order on your
form until you get to the right button.  Then you can use
SendKey() to send "Return"....


Re: Pragmatically Registering

2005-12-27 15:03 • by GoatCheez
54705 in reply to 54704
scooter:
Anonymous:
I'm not sure if people are joking or not with some of the responses to
this WTF.  Their is no good way to do this using screen
geometry.




You obviously have no sense of adventure...  Real Windows UI programmers don't rely on those flaky events like Button.Click(). 
If you are at all serious about quality programs, capture the Click
event and use the Windows SendKey() method to hop the tab order on your
form until you get to the right button.  Then you can use
SendKey() to send "Return"....



Yeah, I seem to remember alot of information on UI programming spread around at about the same time those pay to browse programs started popping up... coincidence?

Re: Pragmatically Registering

2005-12-27 15:04 • by MikeB
I'm speechless.....uuuhhhmmmm. Oh, do chickens have large talons?

Re: Pragmatically Registering

2005-12-27 15:04 • by GoatCheez
54707 in reply to 54705
pay to browse meaning whatever company would pay you $.02 an hour to browse the web while their adds were on the bottom/top of your screen.

Re: Pragmatically Registering

2005-12-27 15:06 • by Doobie Dan
54708 in reply to 54691

ferrengi:
Wow,
If you can send me the executable for this "program", I would love to run it on my machine and watch this monstrosity in action.


You would let that run on your machine?!!  You, sir, are a brave man.  I salute you.

Re: Pragmatically Registering

2005-12-27 15:11 • by Richard Nixon
54709 in reply to 54694
Gene Wirchenko:
Anonymous:
Thankfully, "run" is the only thing in the Start menu that could possibly start with an "R"... [8-)]


I once had a finger slip on one command and so typed "ruin" for "run".

Sincerely,

Gene Wirchenko



Wow, that's really fascinating. Any other stories about typos you've made in the past? Please, enthrall and entertain us.

Sincerely,
Richard Nixon

Re: Pragmatically Registering

2005-12-27 15:20 • by bjmarte
54710 in reply to 54709
Holy *bleeping* *bleep*. I read this thing religiously.  I thought I'd seen it all, now this [:O]

Re: Pragmatically Registering

2005-12-27 15:21 • by GoatCheez
54711 in reply to 54709
Yet another nixon post contributing nothing while trying to make another poster feel bad. I wonder why. I know nixon sucked... but wtf lol.

Not so bad...

2005-12-27 15:37 • by RevMike
Without more context, I can't really complain too much.  I've seen lots of testing software that puts events on the event queue to simulate how a user would actually do something.  Perhaps this was a test program for an install process?

Oh, who am I kidding.  This is horrible.

Re: Not so bad...

2005-12-27 16:42 • by Nand
54713 in reply to 54712
Well, to be fair, the code comes from a bunch of kids trying to figure out programming, and the author is aware of how awful this way of registering a control is.

http://www.youngcoders.com/thread15404.html

It's still quite an achievement to come up with a solution *this* wrong though :)

Re: Pragmatically Registering

2005-12-27 16:46 • by What's a name?
The more I read on this site the more I am convinced that I should get out of the programming business. I simply don't want to be associated with people who do such things and call themself "programmers".

Used car salesman seems like a much more honest profession than programming to me now. Any job offers?

Re: Pragmatically Registering

2005-12-27 17:02 • by jeremydwill
54715 in reply to 54714

Anonymous:
The more I read on this site the more I am convinced that I should get out of the programming business. I simply don't want to be associated with people who do such things and call themself "programmers".

Used car salesman seems like a much more honest profession than programming to me now. Any job offers?


http://jobsearch.monster.com/jobsearch.asp?q=used+car+sales&fn=&lid=&re=104&cy=us

Re: Pragmatically Registering

2005-12-27 17:11 • by Axel
54716 in reply to 54715
    With a german Windows this will even shutdown the computer Oo

Re: Pragmatically Registering

2005-12-27 17:14 • by GoatCheez
54717 in reply to 54714
Anonymous:
The more I read on this site the more I am convinced that I should get out of the programming business. I simply don't want to be associated with people who do such things and call themself "programmers".

Used car salesman seems like a much more honest profession than programming to me now. Any job offers?


I think the true problem lies in our education system. People are graduating college with computer science degrees who don't C from C#, or Java from JavaScript. Yet, they still manage to pass all of their programming classes. I really think it has to do with some college requiring professors to pass X amount of students. If a professor gets 100 kids who can't program, and never learn how to, he still has to pass some or the administrators will thing he or she cannot teach programming. If it were up to me, I would have a very strict grading structure, and am sure that most of the time only one or two people would just barely pass a test in a group of 20. I have had to tutor CS students, and some of them just cannot be tought how to program. These people still manage to get their degrees. This is THE reason why I feel that CS degrees are completely useless.

Re: Pragmatically Registering

2005-12-27 17:37 • by sao
54718 in reply to 54709
Richard Nixon:
Gene Wirchenko:
Anonymous:
Thankfully, "run" is the only thing in the Start menu that could possibly start with an "R"... [8-)]


I once had a finger slip on one command and so typed "ruin" for "run".

Sincerely,

Gene Wirchenko



Wow, that's really fascinating. Any other stories about typos you've made in the past? Please, enthrall and entertain us.

Sincerely,
Richard Nixon



i once typed 'teh' instead of 'the'.

Re: Pragmatically Registering

2005-12-27 17:47 • by spotcatbug
54720 in reply to 54718
I would like to see the routine he would create to output to a text file. Let's see, first move the mouse to the Notepad icon. Issue a double-click. Send keys for the entire contents of the text file being output. Move the mouse to the File menu. Click. Move to Exit. Click. Move to "Yes" button. Click "Yes" to save. And, of course, just hard-code the locations of all these things in absolute screen coordinates because everybody's computer is set up exactly like mine and I never move the Notepad window.

Re: Not so bad...

2005-12-27 18:10 • by Jeff S
54721 in reply to 54712

A classic "WTF" in the true spirit of what this site is all about.


Thanks, Alex !!

Re: Pragmatically Registering

2005-12-27 18:15 • by TLLOTS
54722 in reply to 54717
GoatCheez:
I think the true problem lies in our education system. People are graduating college with computer science degrees who don't C from C#, or Java from JavaScript. Yet, they still manage to pass all of their programming classes. I really think it has to do with some college requiring professors to pass X amount of students. If a professor gets 100 kids who can't program, and never learn how to, he still has to pass some or the administrators will thing he or she cannot teach programming. If it were up to me, I would have a very strict grading structure, and am sure that most of the time only one or two people would just barely pass a test in a group of 20. I have had to tutor CS students, and some of them just cannot be tought how to program. These people still manage to get their degrees. This is THE reason why I feel that CS degrees are completely useless.

I'm inclined to agree. I recently went through a webdevelopment course (not the same as a CS degree I know), but while it taught programming in javascript and php, not once was it taught how to program. While I'm quite pleased to have recieved a diploma for the course, it's not something I'd place much value in when it comes to job interviews etc. Indeed if I ever find myself in the position of hiring people and I saw someone with the same degree I'd be more inclined to be harder on them, simply because of the level of crap I saw that was allowed to pass, including some code by one of the students which rivaled much of the WTF code I've seen posted here.

Re: Pragmatically Registering

2005-12-27 18:50 • by Quinnum
54723 in reply to 54684
scooter:
What happens when a user moves their taskbar to the right hand side of the screen?



I would suggest that this programmer make sweeps across the screen,
examining 20x20 px squares looking for a portion of the word
"Start".  This would be a much more robust solution for locating
the start menu than just assuming that Screen.Height / 15 - 10 will work.




Arrgh but what about if 'auto-hide' is enabled ???



Re: Pragmatically Registering

2005-12-27 19:32 • by Runtime Error
54724 in reply to 54723
Quinnum:
scooter:
What happens when a user moves their taskbar to the right hand side of the screen?



I would suggest that this programmer make sweeps across the screen,
examining 20x20 px squares looking for a portion of the word
"Start".  This would be a much more robust solution for locating
the start menu than just assuming that Screen.Height / 15 - 10 will work.




Arrgh but what about if 'auto-hide' is enabled ???






The obvious solution is to reset the user's taskbar location and other
settings back to default settings when the program starts.

Re: Pragmatically Registering

2005-12-27 19:43 • by GWheeler
54725 in reply to 54681
Hey that sounds a lot like this:
http://blogs.msdn.com/oldnewthing/archive/2005/08/16/452141.aspx

(the story in the last paragraph)

Don't laugh. I have a driver install program that actually has to do that. It installs a device driver for some custom hardware on a 'headless' box (no keyboard, mouse, or monitor). In our case, there is no user to dismiss the message boxes for us.

Re: Pragmatically Registering

2005-12-27 20:06 • by aikimark
54726 in reply to 54723

Quinnum:

Arrgh but what about if 'auto-hide' is enabled ???


That was going to be my question.  Since you've asked it, with toungue firmly implanted in my cheek, I submit:

Declare Function ScreenShout Lib "user32" Alias "ScreenShout" (ByVal SayWhat As String) As Long
lngRC = ScreenShout("Ollie, Ollie, Oxen Free")

If lngRC <> 0 Then   'We have unhidden the task bar
... 'click the task bar in one of the four quadrants
Else
lngRC = ScreenShout("Come out. Come out, wherever you are")
If lngRC <> 0 Then   'We have unhidden the task bar
... 'click the task bar in one of the four quadrants

Else
... 'keep shouting in different languages
End If
End If 

====================


Note: Be sure to programmatically turn up the speakers and unmute them before calling the ScreenShout API.


What?!?  The ScreenShout API isn't one of the special 'hidden' APIs that Microsoft uses to maintain their Office marketshare dominance?

Re: Pragmatically Registering

2005-12-27 22:16 • by Xarium
54732 in reply to 54726
A long time ago I put my Start Menu at the top of the screen to test
what it was like having it up amoungst the rest of the menus.  I
have kept it only partially for that reason because it has proved to be
a stunningly accurate (and early/fast) software worthiness
filter.  It works like this; I install a piece of software and if
it breaks or does something stupid because the Start Menu isn't where
the code assumes it is (like the above piece of code does) I uninstall
it immediately.

You'd be surprised how many previously reputable software companies
have failed this simple test.  No Adobe product will never be
installed be me again - sadly, I haven't found a way to replace Flash
yet, but then it hasn't been an Adobe product for as long either.

Re: Pragmatically Registering

2005-12-27 22:19 • by Xarium
54733 in reply to 54732
Correction: No Adobe product will EVER be
installed be me again



Meanwhile, I've just learned that the "edit feature" appears not to be...

Re: Pragmatically Registering

2005-12-27 22:29 • by FrostCat
54734 in reply to 54718

sao:
i once typed 'teh' instead of 'the'.


I used to know a guy who's last name was Teh.  The fun he had using Word...

Re: Pragmatically Registering

2005-12-28 00:03 • by Vector
mouse_event MOUSEEVENTF_ABSOLUTE, 32, Screen.Height / 15 - 10, 1, 1

mouse_event MOUSEEVENTF_LEFTDOWN, 32, Screen.Height / 15 - 10, 1, 1

mouse_event MOUSEEVENTF_LEFTUP, 32, Screen.Height / 15 - 10, 1, 1




Heh... the funny thing about that is that he could've called Screen.twipsPerPixelY rather than hard-coding 15.


By entering 15 he's assuming that the user has the screen set at a particular resolution (probably 1024x768).


So, If you run 800x600 or 1280x1024 it's probably not even gonna hit the right spot anyway. :^)
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment