?? dllextend.cpp
字號:
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <commctrl.h>
#include "DllExtend.h"
#include "ALlib.h"
BOOL WINAPI DllMain(HINSTANCE hinstDll,DWORD fdwReason,LPVOID)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
g_hinstDll=hinstDll;
texthwnd=FindWindow("Notepad",NULL);
Eid=GetWindowThreadProcessId(texthwnd,NULL);
lpfnOld = SubclassWindow(texthwnd, textWndProc);
SendMessage(texthwnd,WM_NOTEPAD,0,0);
//測試點
//ALbox(NULL,"測試所屬進程");
}
break;
}
return(TRUE);
}
extern "C" __declspec(dllexport) BOOL SetHook(void)
{
gHook=SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hinstDll,Eid);
return TRUE;
}
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(gHook,nCode,wParam,lParam);
}
LRESULT CALLBACK textWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HWND hEdits;
static BOOL bl = TRUE;
static BOOL Boolbar = TRUE;
static COLORREF textcolor = 0xff0000;
static COLORREF colors = 0xc8ffff;
int pPartsWidth[3];
RECT crect;
RECT wrect;
HICON abxp,ab98;
static BOOL ass = TRUE;
long n,i,j;
LPSTR Filenzme;
switch(message)
{
case WM_NOTEPAD:
{
char str[20];
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
wsprintf(str,"%d.%d",osvi.dwMajorVersion,osvi.dwMinorVersion);
winver = atof(str);
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
hMainmenu = GetMenu(texthwnd);
hSubMenu1 = GetSubMenu(hMainmenu,3);
hSubMenu2 = LoadMenu(g_hinstDll,"SUBMenu");
if(winver <=5.00)
{
hwndStatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE|WS_BORDER,NULL,texthwnd,NULL);
SetTimer(hwnd,1,200,NULL);
hSubMenu1 = LoadMenu(g_hinstDll,"MyMenu");
InsertMenu(hMainmenu,(long)3,MF_STRING|MF_POPUP|MF_BYPOSITION,(long)hSubMenu1,(LPCTSTR)"查看(&V)");
InsertMenu(hSubMenu1,(long)4,MF_STRING|MF_POPUP|MF_BYPOSITION,(long)hSubMenu2,(LPCTSTR)"顏色(&C)");
CheckMenuItem(hSubMenu1,IDE_Statusbar,MF_CHECKED);
}
else
{
InsertMenu(hSubMenu1,(long)1,MF_STRING|MF_POPUP|MF_BYPOSITION,(long)IDE_SIZES,(LPCTSTR)"字數統計(&W)...");
InsertMenu(hSubMenu1,(long)2,MF_STRING|MF_POPUP|MF_BYPOSITION,(long)IDE_TABS,(LPCTSTR)"制表位(&T)...");
InsertMenu(hSubMenu1,(long)3,MF_SEPARATOR,0,0);
InsertMenu(hSubMenu1,(long)4,MF_STRING|MF_POPUP|MF_BYPOSITION,(long)hSubMenu2,(LPCTSTR)"顏色(&C)");
}
DrawMenuBar(texthwnd);
SetForegroundWindow(texthwnd);
hBrush = CreateSolidBrush(0xC8FFFF);
UnhookWindowsHookEx(gHook);
}
break;
case WM_TIMER:
if(winver<=5.00)
{
hEdits = GetFocus();
if(GetWindowLong(hEdits,GWL_ID) == 15)
{
i = SendMessage(hEdits,EM_LINEFROMCHAR,-1,0);
wsprintf(szBufh,"行號:%d",i+1);
SendMessage(hwndStatusbar,SB_SETTEXT,1,(LPARAM)(LPSTR)&szBufh);
j = SendMessage(hEdits,EM_LINEINDEX,-1,0);
SendMessage(hEdits,EM_GETSEL,(int)&n,NULL);
n = n-j;
wsprintf(szBufh,"列號:%d",n);
SendMessage(hwndStatusbar,SB_SETTEXT,2,(LPARAM)(LPSTR)&szBufh);
}
}
break;
case WM_CTLCOLOREDIT:
if(bl)
{
SetBkColor((HDC)wParam,colors);
SetTextColor((HDC)wParam,textcolor);
return (long)hBrush;
}
break;
case WM_SIZE:
if(winver<=5.00)
{
MoveWindow(hwndStatusbar,
0,
0,
LOWORD(lParam),
HIWORD(lParam),
TRUE);
GetClientRect(hwndStatusbar,&crect);
pPartsWidth[0]=crect.right-170;
pPartsWidth[1]=crect.right-90;
pPartsWidth[2]=crect.right;
SendMessage(hwndStatusbar,SB_SETPARTS,3,(LPARAM)pPartsWidth);
}
break;
case WM_PAINT:
{
if(winver<=5.00)
{
hEdits = GetFocus();
if(GetWindowLong(hEdits,GWL_ID) == 15)
{
GetWindowRect(hwndStatusbar,&wrect);
GetClientRect(texthwnd,&crect);
if(Reginfo()==0)
{
if(Boolbar)
{
ShowWindow(hwndStatusbar,SW_SHOW);
MoveWindow(hEdits,0,0,crect.right,(crect.bottom-(wrect.bottom-wrect.top)),TRUE);
EnableMenuItem(hSubMenu1,IDE_Statusbar,FALSE);
}
else
{
MoveWindow(hEdits,0,0,crect.right,crect.bottom,TRUE);
ShowWindow(hwndStatusbar,SW_HIDE);
EnableMenuItem(hSubMenu1,IDE_Statusbar,FALSE);
}
}
else
{
MoveWindow(hEdits,0,0,crect.right,crect.bottom,TRUE);
ShowWindow(hwndStatusbar,SW_HIDE);
EnableMenuItem(hSubMenu1,IDE_Statusbar,TRUE);
}
}
}
hEdits = GetFocus();
SendMessage(hEdits,EM_SETTABSTOPS,(WPARAM)1,(LPARAM)(LPDWORD)&l);
InvalidateRect(hwnd,NULL,TRUE);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDE_Statusbar:
if(Boolbar)
{
CheckMenuItem(hSubMenu1,IDE_Statusbar,MF_UNCHECKED);
InvalidateRect(hwnd,NULL,TRUE);
Boolbar=FALSE;
}
else
{
CheckMenuItem(hSubMenu1,IDE_Statusbar,MF_CHECKED);
InvalidateRect(hwnd,NULL,TRUE);
Boolbar=TRUE;
}
break;
case IDE_SIZES:
hEdits = GetFocus();
Filenzme = GetEditText(hEdits);
GetTextSize(Filenzme);
DelTmpFile(Filenzme);
break;
case IDE_TABS:
DialogBoxParam(g_hinstDll,"TABSIZE",texthwnd,(DLGPROC)TabProc,NULL);
break;
case IDE_GCOLOR:
bl = TRUE;
colors = 0x00808000;
textcolor = 0x0080ffff;
hBrush = CreateSolidBrush(colors);
EnableMenuItem(hSubMenu2,IDE_BCOLOR,FALSE);
EnableMenuItem(hSubMenu2,IDE_WCOLOR,FALSE);
EnableMenuItem(hSubMenu2,IDE_GCOLOR,TRUE);
InvalidateRect(hwnd,NULL,TRUE);
break;
case IDE_BCOLOR:
bl = TRUE;
colors = 0xc8ffff;
textcolor = 0xff0000;
hBrush = CreateSolidBrush(colors);
EnableMenuItem(hSubMenu2,IDE_BCOLOR,TRUE);
EnableMenuItem(hSubMenu2,IDE_WCOLOR,FALSE);
EnableMenuItem(hSubMenu2,IDE_GCOLOR,FALSE);
InvalidateRect(hwnd,NULL,TRUE);
break;
case IDE_WCOLOR:
bl = FALSE;
EnableMenuItem(hSubMenu2,IDE_BCOLOR,FALSE);
EnableMenuItem(hSubMenu2,IDE_WCOLOR,TRUE);
EnableMenuItem(hSubMenu2,IDE_GCOLOR,FALSE);
InvalidateRect(hwnd,NULL,TRUE);
break;
case 65:
abxp = LoadIcon(g_hinstDll,"Iconxp");
ShellAbout(hwnd,"記事本","\n功能擴展: ALAL 工作室",abxp);
return TRUE;
case 11:
ab98 = LoadIcon(g_hinstDll,"Icon98");
ShellAbout(hwnd,"記事本","\n功能擴展: ALAL 工作室",ab98);
return TRUE;
}
break;
case WM_DESTROY:
KillTimer(hwnd,1);
PostQuitMessage(0);
break;
}
return CallWindowProc(lpfnOld,hwnd,message,wParam,lParam);
}
LRESULT CALLBACK TabProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
{
RECT rcDlg,rcEdit;
int cxDlg,cyDlg;
GetWindowRect(hDlg,&rcDlg);
GetWindowRect(texthwnd,&rcEdit);
cxDlg = rcDlg.right - rcDlg.left;
cyDlg = rcDlg.bottom - rcDlg.top;
SetWindowPos(hDlg,
HWND_TOP,
((rcEdit.right)+(rcEdit.left))/2-(cxDlg)/2,
((rcEdit.bottom)+(rcEdit.top))/2-(cyDlg)/2,
0,0,
SWP_NOSIZE);
SetDlgItemText(hDlg,IDC_EDIT1,"16");
}
return(TRUE);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
l = GetDlgItemInt(hDlg,IDC_EDIT1,NULL,FALSE);
InvalidateRect(texthwnd,NULL,TRUE);
EndDialog(hDlg,TRUE);
break;
case IDC_BUTTON2:
EndDialog(hDlg,TRUE);
break;
}
break;
case WM_CLOSE:
EndDialog(hDlg,TRUE);
break;
}
return(FALSE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -