#include <windows.h>
#define BUTTON1 1
#define BUTTON2 2
WNDPROC lpfnOldWndProc;
HWND hWnd;
HWND SuperClassedButtonButton,normalButton ;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) ;
LRESULT CALLBACK SuperClassedButton(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) ;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProc;
WndClsEx.cbClsExtra = NULL;
WndClsEx.cbWndExtra = NULL;
WndClsEx.hInstance = hInstance;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = "WndMsg";
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClsEx);
hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "WndMsg", "SuperClass Example", WS_OVERLAPPEDWINDOW, 10, 10, 240, 140, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
normalButton = CreateWindow(TEXT("button"), TEXT("Normal"),WS_CHILD|WS_VISIBLE, 10, 10, 100, 80,hWnd, (HMENU) BUTTON1, NULL, NULL);
//create superclassed button//
WNDCLASSEX wndinfo;
GetClassInfoEx(0,"button",&wndinfo);
wndinfo.hInstance = (HINSTANCE) GetModuleHandle(NULL);
wndinfo.lpszClassName="suspercls";
wndinfo.cbSize=sizeof(WNDCLASSEX) ;
lpfnOldWndProc=wndinfo.lpfnWndProc;
wndinfo.lpfnWndProc=SuperClassedButton;
RegisterClassEx(&wndinfo);
SuperClassedButtonButton = CreateWindow(TEXT("suspercls"), TEXT("Super"),WS_CHILD|WS_VISIBLE, 120, 10, 100, 80,hWnd, (HMENU) BUTTON2, NULL, NULL);
////////////////////////////
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg); }
return Msg.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case BUTTON1:
MessageBeep(MB_ICONEXCLAMATION);
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//Superclassed button proceedure//
LRESULT CALLBACK SuperClassedButton(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_LBUTTONUP:
MessageBeep(MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
}
return CallWindowProc(lpfnOldWndProc, hWnd, Msg, wParam, lParam);
}