#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include <conio.h>
#define ID_Edit 1000
HINSTANCE hInstDLL;
static HINSTANCE hInst;
WNDPROC wpOrigEditProc;
static HANDLE Form1;
static HANDLE hEdit;
extern int asc (char *);
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL WINAPI __declspec(dllexport) LibMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInstDLL = hDLLInst;
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
HINSTANCE APIENTRY __declspec(dllexport)
CreateEdit(HINSTANCE hInstance, HANDLE Form )
{
hInst = hInstance;
Form1 = Form;
hEdit=CreateWindow(
"edit",
"Edit will only accept numbers ",
WS_CHILD|WS_VISIBLE|WS_BORDER,
1,1,300,30,
Form1,
(HMENU)ID_Edit,
hInstDLL,
NULL);
wpOrigEditProc = (WNDPROC) SetWindowLong(hEdit, GWL_WNDPROC, (LONG) EditSubclassProc);
return hEdit;
}
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CHAR) {
if((wParam<asc("0")||wParam>asc("9"))) {
return 0;}
return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
}
if(uMsg==WM_DESTROY) {
SetWindowLong(hEdit, GWL_WNDPROC, (LONG) wpOrigEditProc);
return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
}
return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam);
}
extern int asc (char *z)
{
static int q;
q = 0;
memmove(&q,z,1);
return q;
}
|