//プロジェクト名edit001 C++ソースファイルedit001.cpp #include extern "C" { __declspec(dllexport) long openedit(int y1,int x1,int y2,int x2); __declspec(dllexport) long openeditf(long hnd1,int y1,int x1,int y2,int x2); __declspec(dllexport) void seteditfont( long hWnd01, char * string01,int th,int r,int g,int b); __declspec(dllexport) void setedittext( long hWnd01, char * string01); __declspec(dllexport) char * getedittext( long hWnd01, char * buf01); __declspec(dllexport) void closeedit( long hWnd01, int tr, int tg, int tb); __declspec(dllexport) void noborder( void); __declspec(dllexport) void nomenu( void); __declspec(dllexport) void seticon01(char * string01,char * string02); static int x01=0; static int y01=0; static int x02=0; static int y02=0; static int row01=0; static int r01=0; static int g01=0; static int b01=0; static RECT rctA; static LONG pWnd01=0; static LONG pWnd1=0; HWND hWnd0; HWND hWnd1; HFONT hFont; HBRUSH hbrEdit1 = CreateSolidBrush(RGB(255,255,255)); LRESULT CALLBACK border01(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam); LRESULT CALLBACK border1(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam); LRESULT CALLBACK border2(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam); LRESULT CALLBACK border01(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) { if(msg==WM_SETFOCUS || msg==WM_MOUSEMOVE) { SendMessage( hWnd1 , WM_PAINT, 0, 0); } if(msg==WM_PAINT) { rctA.left = x01; rctA.top = y01; rctA.right = x01+x02; rctA.bottom = y01+y02; int row02 = SendMessage( hWnd , EM_GETLINECOUNT, 0, 0); if(row01!=row02) { InvalidateRect( hWnd1 , &rctA , TRUE ); SendMessage( hWnd1 , WM_PAINT, 0, 0); row01=row02; } } return CallWindowProc((WNDPROC)pWnd01,hWnd,msg,wparam,lparam); } LRESULT CALLBACK border1(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) { if(msg==WM_PAINT || msg==WM_SETFOCUS || WM_CHILDACTIVATE || msg==WM_MOUSEMOVE) { HDC hDC; HPEN hPen; hDC = GetDC( hWnd ); hPen = CreatePen( PS_SOLID, 1, RGB(170,170,170) ); SelectObject( hDC, hPen ); SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle( hDC, x01-1, y01-1, x01+x02+1, y01+y02+1 ); DeleteObject( hPen ); ReleaseDC( hWnd , hDC ); } if(msg==WM_CTLCOLOREDIT && (HWND)lparam==hWnd0) { SetTextColor((HDC)wparam, RGB( r01, g01, b01)); } return CallWindowProc((WNDPROC)pWnd1,hWnd,msg,wparam,lparam); } LRESULT CALLBACK border2(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) { if(msg==WM_PAINT || msg==WM_SETFOCUS || WM_CHILDACTIVATE || msg==WM_MOUSEMOVE) { HDC hDC; HPEN hPen; hDC = GetDC( hWnd ); hPen = CreatePen( PS_SOLID, 1, RGB(170,170,170) ); SelectObject( hDC, hPen ); SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle( hDC, x01-1, y01-1, x01+x02+1, y01+y02+1 ); DeleteObject( hPen ); ReleaseDC( hWnd , hDC ); } if(msg==WM_CTLCOLOREDIT && (HWND)lparam==hWnd0) { SetTextColor((HDC)wparam, RGB( r01, g01, b01)); return (LRESULT)hbrEdit1; } return CallWindowProc((WNDPROC)pWnd1,hWnd,msg,wparam,lparam); } void noborder( void) { HWND hWnd2=GetParent( hWnd1 ); HWND hWnd3=GetParent( hWnd2 ); HWND hWnd4=GetParent( hWnd3 ); SetWindowLong( hWnd1, GWL_EXSTYLE, NULL ); long temp=GetWindowLong(hWnd1, GWL_STYLE); temp=(temp ^ WS_SYSMENU); temp=(temp ^ WS_CAPTION); temp=(temp ^ WS_BORDER); temp=(temp ^ WS_DLGFRAME); SetWindowLong( hWnd2, GWL_STYLE, temp ); SetWindowLong( hWnd3, GWL_EXSTYLE, NULL ); RECT rc; GetWindowRect( hWnd4, (LPRECT)&rc); int x=(rc.right-rc.left); int y=(rc.bottom-rc.top); SetWindowPos( hWnd4, HWND_TOP, 0, 0, x-1, y-1, SWP_NOMOVE); SetWindowPos( hWnd4, HWND_TOP, 0, 0, x, y, SWP_NOMOVE); return; } void nomenu( void) { HWND hWnd2=GetParent( hWnd1 ); HWND hWnd3=GetParent( hWnd2 ); HWND hWnd4=GetParent( hWnd3 ); SetMenu( hWnd4 , NULL ); return; } long openedit(int y1,int x1,int y2,int x2) { x01=x1; y01=y1; x02=x2; y02=y2; HWND hWnd00=GetFocus(); hWnd1=GetParent( hWnd00 ); HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd1,GWL_HINSTANCE); HWND hWnd01=CreateWindow(TEXT("EDIT") , NULL ,WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL |ES_LEFT | ES_MULTILINE ,x1 , y1 , x2 , y2 , hWnd1 , (HMENU)178 ,hInst , NULL); LONG pWnd1b=GetWindowLong(hWnd01,GWL_WNDPROC); if(pWnd1b != (long)border01) pWnd01=pWnd1b; SetWindowLong(hWnd01, GWL_WNDPROC, (long)border01); pWnd1b=GetWindowLong(hWnd1,GWL_WNDPROC); if(pWnd1b != (long)border1) pWnd1=pWnd1b; SetWindowLong(hWnd1, GWL_WNDPROC, (long)border1); SetFocus(hWnd01); return (long)hWnd01; } long openeditf(long hnd1,int y1,int x1,int y2,int x2) { x01=x1; y01=y1; x02=x2; y02=y2; hWnd1=(HWND)hnd1; HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd1,GWL_HINSTANCE); HWND hWnd01=CreateWindow(TEXT("EDIT") , NULL ,WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL |ES_LEFT | ES_MULTILINE ,x1 , y1 , x2 , y2 , hWnd1 , (HMENU)178 ,hInst , NULL); LONG pWnd1b=GetWindowLong(hWnd01,GWL_WNDPROC); if(pWnd1b != (long)border01) pWnd01=pWnd1b; SetWindowLong(hWnd01, GWL_WNDPROC, (long)border01); pWnd1b=GetWindowLong(hWnd1,GWL_WNDPROC); if(pWnd1b != (long)border2) pWnd1=pWnd1b; SetWindowLong(hWnd1, GWL_WNDPROC, (long)border2); SetFocus(hWnd01); return (long)hWnd01; } void seteditfont( long hWnd01, char * string01,int th,int r,int g,int b) { hWnd0=(HWND)hWnd01; r01=r; g01=g; b01=b; HDC hdc = GetDC( (HWND)hWnd01 ); int nHeight = -MulDiv ( th, GetDeviceCaps (hdc, LOGPIXELSY), 72); ReleaseDC( (HWND)hWnd01 , hdc ); int bold01 = 400; hFont = CreateFont( nHeight, 0, 0, 0, bold01, 0, 0, 0, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_MODERN, string01); SendMessage( (HWND)hWnd01, WM_SETFONT, (WPARAM)hFont, MAKELPARAM( TRUE, 0)); return; } void setedittext( long hWnd01, char * string01) { row01 = SendMessage( (HWND)hWnd01 , EM_GETLINECOUNT, 0, 0); SetWindowText( (HWND)hWnd01 , string01 ); } char * getedittext( long hWnd01, char * buf01) { int len01=strlen(buf01); int len02=GetWindowTextLength( (HWND)hWnd01); char * param = (char *)calloc(1,len02 + 2); if (param != NULL) { int n=GetWindowText( (HWND)hWnd01, param, len02+1); if (len01>(n+1)) { memcpy(buf01,param,n+1); } else { * buf01='\0'; } free(param); } else { * buf01='\0'; } return buf01; } void closeedit( long hWnd01, int tr, int tg, int tb) { HDC hDC; HPEN hPen; hDC = GetDC( hWnd1 ); hPen = CreatePen( PS_SOLID, 1, RGB( tr, tg, tb) ); SelectObject( hDC, hPen ); SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle( hDC, x01-1, y01-1, x01+x02+1, y01+y02+1 ); DeleteObject( hPen ); ReleaseDC( hWnd1 , hDC ); DestroyWindow( (HWND)hWnd01); return; } void seticon01(char * string01,char * string02) { HICON hIcon; HWND hWnd2=GetParent( hWnd1 ); HWND hWnd3=GetParent( hWnd2 ); HWND hWnd4=GetParent( hWnd3 ); if ( * string01 != NULL) { hIcon = ExtractIcon( NULL, string01, 0); if(hIcon) { SendMessage(hWnd4, WM_SETICON, ICON_SMALL, (long)hIcon); } } // DestroyIcon( hIcon); if ( * string02 != NULL) { SetWindowText( hWnd4, string02); } } }