Blog

Posts about technology and arts.

Code to change your message in MSN messenger

I’ve always wanted to know how does the code to show what was I listening to looked like. I found it after installing XMPlay and XMPlay MSN Plug-in. The plug-in zip had the plug-in itself and its source code. And what a neat source code (-:.

Basically, you just send a message to the MSN UI API with a defined data structure. And to remove the message, just send again with an empty string.

/*
Bruno de Paula Kinoshita
original src code:
XMPlay MSN Plugin (c) 2005-2006 Elliott Sales de Andrade
*/

#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

typedef struct {
BOOL showCues;
BOOL keepOnClose;
} MSNStuff;
static MSNStuff msnConf;

void setNowPlaying( char *title)
{
    wchar_t *lpMsn;
    int strLen = 20;
    HWND xmpwin;
    HWND msnui=0;
    
    lpMsn = (wchar_t*)calloc(1024,1024);
    // stuff for MSN before...
    memcpy(lpMsn, L&quot;\&#92;&#48;Music\&#92;&#48;1\&#92;&#48;{0}\&#92;&#48;&quot;, 17*2);
    // actual title...
    strLen=MultiByteToWideChar(false?CP_UTF8:CP_ACP,0,title,-1,lpMsn+17,492)-1;  /* 1024/2 - 20 */
    // stuff for MSN after...
    memcpy(lpMsn + 17 + strLen, L&quot;\&#92;&#48;&quot;, 3*2);
    strLen += 20;
    
    COPYDATASTRUCT msndata;
    msndata.dwData = 0x547;
    msndata.lpData = (void*)lpMsn;
    msndata.cbData = strLen * 2;
    
    while ( msnui = FindWindowEx(NULL, msnui, &quot;MsnMsgrUIManager&quot;, NULL) )
        SendMessage(msnui, WM_COPYDATA, (WPARAM)xmpwin, (LPARAM)&amp;msndata);
}

int main(int argc, char *argv[])
{
    char *title;
    
    if ( argc == 1 )
        title = &quot;&quot;;
    else
        title = argv[1];
    
    setNowPlaying ( title );
    
    return EXIT_SUCCESS;
}

Displaying Japanese characters in Java Swing

It’s not as complicated as I first thought.

Had to use this technique to develop an Swing application for the JLPT certification exam.

public static void main(String[] args) {
	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	Container container = frame.getContentPane();
	JLabel japanese = new JLabel( "Kino\u304D\u306E" );
	japanese.setToolTipText( "This is Japanese" );
	Font f = new Font("Arial Unicode MS", Font.BOLD, 16);
	japanese.setFont(f);
	container.add( japanese );
	frame.pack();
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
}

All you have to do is to use the hexadecimal representation of the characters instead of using plain text. And here is the result.

=

Banzai!

Subscribe