본문 바로가기
IT-개발,DB

[VC++] SubClassing 하는 방법

by SB리치퍼슨 2011. 1. 18.

VC++ Source Code
// Subclassing.cpp : Defines the entry point for the application.
// #include "stdafx.h"#include <tchar.h>
#define STRSAFE_NO_DEPRECATE
WNDPROC g_pOldProc;
char szAppName[]="Subclassing Demo";
LRESULT CALLBACK SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{  
 if(uMsg == WM_CLOSE)   
 {       
  DestroyWindow(hWnd);       
  PostQuitMessage(0);       
  return 0;   
 }   
 return CallWindowProc(g_pOldProc, hWnd, uMsg, wParam, lParam);

int APIENTRY _tWinMain(HINSTANCE hInstance,                    
 HINSTANCE hPrevInstance,                    
 LPSTR     lpCmdLine,                    
 int       nCmdShow)
{   
 HWND hEdit = 0;       
 /*Create a top-level edit control*/   
 hEdit = CreateWindowEx(                0,
   _T("EDIT"), _T(szAppName),               
   WS_OVERLAPPEDWINDOW,                
   CW_USEDEFAULT,                
   CW_USEDEFAULT,                
   200,                
   100,                
   0,                
   0,                
   hInstance,                
   0);       
 g_pOldProc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, PtrToLong(SubclassProc));    
 ShowWindow(hEdit, SW_SHOWNORMAL);    
 
 MSG msg;   
 
 while(GetMessage(&msg, 0, 0, 0))   
 {       
  TranslateMessage(&msg);       
  DispatchMessage(&msg);   
 }   
 
 return 0;
}

반응형

댓글