//======================================================================//
// MiniQQ GUI ver 1.0 //
// 作者:YoYo Chan //
// Email: //
// Blog: //
// MiniGUI版本: 1.3.3 //
//==================================================================//
#include
#include
#include
#include
#include
#include
#ifndef _LITE_VERSION
#include
#endif
#define IDC_BUTTON0 100
#define IDC_BUTTON1 100+1
#define IDC_BUTTON2 100+2
#define IDC_BUTTON3 100+3
#define IDC_CHECKBOX0 110
#define IDC_CHECKBOX1 110+1
#define IDC_CHECKBOX2 110+2
#define IDC_TEXT0 120
#define IDC_TEXT1 120+1
#define IDC_TEXT2 120+2
#define IDC_TEXT3 120+3
#define IDC_TEXT4 120+4
#define IDC_EDIT0 130
#define IDC_EDIT1 130+1
#define IDC_EDIT2 130+2
#define IDC_EDIT3 130+3
#define IDC_EDIT4 130+4
#define IDC_LISTBOX0 140
//==========================Dialog代码开始==============================//
//======================================================================//
static DLGTEMPLATE DlgInitProgress = {
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
0,0,320,240,
"This is a dialog!",
0,0,
3,NULL,
0
};
static CTRLDATA CtrlInitProgress[] =
{
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
50,50,250,30,
IDC_TEXT4,
"欢迎到我的BLOG做客:",
0
},
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
50,80,250,30,
IDC_TEXT4,
"",
0
},
{
CTRL_BUTTON,
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
120,150,80,30,
IDOK,
"关闭",
0
}
};
static int InitDialogBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
switch(message){
case MSG_INITDIALOG:
return 1;
case MSG_COMMAND:
switch(wParam){
case IDOK:
EndDialog(hDlg, wParam);
break;
}
return 0;
case MSG_CLOSE:
EndDialog(hDlg, wParam);
return 0;
}
return DefaultDialogProc(hDlg, message, wParam, lParam);
}
static int InitDialogBox(HWND hWnd)
{
DlgInitProgress.controls = CtrlInitProgress;
DialogBoxIndirectParam(&DlgInitProgress, hWnd, InitDialogBoxProc, 0L);
}
//=======================Dialog代码结束=================================//
//========================Login代码开始=================================//
//======================================================================//
int MiniGUIMain(int argc, const char* argv[])
{
static int LoginWinProc();
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect( 0, 0, 800, 600);
#endif
char *p = "这是YoYo的第一个MiniGUI程序!";
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "MiniQQ ver0.1 Author: YoYo Chan";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = LoginWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 320;
CreateInfo.by = 240;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = p;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow(&CreateInfo);
if(hMainWnd==HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while(GetMessage(&Msg, hMainWnd)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(hMainWnd);
printf("The MainWin has been close!\n");
return 0;
}
static int LoginWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
static int QQWin();
char *str1 = (char *)GetWindowAdditionalData(hWnd);
switch(message){
case MSG_CREATE:
CreateWindow(CTRL_STATIC,
str1,
WS_CHILD | WS_VISIBLE,
IDC_TEXT0,
10,10,220,20,hWnd,0);
CreateWindow(CTRL_STATIC,
"用户名:",
WS_CHILD | WS_VISIBLE,
IDC_TEXT1,
50,50,80,20,hWnd,0);
CreateWindow(CTRL_EDIT,
"User Name",
WS_CHILD | WS_BORDER | WS_VISIBLE,
IDC_EDIT0,
130,50,100,20,hWnd,0);
CreateWindow(CTRL_STATIC,
"密码:",
WS_CHILD | WS_VISIBLE,
IDC_TEXT2,
50,80,80,20,hWnd,0);
CreateWindow(CTRL_EDIT,
"Password",
WS_CHILD | WS_BORDER | WS_VISIBLE | ES_PASSWORD,
IDC_EDIT1,
130,80,100,20,hWnd,0);
CreateWindow(CTRL_BUTTON,
"登陆",
WS_CHILD | BS_DEFPUSHBUTTON | WS_VISIBLE,
IDC_BUTTON0,
100,160,80,30,hWnd,0);
CreateWindow(CTRL_BUTTON,
"保存密码",
WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE,
IDC_CHECKBOX0,
50,120,100,30,hWnd,0);
CreateWindow(CTRL_BUTTON,
"隐身登陆",
WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE,
IDC_CHECKBOX1,
180,120,100,30,hWnd,0);
printf("The MainWin has been opened!\n");
return 0;
case MSG_COMMAND:{
int id = LOWORD(wParam);
int code = HIWORD(wParam);
switch(id){
case IDC_BUTTON0:
if(code == BN_CLICKED){
SendMessage(hWnd, MSG_CLOSE, 0, 0);
QQWin();
}
}
return 0;
}
case MSG_DESTROY:
DestroyAllControls(hWnd);
return 0;
case MSG_CLOSE:
DestroyMainWindow(hWnd);
PostQuitMessage(hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
//=========================Login代码结束=================================//
//=========================QQ主面板代码开始==============================//
//=======================================================================//
static int QQWin(void)
{
static int QQWinProc();
MSG Msg;
HWND hQQWnd;
MAINWINCREATE CreateInfo;
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "MiniQQ ver0.1";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = QQWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 180;
CreateInfo.by = 450;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hQQWnd = CreateMainWindow(&CreateInfo);
if(hQQWnd==HWND_INVALID)
return -1;
ShowWindow(hQQWnd, SW_SHOWNORMAL);
while(GetMessage(&Msg, hQQWnd)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(hQQWnd);
printf("The QQWin has been closed!\n");
return 0;
}
static int QQWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
static int MessageWin();
static HWND hListBox;
switch(message){
case MSG_CREATE:{
HWND hListBox;
hListBox = CreateWindow(CTRL_LISTBOX,
"FriendsList",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_SORT | LBS_NOTIFY | LBS_USEICON,
IDC_LISTBOX0,
10,10,160,350,hWnd,0);
LISTBOXITEMINFO lbii;
lbii.hIcon = GetSmallSystemIcon(4);
lbii.cmFlag = CMFLAG_BLANK;
lbii.string = "YoYo Chan";
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)&lbii);
CreateWindow(CTRL_BUTTON,
"点击我",
WS_CHILD | WS_VISIBLE,
IDC_BUTTON3,
10,370,160,30,hWnd,0);
printf("The QQWin has been opened!\n");
return 0;
}
case MSG_COMMAND:{
int id = LOWORD(wParam);
int code = HIWORD(wParam);
switch(id){
case IDC_LISTBOX0:
if(code == LBN_DBLCLK){
hListBox = GetDlgItem(hWnd, IDC_LISTBOX0);
int index;
char buffer[20];
index = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
SendMessage(hListBox, LB_GETTEXT, index, (LPARAM)buffer);
MessageWin(hWnd, (char *)buffer);
}
case IDC_BUTTON3:
if(code == BN_CLICKED)
InitDialogBox(hWnd);
}
return 0;
}
case MSG_DESTROY:
DestroyAllControls(hWnd);
return 0;
case MSG_CLOSE:
DestroyMainWindow(hWnd);
PostQuitMessage(hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
//======================QQ主面板代码结束=================================//
//=====================消息对话框代码开始================================//
//=======================================================================//
static int MessageWin(HWND hWnd, char* friendName)
{
static int MessageWinProc();
HWND hMsgWnd;
MAINWINCREATE CreateInfo;
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = friendName;
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = MessageWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 450;
CreateInfo.by = 350;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = hWnd;
hMsgWnd = CreateMainWindow(&CreateInfo);
if(hMsgWnd==HWND_INVALID)
return -1;
ShowWindow(hMsgWnd, SW_SHOWNORMAL);
return 0;
}
static int MessageWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
static int MessageSendProc();
switch(message){
case MSG_CREATE:
CreateWindow(CTRL_MLEDIT,
"",
WS_CHILD | WS_BORDER | WS_VISIBLE | ES_AUTOWRAP | WS_VSCROLL,
IDC_EDIT2,
10,10,350,200,hWnd,0);
SendMessage(GetDlgItem(hWnd, IDC_EDIT2), EM_SETREADONLY, TRUE, 0);
CreateWindow(CTRL_EDIT,
"",
WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOWRAP,
IDC_EDIT3,
10,220,350,100,hWnd,0);
CreateWindow(CTRL_BUTTON,
"发送",
WS_CHILD | WS_VISIBLE,
IDC_BUTTON1,
370,220,70,45,hWnd,0);
CreateWindow(CTRL_BUTTON,
"关闭",
WS_CHILD | WS_VISIBLE,
IDC_BUTTON2,
370,275,70,45,hWnd,0);
SetNotificationCallback(GetDlgItem(hWnd, IDC_BUTTON1), MessageSendProc);
printf("The MessageWin has been opened!\n");
return 0;
case MSG_COMMAND:{
int id = LOWORD(wParam);
int code = HIWORD(wParam);
switch(id){
case IDC_BUTTON2:
if(code == BN_CLICKED)
SendMessage(hWnd, MSG_CLOSE, 0, 0);
}
return 0;
}
case MSG_DESTROY:
DestroyAllControls(hWnd);
printf("The MessageWin has been destroyed!\n");
return 0;
case MSG_CLOSE:
DestroyMainWindow(hWnd);
MainWindowCleanup(hWnd);
printf("The MessageWin has been closed!\n");
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
static int MessageSendProc(HWND hWnd, int id, int nc, DWORD add_data)
{
switch(nc){
case BN_CLICKED:{
char buffer[256];
char *p;
p = (char *)malloc(1024);
GetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT2), p, 1024);
GetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT3), buffer, 255);
strcat(p, buffer);
SetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT2), p);
free(p);
return 0;
}
return 0;
}
}
//=======================信息对话框代码结束==============================//
效果图: