A life of windows message

The Basic Windows Message (The Old New Story)

    A. First Edition

    This is just a little practice and I am bit embarrassed when I made some low level mistakes. However, I don't think the

    comment is fair enough!

    B.The problem

The problem starts like this. In the simplest "hello-world" windows creation program, I forget to return the "DefWindowProc". And it takes me hours to debug and still have no clue why "CreateWindow" fails. W gives me some intolerable comments when he pointed out my mistake. But he doesn't really understand the real reason behind this.

Usually when you setup a callback function, you don't really need to guarantee it works because it is just a pointer and

only fails when the program runs. However, "CreateWindow" does more than what I expect. It deliberately asks you to handle

at least some basic message. i.e. If you don't return TRUE for message "WM_NCCREATE", "CreateWindow" will fail. And this

is the reason when you don't use "DefWindowProc" and fail to create window because in many other message handling you need

to return 0 instead of 1.

C.The idea of program

First I trace to write down all possible message in a file and then try to figure out what is the minimum message needed

to be processed by "DefWindowProc". This is really a boring job and that is why this simple program is worthwhile to be

posted because you have to copy&paste for nearly one hundred message cases.

    D.The major functions

    ¡¡

    E.Further improvement

    I finally pinpoint all fundamental messages and it is quite worthwhile for a whole evening work!

    ¡¡

    F.File listing

    1. myWin.cpp

    ¡¡

    file name: myWin.cpp

    #include <windows.h>
    #include <stdio.h>

    WNDCLASS wndClass;
    int nWinWidth, nWinHeight;
    BYTE count=200;

    int counter=0;

    FILE* stream;

    LRESULT CALLBACK WindowProc
    				(HWND hwnd,      // handle to window
    				UINT uMsg,      // message identifier
    				WPARAM wParam,  // first message parameter
    				LPARAM lParam   // second message parameter
    				)
    {
    	//fprintf(stream, "%d:", counter++);
    	switch(uMsg)
    	{
    		//this is necessary because CreateWindow may fail if not return TRUE
    	case WM_NCCREATE:
    		fprintf(stream, "WM_NCCREATE");
    		return TRUE;//////////////////
    		break;
    		//this is necessary because window won't calculate redraw area
    	case WM_NCCALCSIZE:
    		fprintf(stream, "WM_NCCALCSIZE");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//this is when window draw title bar
    	case WM_NCACTIVATE:
    		fprintf(stream, "WM_NCACTIVATE");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//window paint frame
    	case WM_NCPAINT:
    		fprintf(stream, "WM_NCPAINT");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//paint background
    	case WM_ERASEBKGND:
    		fprintf(stream, "WM_ERASEBKGND");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//all mouse click event needs this
    	case WM_NCHITTEST:
    		fprintf(stream, "WM_NCHITTEST");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    		//you want to set mouse cursor to arrow instead of "sand"
    	case WM_SETCURSOR:
    		fprintf(stream, "WM_SETCURSOR");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//you want mouse be clicked and up
    	case WM_NCLBUTTONDOWN:
    		fprintf(stream, "WM_NCLBUTTONDOWN");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//you want system command be carried, like shutdown from "window menu"
    	case WM_SYSCOMMAND :
    		fprintf(stream, "WM_SYSCOMMAND ");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    		//ask you if you want to shut down
    	case WM_CLOSE:
    		fprintf(stream, "WM_CLOSE");
    		DestroyWindow(hwnd);
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    		//if you don't post quit message, message loop won't end
    	case WM_DESTROY:
    		fprintf(stream, "WM_DESTROY");
    		PostQuitMessage(0);
    		break;

    	}

    	return 0L;
    }

    /*
    LRESULT CALLBACK WindowProc
    				(HWND hwnd,      // handle to window
    				UINT uMsg,      // message identifier
    				WPARAM wParam,  // first message parameter
    				LPARAM lParam   // second message parameter
    				)
    {
    	//fprintf(stream, "%d:", counter++);
    	switch(uMsg)
    	{
    	case WM_GETMINMAXINFO:
    		fprintf(stream, "WM_GETMINMAXINFO");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_NCCREATE:
    		fprintf(stream, "WM_NCCREATE");
    		return TRUE;//////////////////
    		break;
    	case WM_NCCALCSIZE:
    		fprintf(stream, "WM_NCCALCSIZE");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_CREATE:
    		fprintf(stream, "WM_CREATE");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_SHOWWINDOW:
    		fprintf(stream, "WM_SHOWWINDOW");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_WINDOWPOSCHANGING:
    		fprintf(stream, "WM_WINDOWPOSCHANGING");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    	case WM_ACTIVATEAPP:
    		fprintf(stream, "WM_ACTIVATEAPP");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_NCACTIVATE:
    		fprintf(stream, "WM_NCACTIVATE");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_GETTEXT:
    		fprintf(stream, "WM_GETTEXT");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_ACTIVATE:
    		fprintf(stream, "WM_ACTIVATE");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_IME_SETCONTEXT:
    		fprintf(stream, "WM_IME_SETCONTEXT");
    		break;
    	case WM_IME_NOTIFY:
    		fprintf(stream, "WM_IME_NOTIFY");
    		break;
    	case WM_SETFOCUS:
    		fprintf(stream, "WM_SETFOCUS");
    		break;
    	case WM_NCPAINT:
    		fprintf(stream, "WM_NCPAINT");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    	case WM_ERASEBKGND:
    		fprintf(stream, "WM_ERASEBKGND");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);

    		break;
    	case WM_WINDOWPOSCHANGED:
    		fprintf(stream, "WM_WINDOWPOSCHANGED");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_SIZE:
    		fprintf(stream, "WM_SIZE");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_MOVE:
    		fprintf(stream, "WM_MOVE");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_PAINT:
    		fprintf(stream, "WM_PAINT");
    		break;
    	case WM_GETICON:
    		fprintf(stream, "WM_GETICON");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    	case WM_KEYUP:
    		fprintf(stream, "WM_KEYUP");
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_NCHITTEST:
    		fprintf(stream, "WM_NCHITTEST");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_SETCURSOR:
    		fprintf(stream, "WM_SETCURSOR");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case EN_KILLFOCUS:
    		fprintf(stream, "EN_KILLFOCUS");
    		break;

    	case WM_NCMOUSEMOVE:
    		fprintf(stream, "WM_NCMOUSEMOVE");
    		break;

    	case WM_NCLBUTTONDOWN:
    		fprintf(stream, "WM_NCLBUTTONDOWN");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_CAPTURECHANGED:
    		fprintf(stream, "WM_CAPTURECHANGED");
    		break;
    	case WM_SYSCOMMAND :
    		fprintf(stream, "WM_SYSCOMMAND ");
    		return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	case WM_CLOSE:
    		fprintf(stream, "WM_CLOSE");
    		DestroyWindow(hwnd);
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;

    	case WM_KILLFOCUS:
    		fprintf(stream, "WM_KILLFOCUS");
    		break;

    	case WM_DESTROY:
    		fprintf(stream, "WM_DESTROY");
    		PostQuitMessage(0);
    		break;

    	default:
    		fprintf(stream, "not listed %d", uMsg);
    		//return DefWindowProc(hwnd, uMsg, wParam, lParam);
    		break;
    	}
    	fprintf(stream, "\n");
    	return 0L;
    }
    */

    /*
    LRESULT CALLBACK WindowProc
    				(HWND hwnd,      // handle to window
    				UINT uMsg,      // message identifier
    				WPARAM wParam,  // first message parameter
    				LPARAM lParam   // second message parameter
    				)
    {
    	//fprintf(stream, "%d:", counter++);
    	switch(uMsg)
    	{
    	case WM_ACTIVATE:
    		fprintf(stream, "WM_ACTIVATE");
    		break;
    	case WM_ACTIVATEAPP:
    		fprintf(stream, "WM_ACTIVATEAPP");
    		break;
    	case WM_CANCELMODE:
    		fprintf(stream, "WM_CANCELMODE");
    		break;
    	case WM_CHILDACTIVATE:
    		fprintf(stream, "WM_CHILDACTIVATE");
    		break;
    	case WM_CLOSE:
    		fprintf(stream, "WM_CLOSE");
    		break;
    	case WM_COMPACTING:
    		fprintf(stream, "WM_COMPACTING");
    		break;
    	case WM_CREATE:
    		fprintf(stream, "WM_CREATE");
    		break;
    	case WM_DESTROY:
    		fprintf(stream, "WM_DESTROY");
    		PostQuitMessage(0);
    		break;
    	case WM_ENABLE:
    		fprintf(stream, "WM_ENABLE");
    		break;
    	case WM_ENTERSIZEMOVE:
    		fprintf(stream, "WM_ENTERSIZEMOVE");
    		break;
    	case WM_EXITSIZEMOVE:
    		fprintf(stream, "WM_EXITSIZEMOVE");
    		break;
    	case WM_GETICON:
    		fprintf(stream, "WM_GETICON");
    		break;
    	case WM_GETMINMAXINFO:
    		fprintf(stream, "WM_GETMINMAXINFO");
    		break;
    	case WM_GETTEXT:
    		fprintf(stream, "WM_GETTEXT");
    		break;
    	case WM_GETTEXTLENGTH:
    		fprintf(stream, "WM_GETTEXTLENGTH");
    		break;
    	case WM_INPUTLANGCHANGE:
    		fprintf(stream, "WM_INPUTLANGCHANGE");
    		break;
    	case WM_INPUTLANGCHANGEREQUEST:
    		fprintf(stream, "WM_INPUTLANGCHANGEREQUEST");
    		break;
    	case WM_MOVE:
    		fprintf(stream, "WM_MOVE");
    		break;
    	case WM_MOVING:
    		fprintf(stream, "WM_MOVING");
    		break;
    	case WM_NCACTIVATE:
    		fprintf(stream, "WM_NCACTIVATE");
    		break;
    	case WM_NCCALCSIZE:
    		fprintf(stream, "WM_NCCALCSIZE");
    		break;
    	case WM_NCCREATE:
    		fprintf(stream, "WM_NCCREATE");
    		//return TRUE;///
    		break;
    	case WM_NCDESTROY:
    		fprintf(stream, "WM_NCDESTROY");
    		break;
    	case WM_PARENTNOTIFY:
    		fprintf(stream, "WM_PARENTNOTIFY");
    		break;
    	case WM_QUERYDRAGICON:
    		fprintf(stream, "WM_QUERYDRAGICON");
    		break;
    	case WM_QUERYOPEN:
    		fprintf(stream, "WM_QUERYOPEN");
    		break;
    	case WM_QUIT:
    		fprintf(stream, "WM_QUIT");
    		break;
    	case WM_SETICON:
    		fprintf(stream, "WM_SETICON");
    		break;
    	case WM_SETTEXT:
    		fprintf(stream, "WM_SETTEXT");
    		break;
    	case WM_SHOWWINDOW:
    		fprintf(stream, "WM_SHOWWINDOW");
    		break;
    	case WM_SIZE:
    		fprintf(stream, "WM_SIZE");
    		break;
    	case WM_SIZING:
    		fprintf(stream, "WM_SIZING");
    		break;
    	case WM_STYLECHANGED:
    		fprintf(stream, "WM_STYLECHANGED");
    		break;
    	case WM_STYLECHANGING:
    		fprintf(stream, "WM_STYLECHANGING");
    		break;
    	case WM_USERCHANGED:
    		fprintf(stream, "WM_USERCHANGED");
    		break;
    	case WM_WINDOWPOSCHANGED:
    		fprintf(stream, "WM_WINDOWPOSCHANGED");
    		break;
    	case WM_WINDOWPOSCHANGING:
    		fprintf(stream, "WM_WINDOWPOSCHANGING");
    		break;
    	case WM_IME_CHAR:
    		fprintf(stream, "WM_IME_CHAR");
    		break;
    	case WM_IME_COMPOSITION:
    		fprintf(stream, "WM_IME_COMPOSITION");
    		break;
    	case WM_IME_COMPOSITIONFULL:
    		fprintf(stream, "WM_IME_COMPOSITIONFULL");
    		break;
    	case WM_IME_CONTROL:
    		fprintf(stream, "WM_IME_CONTROL");
    		break;
    	case WM_IME_ENDCOMPOSITION:
    		fprintf(stream, "WM_IME_ENDCOMPOSITION");
    		break;
    	case WM_IME_KEYDOWN:
    		fprintf(stream, "WM_IME_KEYDOWN");
    		break;
    	case WM_IME_KEYUP:
    		fprintf(stream, "WM_IME_KEYUP");
    		break;
    	case WM_IME_NOTIFY:
    		fprintf(stream, "WM_IME_NOTIFY");
    		break;
    		//win2k msg
    //	case WM_IME_REQUEST:
    //		fprintf(stream, "WM_IME_REQUEST");
    //		break;
    	case WM_IME_SELECT:
    		fprintf(stream, "WM_IME_SELECT");
    		break;
    	case WM_IME_SETCONTEXT:
    		fprintf(stream, "WM_IME_SETCONTEXT");
    		break;
    	case WM_IME_STARTCOMPOSITION:
    		fprintf(stream, "WM_IME_STARTCOMPOSITION");
    		break;
    	case  WM_POWERBROADCAST:
    		fprintf(stream, "WM_POWERBROADCAST");
    		break;
    	case WM_DEVICECHANGE:
    		fprintf(stream, "WM_DEVICECHANGE");
    		break;
    	case WM_MDIACTIVATE:
    		fprintf(stream, "WM_MDIACTIVATE");
    		break;
    	case WM_MDICASCADE:
    		fprintf(stream, "WM_MDICASCADE");
    		break;
    	case WM_MDICREATE:
    		fprintf(stream, "WM_MDICREATE");
    		break;
    	case WM_MDIDESTROY:
    		fprintf(stream, "WM_MDIDESTROY");
    		break;
    	case WM_MDIGETACTIVE:
    		fprintf(stream, "WM_MDIGETACTIVE");
    		break;
    	case WM_MDIICONARRANGE:
    		fprintf(stream, "WM_MDIICONARRANGE");
    		break;
    	case WM_MDIMAXIMIZE:
    		fprintf(stream, "WM_MDIMAXIMIZE");
    		break;
    	case WM_MDINEXT:
    		fprintf(stream, "WM_MDINEXT");
    		break;
    	case WM_MDIREFRESHMENU:
    		fprintf(stream, "WM_MDIREFRESHMENU");
    		break;
    	case WM_MDIRESTORE:
    		fprintf(stream, "WM_MDIRESTORE");
    		break;
    	case WM_MDISETMENU:
    		fprintf(stream, "WM_MDISETMENU");
    		break;
    	case WM_MDITILE:
    		fprintf(stream, "WM_MDITILE");
    		break;
    	case EM_CANUNDO:
    		fprintf(stream, "EM_CANUNDO");
    		break;
    	case EM_CHARFROMPOS:
    		fprintf(stream, "EM_CHARFROMPOS");
    		break;
    	case EM_EMPTYUNDOBUFFER:
    		fprintf(stream, "EM_EMPTYUNDOBUFFER");
    		break;
    	case EM_FMTLINES:
    		fprintf(stream, "EM_FMTLINES");
    		break;
    	case EM_GETFIRSTVISIBLELINE:
    		fprintf(stream, "EM_GETFIRSTVISIBLELINE");
    		break;
    	case EM_GETHANDLE:
    		fprintf(stream, "EM_GETHANDLE");
    		break;
    	//case EM_GETIMESTATUS:
    	//	fprintf(stream, "EM_GETIMESTATUS");
    	//	break;
    	case EM_GETLIMITTEXT:
    		fprintf(stream, "EM_GETLIMITTEXT");
    		break;
    	case EM_GETLINE:
    		fprintf(stream, "EM_GETLINE");
    		break;
    	case EM_GETLINECOUNT:
    		fprintf(stream, "EM_GETLINECOUNT");
    		break;
    	case EM_GETMARGINS:
    		fprintf(stream, "EM_GETMARGINS");
    		break;
    	case EM_GETMODIFY:
    		fprintf(stream, "EM_GETMODIFY");
    		break;
    	case EM_GETPASSWORDCHAR:
    		fprintf(stream, "EM_GETPASSWORDCHAR");
    		break;
    	case EM_GETRECT:
    		fprintf(stream, "EM_GETRECT");
    		break;
    	case EM_GETSEL:
    		fprintf(stream, "EM_GETSEL");
    		break;
    	case EM_GETTHUMB:
    		fprintf(stream, "EM_GETTHUMB");
    		break;
    	case EM_GETWORDBREAKPROC:
    		fprintf(stream, "EM_GETWORDBREAKPROC");
    		break;
    	case EM_LIMITTEXT:
    		fprintf(stream, "EM_LIMITTEXT");
    		break;
    	case EM_LINEFROMCHAR:
    		fprintf(stream, "EM_LINEFROMCHAR");
    		break;
    	case EM_LINEINDEX:
    		fprintf(stream, "EM_LINEINDEX");
    		break;
    	case EM_LINELENGTH:
    		fprintf(stream, "EM_LINELENGTH");
    		break;
    	case EM_LINESCROLL:
    		fprintf(stream, "EM_LINESCROLL");
    		break;
    	case EM_POSFROMCHAR:
    		fprintf(stream, "EM_POSFROMCHAR");
    		break;
    	case EM_REPLACESEL:
    		fprintf(stream, "EM_REPLACESEL");
    		break;
    	case EM_SCROLL:
    		fprintf(stream, "EM_SCROLL");
    		break;
    	case EM_SCROLLCARET:
    		fprintf(stream, "EM_SCROLLCARET");
    		break;
    	case EM_SETHANDLE:
    		fprintf(stream, "EM_SETHANDLE");
    		break;
    	//case EM_SETIMESTATUS:
    	//	fprintf(stream, "EM_SETIMESTATUS");
    	//	break;

    	case EM_SETMARGINS:
    		fprintf(stream, "EM_SETMARGINS");
    		break;
    	case EM_SETMODIFY:
    		fprintf(stream, "EM_SETMODIFY");
    		break;
    	case EM_SETPASSWORDCHAR:
    		fprintf(stream, "EM_SETPASSWORDCHAR");
    		break;
    	case EM_SETREADONLY:
    		fprintf(stream, "EM_SETREADONLY");
    		break;
    	case EM_SETRECT:
    		fprintf(stream, "EM_SETRECT");
    		break;
    	case EM_SETRECTNP:
    		fprintf(stream, "EM_SETRECTNP");
    		break;
    	case EM_SETSEL:
    		fprintf(stream, "EM_SETSEL");
    		break;
    	case EM_SETTABSTOPS:
    		fprintf(stream, "EM_SETTABSTOPS");
    		break;
    	case EM_SETWORDBREAKPROC:
    		fprintf(stream, "EM_SETWORDBREAKPROC");
    	case EM_UNDO:
    		fprintf(stream, "EM_UNDO");
    		break;

    	//case EN_ALIGN_LTR_EC:
    	//	fprintf(stream, "EN_ALIGN_LTR_EC");
    	//	break;
    	//case EN_ALIGN_RTL_EC:
    	//	fprintf(stream, "EN_ALIGN_RTL_EC");
    	//	break;
    	case EN_CHANGE:
    		fprintf(stream, "EN_CHANGE");
    		break;
    	case EN_ERRSPACE:
    		fprintf(stream, "EN_ERRSPACE");
    		break;
    	case EN_HSCROLL:
    		fprintf(stream, "EN_HSCROLL");
    		break;
    	case EN_KILLFOCUS:
    		fprintf(stream, "EN_KILLFOCUS");
    		break;
    	case EN_MAXTEXT:
    		fprintf(stream, "EN_MAXTEXT");
    		break;
    	case EN_SETFOCUS:
    		fprintf(stream, "EN_SETFOCUS");
    		break;
    	case EN_UPDATE:
    		fprintf(stream, "EN_UPDATE");
    		break;
    	case EN_VSCROLL:
    		fprintf(stream, "EN_VSCROLL");
    		break;
    	case WM_COMMAND:
    		fprintf(stream, "WM_COMMAND");
    		break;
    	case WM_COPY:
    		fprintf(stream, "WM_COPY");
    		break;
    	case WM_CTLCOLOREDIT:
    		fprintf(stream, "WM_CTLCOLOREDIT");
    		break;

    	case WM_PASTE:
    		fprintf(stream, "WM_PASTE");
    		break;
    	case WM_UNDO:
    		fprintf(stream, "WM_UNDO");
    		break;

    	case WM_DISPLAYCHANGE:
    		fprintf(stream, "WM_DISPLAYCHANGE");
    		break;
    	case WM_ERASEBKGND:
    		fprintf(stream, "WM_ERASEBKGND");
    		break;
    	case WM_ICONERASEBKGND:
    		fprintf(stream, "WM_ICONERASEBKGND");
    		break;
    	case WM_NCPAINT:
    		fprintf(stream, "WM_NCPAINT");
    		break;
    	case WM_PAINT:
    		fprintf(stream, "WM_PAINT");
    		break;
    	case WM_PAINTICON:
    		fprintf(stream, "WM_PAINTICON");
    		break;
    	case WM_PRINT:
    		fprintf(stream, "WM_PRINT");
    		break;
    	case WM_PRINTCLIENT:
    		fprintf(stream, "WM_PRINTCLIENT");
    		break;
    	case WM_SETREDRAW:
    		fprintf(stream, "WM_SETREDRAW");
    		break;
    	//case WM_SYNCPAIN:
    	//	fprintf(stream, "WM_SYNCPAIN");
    	//	break;

    //	case WM_APPCOMMAND:
    //		fprintf(stream, "WM_APPCOMMAND");
    //		break;
    	case WM_CHAR:
    		fprintf(stream, "WM_CHAR");
    		break;
    	case WM_DEADCHAR:
    		fprintf(stream, "WM_DEADCHAR");
    		break;
    	case WM_GETHOTKEY:
    		fprintf(stream, "WM_GETHOTKEY");
    		break;
    	case WM_HOTKEY:
    		fprintf(stream, "WM_HOTKEY");
    		break;

    	case WM_KEYUP:
    		fprintf(stream, "WM_KEYUP");
    		break;
    	case WM_KILLFOCUS:
    		fprintf(stream, "WM_KILLFOCUS");
    		break;
    	case WM_SETFOCUS:
    		fprintf(stream, "WM_SETFOCUS");
    		break;
    	case WM_SETHOTKEY:
    		fprintf(stream, "WM_SETHOTKEY");
    		break;
    	case WM_SYSCHAR:
    		fprintf(stream, "WM_SYSCHAR");
    		break;
    	case WM_SYSDEADCHAR:
    		fprintf(stream, "WM_SYSDEADCHAR");
    		break;
    	case WM_SYSKEYDOWN:
    		fprintf(stream, "WM_SYSKEYDOWN");
    		break;

    //	case WM_CHANGEUISTATE:
    //		fprintf(stream, "WM_CHANGEUISTATE");
    //		break;
    	case WM_INITMENU:
    		fprintf(stream, "WM_INITMENU");
    		break;
    	case WM_INITMENUPOPUP:
    		fprintf(stream, "WM_INITMENUPOPUP");
    		break;
    	case WM_MENUCHAR:
    		fprintf(stream, "WM_MENUCHAR");
    		break;
    	case WM_MENUSELECT:
    		fprintf(stream, "WM_MENUSELECT");
    		break;
    //	case WM_QUERYUISTATE:
    //		fprintf(stream, "WM_QUERYUISTATE");
    //		break;

    	case WM_SYSCOMMAND :
    		fprintf(stream, "WM_SYSCOMMAND ");
    		break;
    //	case WM_UPDATEUISTAT:
    //		fprintf(stream, "WM_UPDATEUISTAT");
    //		break;

    	case WM_CAPTURECHANGED:
    		fprintf(stream, "WM_CAPTURECHANGED");
    		break;
    	case WM_LBUTTONDBLCLK:
    		fprintf(stream, "WM_LBUTTONDBLCLK");
    		break;
    	case WM_LBUTTONDOWN:
    		fprintf(stream, "WM_LBUTTONDOWN");
    		break;
    	case WM_LBUTTONUP:
    		fprintf(stream, "WM_LBUTTONUP");
    		break;
    	case WM_MBUTTONDBLCLK:
    		fprintf(stream, "WM_MBUTTONDBLCLK");
    		break;
    	case WM_MBUTTONDOWN:
    		fprintf(stream, "WM_MBUTTONDOWN");
    		break;
    	case WM_MBUTTONUP:
    		fprintf(stream, "WM_MBUTTONUP");
    		break;
    	case WM_MOUSEACTIVATE:
    		fprintf(stream, "WM_MOUSEACTIVATE");
    		break;
    	//case WM_MOUSEHOVER:
    	//	fprintf(stream, "WM_MOUSEHOVER");
    	//	break;
    	//case WM_MOUSELEAVE:
    	//	fprintf(stream, "WM_MOUSELEAVE");
    	//	break;

    //	case WM_MOUSEWHEEL:
    //		fprintf(stream, "WM_MOUSEWHEEL");
    //		break;
    	case WM_NCHITTEST:
    		fprintf(stream, "WM_NCHITTEST");
    		break;
    	case WM_NCLBUTTONDBLCLK:
    		fprintf(stream, "WM_NCLBUTTONDBLCLK");
    		break;
    	case WM_NCLBUTTONDOWN:
    		fprintf(stream, "WM_NCLBUTTONDOWN");
    		break;
    	case WM_NCLBUTTONUP:
    		fprintf(stream, "WM_NCLBUTTONUP");
    		break;
    	case WM_NCMBUTTONDBLCLK:
    		fprintf(stream, "WM_NCMBUTTONDBLCLK");
    		break;
    	case WM_NCMBUTTONDOWN:
    		fprintf(stream, "WM_NCMBUTTONDOWN");
    		break;
    	case WM_NCMBUTTONUP:
    		fprintf(stream, "WM_NCMBUTTONUP");
    		break;
    	//case WM_NCMOUSEHOVER:
    //		fprintf(stream, "WM_NCMOUSEHOVER");
    //		break;
    //	case WM_NCMOUSELEAVE:
    //		fprintf(stream, "WM_NCMOUSELEAVE");
    //		break;
    	case WM_NCMOUSEMOVE:
    		fprintf(stream, "WM_NCMOUSEMOVE");
    		break;
    	case WM_NCRBUTTONDBLCLK:
    		fprintf(stream, "WM_NCRBUTTONDBLCLK");
    		break;
    	case WM_NCRBUTTONDOWN:
    		fprintf(stream, "WM_NCRBUTTONDOWN");
    		break;
    	case WM_NCRBUTTONUP:
    		fprintf(stream, "WM_NCRBUTTONUP");
    		break;
    //	case WM_NCXBUTTONDBLCLK:
    //		fprintf(stream, "WM_NCXBUTTONDBLCLK");
    //		break;
    //	case WM_NCXBUTTONDOWN:
    //		fprintf(stream, "WM_NCXBUTTONDOWN");
    //		break;
    //	case WM_NCXBUTTONUP:
    //		fprintf(stream, "WM_NCXBUTTONUP");
    //		break;
    	case WM_RBUTTONDBLCLK:
    		fprintf(stream, "WM_RBUTTONDBLCLK");
    		break;
    	case WM_RBUTTONDOWN:
    		fprintf(stream, "WM_RBUTTONDOWN");
    		break;
    	case WM_RBUTTONUP :
    		fprintf(stream, "WM_RBUTTONUP ");
    		break;
    //	case WM_XBUTTONDBLCLK:
    //		fprintf(stream, "WM_XBUTTONDBLCLK");
    //		break;
    //	case WM_XBUTTONDOWN:
    //		fprintf(stream, "WM_XBUTTONDOWN");
    //		break;
    //	case WM_XBUTTONU:
    //		fprintf(stream, "WM_XBUTTONU");
    //		break;

    	case  WM_SETCURSOR:
    		fprintf(stream, "WM_SETCURSOR");
    		break;

    	default:
    		fprintf(stream, "not listed %d", uMsg);
    		break;
    	}
    	fprintf(stream, "\n");
    	return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    */

    /*
    LRESULT CALLBACK WindowProc
    				(HWND hwnd,      // handle to window
    				UINT uMsg,      // message identifier
    				WPARAM wParam,  // first message parameter
    				LPARAM lParam   // second message parameter
    				)
    {
    	HDC hdc;
    	PAINTSTRUCT ps;
    	RECT rect;
    	HBRUSH hbrush, oldBrush;
    	char buf[80];
    	COLORREF color;//=RGB(255, 0, 0);
    	switch (uMsg)
    	{
    	case WM_PAINT:
    		hdc=BeginPaint(hwnd, &ps);

    		//color=RGB(count++, 0, 0);
    		hbrush=CreateSolidBrush(color);
    		oldBrush=(HBRUSH)SelectObject(hdc, hbrush);
    		GetClientRect(hwnd, &rect);

    		//SetBrushOrgEx(hdc, 10, 10, NULL);
    		PatBlt(hdc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, PATINVERT);
    		SelectObject(hdc, oldBrush);

    		sprintf(buf, "hello world!");
    		TextOut(hdc, 100, 100, buf, strlen(buf));
    		EndPaint(hwnd, &ps);
    		return 0L;
    		break;

    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0L;
    		break;
    	case  WM_MOUSEACTIVATE:
    		return MA_ACTIVATEANDEAT;
    		break;
    	//default:
    	//	return DefWindowProc(hwnd, uMsg, wParam, lParam);
    	//	break;

    	case WM_NCCREATE:
    		return TRUE;
    		break;
    	case WM_CREATE:
    		return 0;
    		break;

    	case WM_NCACTIVATE:
    		if (!wParam)
    		{
    			hdc = GetDC(hwnd);
    			sprintf(buf, "WM_NCACTIVATE");
    			TextOut(hdc, 100, 180, buf, strlen(buf));
    			// Paint into this DC
    			ReleaseDC(hwnd, hdc);
    			return TRUE;
    		}
    		else
    		{
    			return FALSE;
    		}
    		break;
    	case WM_ERASEBKGND:
    		if (wParam!=NULL)
    		{
    			hdc=(HDC)wParam;
    			color=RGB(count++, 0, 0);
    			hbrush=CreateSolidBrush(color);
    			oldBrush=(HBRUSH)SelectObject(hdc, hbrush);
    			GetClientRect(hwnd, &rect);

    			//SetBrushOrgEx(hdc, 10, 10, NULL);
    			PatBlt(hdc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, PATINVERT);
    			SelectObject(hdc, oldBrush);

    		}
    		return 1L;
    		break;

    	}
    	return 0L;
    }
    */

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
    				   int nShowCmd)
    {
    	char szWinApp[]="szMyWinClass";

    	stream=fopen("mylog.txt", "w");
    	//fprintf(stream, "message begins:\n");

    	HWND hwnd;
    	MSG msg;

    	if (!hPrevInstance)
    	{
    		nWinWidth=GetSystemMetrics(SM_CXSCREEN)/2;
    		nWinHeight=GetSystemMetrics(SM_CYSCREEN)/2;

    		memset(&wndClass, 0, sizeof(WNDCLASS));

    		wndClass.lpszClassName=szWinApp;
    		wndClass.style=CS_HREDRAW|CS_VREDRAW;
    		wndClass.hInstance=hInstance;
    		wndClass.lpfnWndProc=WindowProc;
    		wndClass.cbClsExtra=wndClass.cbWndExtra=0;
    		wndClass.hIcon=LoadIcon(NULL, IDI_APPLICATION);
    		wndClass.hCursor=LoadCursor(NULL, IDC_ARROW);
    		wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    		wndClass.lpszMenuName=NULL;

    		if (!RegisterClass(&wndClass))
    		{
    			int err=GetLastError();
    			return FALSE;
    		}

    	}

    	hwnd=CreateWindow(szWinApp, "My Window Test",
    		WS_OVERLAPPEDWINDOW|WS_VISIBLE, 0, 0,
    		nWinWidth, nWinHeight, NULL, NULL, hInstance, NULL);
    	if (!hwnd)
    	{
    		int err=GetLastError();
    		return FALSE;

    	}
    	ShowWindow(hwnd, nShowCmd);
    	UpdateWindow(hwnd);

    	while (GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	fclose(stream);
    	return msg.wParam;
    }

    ¡¡

¡¡

¡¡