1. 程式人生 > >Windows核心程式設計_Edit操作

Windows核心程式設計_Edit操作

今天午飯時間無聊,順手寫了幾個對Edit控制元件操作的函式,都是訊息處理,有需要的可以拿去學習,非常簡單

//EDIT操作
//寫
void settxt(HWND hwnd,char* str) {
	SendMessage(hwnd, 12, 0, (LPARAM)str);
}
//讀
char *gettxt(HWND hwnd) {
	char str[1024] = {0};
	SendMessage(hwnd, WM_GETTEXT, 10, (LPARAM)str);
	return str;
}
//取密碼框EDIT文字
char* GetPOsTxt(HWND hwnd) {
	int Pos = SendMessage(hwnd, 210, 0, 0);	//得到掩蓋符程式碼
	char str[1024] = { 0 };
	if (Pos != 0) {
		PostMessage(hwnd, 204, 0, 0);//去掉密碼屬性//介面訊息優先順序不要使用send
	//獲取密碼文字
		strcpy(str,gettxt(hwnd));	//copy
	}
	//恢復密碼屬性
	PostMessage(hwnd, 204, Pos, 0);
	return str;
}
//刪除密碼EDIT屬性
void DeleteEditPos(HWND hwnd) {
	PostMessage(hwnd, 204, 0, 0);//去掉密碼屬性//介面訊息優先順序不要使用send
}
//設定密碼屬性
void SetEditPos(HWND hwnd) {
	PostMessage(hwnd, 204, 1, 0);//去掉密碼屬性//介面訊息優先順序不要使用send
}
//獲取Edit文字長度位元組為單位
int GetEditSize(HWND hwnd) {
	return SendMessage(hwnd, 14, 0, 0);
}
//設定Edit文字最大長度
void SetEditSize(HWND hwnd,int size/*位元組長度*/) {
	SendMessage(hwnd, 197, size, 0);
}
//設定Edit只讀
void SetEditRead(HWND hwnd) {
	SendMessage(hwnd, 207, 1, 0);
}
//設定Edit預設讀寫
void SetEditWR(HWND hwnd) {
	SendMessage(hwnd, 207, 0, 0);
}
//取Edit指定行的內容
char* GetEditLi(HWND hwnd,int L) {
	char str[1024] = { 0 };
	SendMessage(hwnd, 196, L - 1, (LPARAM)str);
	return str;
}
//取Edit指定行的內容長度
int GetEditLiSize(HWND hwnd,int L) {
	return SendMessage(hwnd, 193, SendMessage(hwnd, 187, L, 0), 0);
}
//將Edit內容清空,不會清空快取區
void DeleteEditTxt(HWND hwnd) {
	settxt(hwnd, "");
}
//清空Edit快取區
void DeleteEdit(HWND hwnd) {
	SendMessage(hwnd, EM_CANUNDO, 0, 0);
}
//Edit游標處插入文字
void SetEditMoveTxt(HWND hwnd, char *str) {
	SendMessage(hwnd, 194, 1, (LPARAM)str);
}
//判斷Edit內容是否在一開始時發生過改變
BOOL GetEditBool(HWND hwnd) {
	return SendMessage(hwnd, 184, 0, 0);
}
//獲取Edit行號
int GetEditLSize_A(HWND hwnd) {
	return SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
}
//設定Edit起始選擇位置
void SetEditMove(HWND hwnd,int Move) {
	SendMessage(hwnd, 177, Move, Move);
}
//滾動Edit滾動條到指定行
void GunEdit(HWND hwnd, signed int L/*正的往下滾,負數往上滾*/) {
	if (L > 0) {
		SendMessage(hwnd, 182, 1, L);
	}
	else {
		SendMessage(hwnd, 182, 0, L);
	}
}
//將Edit變成IE地址輸入框,只能檢索IE地址歷史記錄
#include "Shlwapi.h"
#pragma comment (lib,"Shlwapi.lib")
void SetEditAndIE(HWND hwnd) {
	SHAutoComplete(hwnd, 0);
}