ここまでの成果
#include <string>
#include <list>
#include <windows>
#include <stdio>
using namespace std;
POINT pt;
HWND hListbox = NULL;
HWND hHidemaruWindow = NULL;
list<string> baselist;//元々の候補
list<string> visiblelist;//実際に表示するリスト
string returnstring;
extern "C" __declspec(dllexport)
BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD ul_reason_for_call, LPVOID pParam)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return true;
}
extern "C" __declspec(dllexport)
int appendToBaseListFromFile(const char* filename)
{
// リストに項目をファイルから読み出して、追加する(一行一項目)
FILE* filelib;
string tempstr;
if ((filelib = fopen(filename, "r")) == NULL) {
return false;
}
char buff[1000];
while(fgets(buff, 1000, filelib) != NULL){
tempstr = buff;
tempstr.erase(tempstr.size()-1,2);
if(tempstr != ""){
baselist.push_back(tempstr);
}
}
fclose(filelib);
if(baselist.size() == 0)return false;
return true;
}
extern "C" __declspec(dllexport)
int appendToBaseList(const char* item)
{
// リストに項目を追加する
baselist.push_back(string(item));
return true;
}
extern "C" __declspec(dllexport)
int clearBaseList()
{
// リストをクリアする
baselist.clear();
return true;
}
extern "C" __declspec(dllexport)
int uniqueBaseList()
{
// リストから重複を取り除く
baselist.unique();
return true;
}
////////////////////////////////////////////////////////////////////////
// 以下リストボックス本体
////////////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport)
int showListBox(const char* str)
{
if(hListbox == NULL)return false;
if(baselist.empty())return false;
string firststring;
firststring = str;
list<string>::iterator ite;
visiblelist = baselist;
if(firststring != ""){
int len = firststring.size();
for(ite=visiblelist.begin();ite!=visiblelist.end();){
if(firststring != (*ite).substr(0,len)){
ite = visiblelist.erase(ite);
}else{
ite++;
}
}
}
//リストを一旦クリアする
SendMessage(hListbox , LB_RESETCONTENT,0,0);
if(!visiblelist.empty()){ //追加すべき項目がある場合のみ追加
for(ite = visiblelist.begin();ite!=visiblelist.end();ite++){
SendMessage(hListbox , LB_ADDSTRING,0,(LPARAM)(*ite).c_str());
}
//一番最初のを選択する
SendMessage(hListbox , LB_SETCURSEL,0,0);
}
ShowWindow(hListbox , SW_SHOW);
return true;
}
extern "C" __declspec(dllexport)
int createListBox(int hHideWnd , int fontsize)
{
hHidemaruWindow = HWND(hHideWnd);
GetCaretPos(&pt);
hListbox=CreateWindow("LISTBOX","",
WS_CHILD|WS_BORDER|WS_VSCROLL|LBS_NOTIFY|LBS_WANTKEYBOARDINPUT,
pt.x,pt.y+fontsize,400,100,
hHidemaruWindow,
NULL,
(HINSTANCE)GetWindowLong(hHidemaruWindow , GWL_HINSTANCE),
NULL);
if(hListbox == NULL) return false;
return true;
}
extern "C" __declspec(dllexport)
int delListBox()
{
DestroyWindow(hListbox);
return true;
}
extern "C" __declspec(dllexport)
int upListBox()
{
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
if(nowpos > 0)SendMessage(hListbox , LB_SETCURSEL,nowpos-1,0);
return true;
}
extern "C" __declspec(dllexport)
int downListBox()
{
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
int max = SendMessage(hListbox , LB_GETCOUNT,0,0);
if(nowpos < max)SendMessage(hListbox , LB_SETCURSEL,nowpos+1,0);
return true;
}
extern "C" __declspec(dllexport)
int getItemCount()
{
return SendMessage(hListbox , LB_GETCOUNT,0,0);
}
extern "C" __declspec(dllexport)
const char* getSelectString()
{
if(hListbox == NULL) return (const char*)"";
if (SendMessage(hListbox , LB_GETCOUNT,0,0) <= 0) return (const char*)"";
char* ret;
SendMessage(hListbox ,
LB_GETTEXT ,
SendMessage(hListbox , LB_GETCURSEL,0,0) ,
(LPARAM)ret);
returnstring = ret;
return returnstring.c_str();
}
マクロ
loaddll currentmacrodirectory + "\\listbox.dll";
//項目に追加する
$dic = currentmacrodirectory + "\\dic\\StringTuner.dic";
#ret = dllfunc("appendToBaseListFromFile" , $dic );
//リストボックスを作成する
#ret = dllfunc("createListBox",hidemaruhandle(0) , fontsize);
#ret = dllfunc("showListBox" , "");
while(true){
#c = inputchar("何か押してよ");
if(#c == 0x1C)left;
else if(#c == 0x1D)#ret = dllfunc("upListBox");
else if(#c == 0x1E)right;
else if(#c == 0x1F)#ret = dllfunc("downListBox");
else if(#c == 0x0D)message dllfuncstr("getSelectString");
else break;
}
#ret = dllfunc("delListBox");
freedll;
endmacro;
おお、プロトタイプになってる気がしてきた
#include <
string>
#include <
list>
#include <windows>
#include <stdio>
using namespace std;
HWND hListbox =
NULL;
HWND hHidemaruWindow =
NULL;
WNDPROC baseProc;
list<
string> baselist;
list<
string> visiblelist;
string returnstring;
~途中省略~
内容は前回と一緒
~途中省略~
extern "C" __declspec(dllexport)
int sortBaseList()
{
baselist.sort();
return true;
}
LRESULT CALLBACK NewProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp)
{
int ypos , newpos , max , height , i;
switch(msg) {
case WM_LBUTTONDOWN:
ypos = (lp >> 16) & 0xFFFF;
max = SendMessage(hListbox , LB_GETCOUNT,0,0)-1;
newpos = SendMessage(hListbox , LB_GETTOPINDEX,0,0);
height = SendMessage(hListbox , LB_GETITEMHEIGHT,0,0);
i=0;
while(ypos >= 0){
i++;
ypos = ypos - height;
}
newpos = newpos + i -1;
if(newpos > max) newpos = max;
SendMessage(hListbox , LB_SETCURSEL,newpos,0);
return 0;
case WM_SETFOCUS:
SetFocus(hHidemaruWindow);
return 0;
}
return CallWindowProc(baseProc , hwnd , msg , wp , lp);
}
extern "C" __declspec(dllexport)
int showListBox(const char* str)
{
~内容省略~
前回と一緒
~内容省略~
}
extern "C" __declspec(dllexport)
int createListBox(int hHideWnd , int fontsize)
{
POINT pt;
hHidemaruWindow =
HWND(hHideWnd);
GetCaretPos(&pt);
HWND hHideEdit = FindWindowEx(hHidemaruWindow ,
NULL ,
"HM32CLIENT" ,
NULL);
if(hHideEdit ==
NULL){
hHideEdit = FindWindowEx(hHidemaruWindow ,
NULL ,
"Hidemaru32Class" ,
NULL);
hHideEdit = FindWindowEx(hHideEdit ,
NULL ,
"HM32CLIENT" ,
NULL);
}
hListbox=CreateWindow(
"LISTBOX",
"",
WS_CHILD|WS_BORDER|WS_VSCROLL|LBS_NOTIFY|LBS_WANTKEYBOARDINPUT,
pt.x,pt.y + fontsize,400,100,
hHideEdit ,
NULL,
(
HINSTANCE)GetWindowLong(hHideEdit , GWL_HINSTANCE),
NULL);
if(hListbox ==
NULL)
return false;
baseProc = (WNDPROC)GetWindowLong(hListbox , GWL_WNDPROC);
SetWindowLong(hListbox , GWL_WNDPROC , (
LONG)NewProc);
return true;
}
extern "C" __declspec(dllexport)
int delListBox()
{
DestroyWindow(hListbox);
clearBaseList();
return true;
}
extern "C" __declspec(dllexport)
int upListBox()
{
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
if(nowpos > 0)SendMessage(hListbox , LB_SETCURSEL,nowpos-1,0);
return true;
}
extern "C" __declspec(dllexport)
int downListBox()
{
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
int max = SendMessage(hListbox , LB_GETCOUNT,0,0)-1;
if(nowpos < max)SendMessage(hListbox , LB_SETCURSEL,nowpos+1,0);
return true;
}
extern "C" __declspec(dllexport)
int getItemCount()
{
return SendMessage(hListbox , LB_GETCOUNT,0,0);
}
extern "C" __declspec(dllexport)
const char* getSelectString()
{
if(hListbox ==
NULL)
return (
const char*)
"";
if (SendMessage(hListbox , LB_GETCOUNT,0,0) <= 0)
return (
const char*)
"";
char *ret;
int cursel , len;
cursel = SendMessage(hListbox , LB_GETCURSEL,0,0);
len = SendMessage(hListbox , LB_GETTEXTLEN,cursel,0);
ret = (
char*)malloc(len+1);
SendMessage(hListbox , LB_GETTEXT , cursel , (LPARAM)ret);
returnstring = ret;
free(ret);
return returnstring.c_str();
}
extern "C" __declspec(dllexport)
int nextpageListBox()
{
RECT rc;
int itemcount;
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
int max = SendMessage(hListbox , LB_GETCOUNT,0,0) -1;
GetClientRect(hListbox , &rc);
itemcount = rc.bottom / (SendMessage(hListbox , LB_GETITEMHEIGHT,0,0));
int newpos;
newpos = nowpos+itemcount;
if(max < newpos){
newpos = max;
}
SendMessage(hListbox , LB_SETCURSEL,newpos,0);
SendMessage(hListbox , LB_SETTOPINDEX,newpos,0);
return true;
}
extern "C" __declspec(dllexport)
int prevpageListBox()
{
RECT rc;
int itemcount;
GetClientRect(hListbox , &rc);
itemcount = rc.bottom / (SendMessage(hListbox , LB_GETITEMHEIGHT,0,0));
int nowpos = SendMessage(hListbox , LB_GETCURSEL,0,0);
int newpos;
newpos = nowpos-itemcount;
if(0 > newpos){
newpos = 0;
}
SendMessage(hListbox , LB_SETCURSEL,newpos,0);
SendMessage(hListbox , LB_SETTOPINDEX,newpos,0);
return true;
}