#include<minigui/common.h>
#include<minigui/minigui.h>
#include<minigui/gdi.h>
#include<minigui/window.h>
#include<minigui/control.h>
#include<minigui/dti.c>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define ID_SLEDIT_1 100
#define ID_SLEDIT_2 101
#define ID_static_1 102
#define ID_static_2 103
#define ID_listbox1 107
#define ID_listbox2 108
#define ID_k_9 110
#define ID_k_10 111
#define ID_k_11 112
#define ID_k_12 113
#define ID_k_12 113
#define ID_EDIT 114
static BITMAP bmp;
int status;
int i;
int k;
static int CreateWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{ HWND hWnd_listbox;
HWND hWnd_listbox1;
HDC hdc;
switch (message)
{
LISTBOXITEMINFO lbii;
case MSG_PAINT:
hdc=BeginPaint(hWnd);
FillBoxWithBitmap(hdc,0,0,0,0,&bmp);
EndPaint(hWnd,hdc);
return 0;
case MSG_CREATE:
hWnd_listbox=CreateWindow (CTRL_LISTBOX,
"",
WS_VISIBLE | WS_VSCROLL | WS_BORDER |LBS_NOTIFY |LBS_AUTOCHECKBOX,
ID_listbox1,
20, 27, 100, 130,
hWnd,
0);
hWnd_listbox1=CreateWindow (CTRL_LISTBOX,
"",
WS_VISIBLE | WS_VSCROLL | WS_BORDER |LBS_NOTIFY |LBS_AUTOCHECKBOX,
ID_listbox2,
135, 27, 100, 130,
hWnd,
0);
CreateWindow (
"static",
"姓名:",
WS_VISIBLE | SS_SIMPLE,
ID_static_1,
20, 10, 100, 16,
hWnd,
0);
CreateWindow (
"static",
"电话:",
WS_VISIBLE | SS_SIMPLE,
ID_static_2,
135, 10, 100, 16,
hWnd,
0);
CreateWindow (
"static",
"输入",
WS_VISIBLE | SS_SIMPLE,
ID_static_2,
23, 162, 55, 25,
hWnd,
0);
CreateWindow (
CTRL_SLEDIT,
"",
WS_VISIBLE | WS_BORDER | LBS_SORT | LBS_NOTIFY,
ID_SLEDIT_1,
83, 162, 60, 25,
hWnd,
0);
CreateWindow (
CTRL_SLEDIT,
"",
WS_VISIBLE | WS_BORDER | LBS_SORT | LBS_NOTIFY,
ID_SLEDIT_2,
145, 162, 85, 25,
hWnd,
0);
CreateWindow (
"button",
"添加",
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
ID_k_9,
240, 20, 60, 30,
hWnd,
0);
CreateWindow (
"button",
"删除",
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
ID_k_10,
240, 55, 60, 30,
hWnd,
0);
CreateWindow (
"button",
"修改",
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
ID_k_11,
240, 90, 60, 30,
hWnd,
0);
CreateWindow (
"button",
"查询",
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
ID_k_12,
240, 125, 60, 30,
hWnd,
0);
break;
case MSG_COMMAND:
switch(wParam)
{
case ID_k_12:
{
int index=-1;
char buffer[20]={'\0'};
GetWindowText(GetDlgItem(hWnd,ID_SLEDIT_1),buffer,20);
index=SendMessage (GetDlgItem(hWnd,ID_listbox1), LB_FINDSTRING,0,(LPARAM)buffer);
SendMessage (GetDlgItem(hWnd,ID_listbox1), LB_SETCURSEL,index,0);
}
break;
case ID_k_9:
{
char name[30];
char number[30];
GetWindowText(GetDlgItem(hWnd,ID_SLEDIT_1),name,20);
GetWindowText(GetDlgItem(hWnd,ID_SLEDIT_2),number,20);
lbii.string=name;
SendMessage (GetDlgItem(hWnd,ID_listbox1), LB_ADDSTRING,0,(LPARAM)&lbii);
lbii.string=number;
SendMessage (GetDlgItem(hWnd,ID_listbox2), LB_ADDSTRING,0,(LPARAM)&lbii);
}
break;
case ID_k_10:
for(i=0;i<SendMessage(GetDlgItem(hWnd,ID_listbox1),LB_GETCOUNT,0,0);i++)
{
status=SendMessage(GetDlgItem(hWnd,ID_listbox1),LB_GETCHECKMARK,i,0);
if(status==CMFLAG_CHECKED)
{
SendMessage(GetDlgItem(hWnd,ID_listbox1),LB_DELETESTRING,i,0);
SendMessage(GetDlgItem(hWnd,ID_listbox2),LB_DELETESTRING,i,0);
}
}
break;
case ID_k_11:
{char name[30];
char number[30];
GetWindowText(GetDlgItem(hWnd,ID_SLEDIT_1),name,20);
GetWindowText(GetDlgItem(hWnd,ID_SLEDIT_2),number,20);
for(i=0;i<SendMessage(GetDlgItem(hWnd,ID_listbox1),LB_GETCOUNT,0,0);i++)
{
status=SendMessage(GetDlgItem(hWnd,ID_listbox1),LB_GETCHECKMARK,i,0);
if(status==CMFLAG_CHECKED)
{
SendMessage (GetDlgItem(hWnd,ID_listbox1), LB_SETTEXT,i,(LPARAM)name);
SendMessage (GetDlgItem(hWnd,ID_listbox2), LB_SETTEXT,i,(LPARAM)number);
}
}
}
break;
case MSG_CLOSE:
DestroyMainWindow(hWnd);
PostQuitMessage(hWnd);
return 0;
}
}
return DefaultMainWinProc(hWnd,message,wParam,lParam);
}
int MiniGUIMain (int argc, const char* argv[])
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
HDC hdc;
LoadBitmap(HDC_SCREEN,&bmp,"bk2.jpg");
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "通讯录";
CreateInfo.hMenu =0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = CreateWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 320;
CreateInfo.by = 240;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.dwReserved = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
UnloadBitmap(&bmp);
MiniGUIExtCleanUp();
MainWindowThreadCleanup(hMainWnd);
return 0;
}