Disable and Enable MFC controls by name

I use this snippet all the time to disable/enable, hide/show, move MFC controls.


// Enables and disables an MFC control by name
void CCILikeChease::EnableControl( int iControl, bool enable )
{
// Enable Control
     CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );
     if( wnd_control != NULL ) {
          wnd_control->EnableWindow( enable ) ;
     }
}
void CNetworkDlg::HideControl( int iControl, bool show )
{
     // Hide the Control
     CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );
     if( wnd_control != NULL ) {
          if( show ) {
               wnd_control->ShowWindow( SW_SHOW ) ;
          } else {
               wnd_control->ShowWindow( SW_HIDE ) ;
          }
     }
}
void CNetworkDlg::MoveControl( int iControl, int top, int left, int sizex, int sizey )
{
     // Move the control
     CWnd* wnd_control = (CWnd*)( GetDlgItem( iControl ) );
     if( wnd_control != NULL ) {
          LPRECT lpRect = new RECT ;
          wnd_control->GetClientRect( lpRect ) ;
          lpRect->top = top;
          lpRect->left = left;
          if( sizex > 0 || sizey > 0 ) {
               lpRect->right = sizex + left ;
               lpRect->bottom = sizey + top;
          }
          wnd_control->MoveWindow( lpRect ) ;
          delete lpRect ;
     }
}

How to access Facebook’s data

In my last article I talked about how to create a very simple Facebook Application.
We created a simple hello world application that didn’t do too much besides login to the Facebook API.

In this article we are going to use the Facebook API to access you and your friends information.
We are then going to display the information a different manner then Facebook.

Requirements

The Facebook API is well documented.
If you want more information on any of the topics that I touch in this article is suggest that you search the Facebook API.

The Facebook API uses a REST-based interface. This means that Facebook method calls are made over the internet by sending HTTP GET or POST requests to the Facebook REST server.

The Facebook API has about a hundred different methods, in this tourial we will be using;

  • friends.get - Returns the identifiers of the current user’s Facebook friends
  • friends.areFriends - Returns whether or not each pair of specified users is friends with each other
  • users.getInfo - Returns a wide array of user-specific information for each user identifier passed, limited by the view of the current user

For a full list of all the different Facebook methods see the Facebook API documentation

Basic Application Architecture
First we need to understand how the Facebook API works.

  1. A browse makes a request
    1. A user browse to the Application canvas page
      Example: http://apps.facebook.com/ninteentwenty/
    2. acebook looks at the call back URL associated with the application.
      Example: http://www.abluestar.com/dev/facebook/
  2. Facebook sends a request for that call back page with the user’s ID as a parameter
  3. Our webserver gets the request and builds a page for this user.
    1. In the process of building the response page, we can request additional information from Facebook REST server.
  4. After the page has been built on our server its sent to Facebook
  5. Facebook serves our response to the user.

Most of the time the user doesn’t know that a 3rd party (our server) was involved at all.
The page appears to come from Facebook its self and is embedded in to a page with an iframe.

Make a request using the Facebook API

When starting off a great place to start is the API Test Console. It a tool for building requests for the Facebook Rest server.

You can select the method, call back function (most of the time left blank) and respond type (XML, PHP array, JSON).

For example if we where to select the friends.get method and the a response type of XML.
It would query the Facebook server for a list of all the currents users friends and return the results in XML.

$friends = $facebook->api_client->friends_get();

We could then take two of these UID (aka user IDs) and test to see if they are friends with the friends.areFriends method.
In this case these two people are not friends with each other.

$friends_areFriends = $facebook->api_client->friends_areFriends( ‘508673161′, ‘504464182′ );

The UID is a great method for uniquely identify members but it would be nice to know who 508673161, and 504464182 are.
To do this we can use the method users.getInfo to get information about these users including there names.

$users_getInfo = $facebook->api_client->users_getInfo( ‘732945108′, “name” );

The test console is a great tool for testing out how methods work and how the response is formated.

Now we want to put all three of these functions together to create a application that lists all your friends common friend.
PopFriends.txt demonstrates how to do this.

How to make a facebook applcation.

We are going to build a simple facebook application to demonstrate how to use the Facebook API.

Requirements:

  • Basic knowledge of php
  • A webserver running php5 that is open to the internet.
  • A facebook account (sign up)

Directions

  1. Add the developers application to your facebook account.
    Goto: http://www.facebook.com/developers/ and add the developers application to your account.
    After you sugsefuly add the devlopers application you should see the devlopers icon on the left sidebar.
  2. Create a new application
    Goto: http://www.facebook.com/developers/editapp.php?new

    1. Application Name: for our app, we put ‘Comp1920 Application’
    2. Check the Terms of service box.
    3. Click on the Optional Fields link - this will bring up more options.
    4. Support E-mail: your Facebook contact email may be filled in automatically, but you might not want to give out your personal email to everyone who adds your app! You do have to put a valid email address that you can check, however.
    5. Callback Url: for our app, we put ‘http://www.abluestar.com/dev/facebook/’ - you should put something DIFFERENT - in particular, you should put the url of the directory on your server where you will create your application.
    6. Canvas Page URL: http://apps.facebook.com/: for our app, we put ‘comp1920tutorialapp’ - you must put in a different name.
    7. Use Iframe: keep this setting.
    8. Application Type: leave this set to ‘Website’.
    9. Can your application be added to Facebook: set to ‘yes’ - this will bring up more options.
    10. TOS URL: you can leave this blank.
    11. Post-Add Url: for our app, we put ‘http://apps.facebook.com/comp1920tutorialapp/’ — you should put something DIFFERENT - in particular, you should put your full canvas page url.
    12. Default FBML: type in the text ‘hello’.
    13. Leave everything else under Installation Options blank.
    14. Side Nav Url: for our app, we put ‘http://apps.facebook.com/comp1920tutorialapp/’ — you should put something DIFFERENT - in particular, you should put your canvas page url here as well.
    15. Leave everything else under Integration Points blank.

    All the fields are described in detail on the Facebook documentations wiki.

    We have created out first Facebook application.
    People will be able to add this application to there accounts but it will not do anything just yet.

  3. Download the Facebook php5 API
    GoTo: http://developers.facebook.com/resources.php
    Extract it to a folder on your local computer.
  4. Create a basic Facebook Application with the Facebook php5 API
    1. Download and edit Step1.php with your faviorite php editor. (I suggest and use notepad++)// Include the Facebook php API
      // The API can be downloaded from facebook’s website. http://developers.facebook.com/resources.php
      require_once ‘facebook.php’;// These are settings that are given to you when you register your applcation.
      // ToDo: Change these setting to match the ones found on your
      // My Applcation page http://www.facebook.com/developers/apps.php
      $appapikey = ‘[your api_key]’;
      $appsecret = ‘[your secret]’;

      // Create an instance of the facebook class.
      $facebook = new Facebook($appapikey, $appsecret);

      // attempt to log in to facebook
      // We will attemp to log in as the current user,
      $user = $facebook->require_login();

      // The call back url for all internal links on this page.
      $appcallbackurl = ‘http://www.abluestar.com/dev/facebook/’;

      // catch the exception that gets thrown if the cookie has an invalid session_key in it
      try {
      if (!$facebook->api_client->users_isAppAdded()) {
      $facebook->redirect($facebook->get_add_url());
      }
      } catch (Exception $ex) {
      // this will clear cookies for your application and
      // redirect them to a login prompt
      $facebook->set_user(null, null);
      $facebook->redirect($appcallbackurl);
      die( “can not load facebook class” );
      }

      // Print the users number.
      echo “hello $user”;

  5. Upload the Facebook API and step1.php to your webserver.
  6. Add the application to your own Facebook account to test it.
    Goto your applications Canvas page: http://apps.facebook.com/comp1920tutorialapp/
    Add your application to your Facebook account.
  7. Browse to your applications page
    Goto your applications Canvas page: http://apps.facebook.com/comp1920tutorialapp/

You have made your first working Facebook Application.
In the next article we will be adding some functionality to the application to make it useful and describing how it all works.

Coyote catches the road runner

Finely!

How to beat 9 grandmasters at once

Flower plug

The flower plug was designed to allow the user to know when the bath water was just the right temperature by changing color from a light pink to a beautiful deep purple color. Once the flower is purple, it is safe to enter the water without the fear of it being too hot.

You probably will not be able to find these down at your local wal mart or bathroom accessory store. I searched for the designers website but came up empty handed. if you know where i can buy one of these, leave me a comment.

Designer: Mi-Soo Jung
Found via: yankodesign.com

Wastbasket for the bathroom

The bin can be sealed by a ordinary magazine, useful for people who like to read on the toilet

Designed by SnowTone

APEX Holiday Subscription Drive

APEX (a sf/horror magazine) announced that they would increase there payment rates to 5 Cents a word (professional levels) if they got 500 new subscribers for November. So far they are at 71 new subscribers, thats pretty good since its only the 9th. they are also running this contest that if you blog about there subscription drive or refer someone to there magazine you get entered in to a contest for a free subscription and a mug.

If Every Day Fiction (short stories daily) tried something like this we would be paying ~$50 or so for each story every single day. Approximately ~1500 a month or 18k a year. I hopefully we get there one day and we can pay authors what they deserve.

Travel 4 km in just 3 hours, 41 minutes!

Last week Translink and Google maps got together and released Google transit.
Google transit allows you to fine transit routs for Vancouver and various other metropolitan cities using Google maps.
I have thought of doing this mash up before but I could never get the data out of Translink properly.

A great system I have used it a few times. Of cource they still have some bugs to work out.

6 transfers and 3 hours, 41 minutes to travail 4k
240 st and Lougheed hwy Maple Ridge ==> Mavis and Glover, Langley, Greater Vancouver

Work Smarter, Not Harder

On Dec. 10, 1968, a uniformed man pulled over a bank car in Tokyo. He explained that police had received a warning that dynamite had been planted in the vehicle, which was transporting bonuses for local Toshiba employees. The four passengers got out and watched as the officer crawled underneath.

After a moment he rolled out, shouting that the car was about to explode. When the passengers ran, he got in and drove off.

Thus one man stole 294,307,500 yen in broad daylight, working alone and without harming anyone. The thief was never caught.

Origami Masters Exhibition

Although historically considered a children’s pastime, origami has exploded in popularity and visibility in recent years.
We are now in a Renaissance period in the history of the ancient art of paperfolding.
Artists from around the world are embracing the medium, and new techniques are being constantly explored and created.
This exhibition highlights some of the best work in the in medium, with works by 25 of the top origami artists from nine countries.

The Pacific Coast Origami Conference will be held in the beautiful Fairmont Hotel Vancouver (9-11 Nov 2007)
A public exhibition will be held at the Pendulum Gallery (HSBC) (1-11 Nov 2007 )

Picture: Geistkampfer by Hojyo Takashi taken by Joseph Wu Origami

The Internet Stars Are Viral

Over the past year there have been a lot of viral videos, being addticted to the interent i seen them all.
Here is a montages of some of the more popular ones.

A viral video about viral videos… hmm.

The zen of zombies

During the first chilly weekend of fall, zombie hordes congregated in the park for a relaxing afternoon of yoga..

The short was used to promote Scott Kenemore new book The Zen of Zombie: Better Living Through the Undead
Found via pranks.com

Lee Krasnow - Puzzle box maker

I stumbled on to “Lee Krasnow” work from a MAKE pod cast that I have included below.

I have always loved these types of puzzles, ring puzzles, box puzzles, ball puzzles. Each year my family would give me a bunch of them for xmas/birthday/etc. 10-15 new puzzles each year some are pretty complex but i have never seen anything as complicated as Lee Krasnow’s Barcode Burr.

Barcode BurrWith so many possible ways to notch the pieces (each of which would yield a different puzzle solving experience) Lee Krasnow decided to design the notches of the Barcode Burr so that the pieces moved in a binary progression. This means that when all six pieces are retracted, the first move is to extend piece #1 which will then allow piece #2 to extend. Once #2 is extended, #1 must be pushed back in before #3 may extend. Because #3 is extended, #4 is now able to move, but not until #2 gets pushed back in place. Of course #2 cannot move until #1 is extended again, and then once this happens #1 must be pushed back in before #4 can finally move.

I didn’t see a price tag on the Barcode Burr but I expect it to be pretty damn expensive.

Song at the end of Portal

Portal is one of the better games I have played this year. A black humor puzzle game thats not repetitive and is actually fun… Fun you remember fun don’t you? the way games use to be before we go all caught up in our new shinny graphics cards.

Anyways here is the ending song. Enjoy

Found via http://www.warrenellis.com/?p=5268

MaBeGroMo Rules

One of my good friends are starting the NaNoWriMo today so far hes gotten 457 words in. Not being a writer or wanting to be one I am effectively disqualified from the compaction.

So instead I am joining the MabeGroMo.

MaBeGroMo Rules

Rule 1: At some point between now and November 1, you take a “before” picture of yourself and put your razor away.
Rule 2: At some point after November 30, you take an “after” picture of yourself, and decide whether to reunite with your razor or renew your short-term contract with your newly found friend. You may then claim the title of “MaBeGroMo Member”
Rule 3: If you make it to February 14, you have beaten the extended challenge and can rightfully claim the title of “MaBeGroMo Champion.”
Rule 4: If you make it past February 14, step out of the Home Depot, put down the deer carcass, and shower well before signing up for several internet “dating” services. This is just a suggestion.

You’re thinking about it. I can see it. I’ve taken the liberty of answering some of your presented concerns to give you the encouragement to get started in The Beard FAQ. Good luck.