【转】第一个MiniGUI程序:模仿QQ界面

最近几天在学MiniGui,最好的学习方法就是实践,先写个练练笔。
其实只是一个界面,不知道什么时候才能真正写个完整的程序。
初次写GUI程序,感觉写得不好,还请高手来指教。

//======================================================================//
// MiniQQ GUI ver 1.0 //
// 作者:YoYo Chan //
// Email: czy1000@126.com //
// Blog: http://hi.baidu.com/chenzhuoyou //
// MiniGUI版本: 1.3.3 //
//==================================================================//
#include <stdio.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#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,
  ,,,,
  "This is a dialog!",
  ,,
  ,NULL,
  
}; static CTRLDATA CtrlInitProgress[] =
{
  {
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
,,,,
IDC_TEXT4,
"欢迎到我的BLOG做客:",   },
  {
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
,,,,
IDC_TEXT4,
"HTTP://HI.BAIDU.COM/CHENZHUOYOU",   },
  {
CTRL_BUTTON,
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
,,,,
IDOK,
"关闭",   }
}; static int InitDialogBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
  switch(message){
  case MSG_INITDIALOG:
    return ;
  case MSG_COMMAND:
    switch(wParam){
    case IDOK:
      EndDialog(hDlg, wParam);
      break;
    }
    return ;
  case MSG_CLOSE:
    EndDialog(hDlg, wParam);
    return ;
  }
  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( , , , );
  #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 = ;
  CreateInfo.hCursor = GetSystemCursor();
  CreateInfo.hIcon = ;
  CreateInfo.MainWindowProc = LoginWinProc;
  CreateInfo.lx = ;
  CreateInfo.ty = ;
  CreateInfo.rx = ;
  CreateInfo.by = ;
  CreateInfo.iBkColor = COLOR_lightwhite;
  CreateInfo.dwAddData = p;
  CreateInfo.hHosting = HWND_DESKTOP;   hMainWnd = CreateMainWindow(&CreateInfo);
  if(hMainWnd==HWND_INVALID)
return -;
  ShowWindow(hMainWnd, SW_SHOWNORMAL);
  while(GetMessage(&Msg, hMainWnd)){
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
  }
  MainWindowThreadCleanup(hMainWnd);
  printf("The MainWin has been close!\n");
  return ;
} 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,,,,hWnd,);
    CreateWindow(CTRL_STATIC,
            "用户名:",
            WS_CHILD | WS_VISIBLE,
            IDC_TEXT1,
            50,,,,hWnd,);
    CreateWindow(CTRL_EDIT,
            "User Name",
            WS_CHILD | WS_BORDER | WS_VISIBLE,
            IDC_EDIT0,
            130,,,,hWnd,);
    CreateWindow(CTRL_STATIC,
            "密码:",
            WS_CHILD | WS_VISIBLE,
            IDC_TEXT2,
            50,,,,hWnd,);
    CreateWindow(CTRL_EDIT,
            "Password",
            WS_CHILD | WS_BORDER | WS_VISIBLE | ES_PASSWORD,
            IDC_EDIT1,
            130,,,,hWnd,);
    CreateWindow(CTRL_BUTTON,
            "登陆",
            WS_CHILD | BS_DEFPUSHBUTTON | WS_VISIBLE,
            IDC_BUTTON0,
            100,,,,hWnd,);
    CreateWindow(CTRL_BUTTON,
            "保存密码",
            WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE,
            IDC_CHECKBOX0,
            50,,,,hWnd,);
    CreateWindow(CTRL_BUTTON,
            "隐身登陆",
            WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE,
            IDC_CHECKBOX1,
            180,,,,hWnd,);
    printf("The MainWin has been opened!\n");
    return ;
  case MSG_COMMAND:{
    int id = LOWORD(wParam);
    int code = HIWORD(wParam);
    switch(id){
    case IDC_BUTTON0:
      if(code == BN_CLICKED){
        SendMessage(hWnd, MSG_CLOSE, , );
        QQWin();
      }
    }
    return ;
  }
  case MSG_DESTROY:
    DestroyAllControls(hWnd);
    return ;
  case MSG_CLOSE:
    DestroyMainWindow(hWnd);
    PostQuitMessage(hWnd);
    return ;
  }
  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 = ;
  CreateInfo.hCursor = GetSystemCursor();
  CreateInfo.hIcon = ;
  CreateInfo.MainWindowProc = QQWinProc;
  CreateInfo.lx = ;
  CreateInfo.ty = ;
  CreateInfo.rx = ;
  CreateInfo.by = ;
  CreateInfo.iBkColor = COLOR_lightwhite;
  CreateInfo.dwAddData = ;
  CreateInfo.hHosting = HWND_DESKTOP;   hQQWnd = CreateMainWindow(&CreateInfo);
  if(hQQWnd==HWND_INVALID)
    return -;
  ShowWindow(hQQWnd, SW_SHOWNORMAL);
  while(GetMessage(&Msg, hQQWnd)){
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
  }
  MainWindowThreadCleanup(hQQWnd);
  printf("The QQWin has been closed!\n");
  return ;
} 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,,,,hWnd,);
    LISTBOXITEMINFO lbii;
    lbii.hIcon = GetSmallSystemIcon();
    lbii.cmFlag = CMFLAG_BLANK;
    lbii.string = "YoYo Chan";
    SendMessage(hListBox, LB_ADDSTRING, , (LPARAM)&lbii);
    CreateWindow(CTRL_BUTTON,
            "点击我",
            WS_CHILD | WS_VISIBLE,
            IDC_BUTTON3,
            10,,,,hWnd,);
    printf("The QQWin has been opened!\n");
    return ;
  }   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[];
        index = SendMessage(hListBox, LB_GETCURSEL, , );
        SendMessage(hListBox, LB_GETTEXT, index, (LPARAM)buffer);
        MessageWin(hWnd, (char *)buffer);
      }
    case IDC_BUTTON3:
      if(code == BN_CLICKED)
        InitDialogBox(hWnd);
    }
    return ;
  }
  case MSG_DESTROY:
    DestroyAllControls(hWnd);
    return ;
  case MSG_CLOSE:
    DestroyMainWindow(hWnd);
    PostQuitMessage(hWnd);
    return ;
  }
  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 = ;
  CreateInfo.hCursor = GetSystemCursor();
  CreateInfo.hIcon = ;
  CreateInfo.MainWindowProc = MessageWinProc;
  CreateInfo.lx = ;
  CreateInfo.ty = ;
  CreateInfo.rx = ;
  CreateInfo.by = ;
  CreateInfo.iBkColor = COLOR_lightwhite;
  CreateInfo.dwAddData = ;
  CreateInfo.hHosting = hWnd;   hMsgWnd = CreateMainWindow(&CreateInfo);
  if(hMsgWnd==HWND_INVALID)
    return -;
  ShowWindow(hMsgWnd, SW_SHOWNORMAL);
  return ;
} 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,,,,hWnd,);
    SendMessage(GetDlgItem(hWnd, IDC_EDIT2), EM_SETREADONLY, TRUE, );
    CreateWindow(CTRL_EDIT,
            "",
            WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOWRAP,
            IDC_EDIT3,
            10,,,,hWnd,);
    CreateWindow(CTRL_BUTTON,
            "发送",
            WS_CHILD | WS_VISIBLE,
            IDC_BUTTON1,
            370,,,,hWnd,);     CreateWindow(CTRL_BUTTON,
            "关闭",
            WS_CHILD | WS_VISIBLE,
            IDC_BUTTON2,
            370,,,,hWnd,);
    SetNotificationCallback(GetDlgItem(hWnd, IDC_BUTTON1), MessageSendProc);
    printf("The MessageWin has been opened!\n");
    return ;
  case MSG_COMMAND:{
    int id = LOWORD(wParam);
    int code = HIWORD(wParam);
    switch(id){
    case IDC_BUTTON2:
      if(code == BN_CLICKED)
        SendMessage(hWnd, MSG_CLOSE, , );
    }
    return ;
  }
  case MSG_DESTROY:
    DestroyAllControls(hWnd);
    printf("The MessageWin has been destroyed!\n");
    return ;
  case MSG_CLOSE:
    DestroyMainWindow(hWnd);
    MainWindowCleanup(hWnd);
    printf("The MessageWin has been closed!\n");
    return ;
  }
  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[];
      char *p;
      p = (char *)malloc();
      GetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT2), p, );
      GetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT3), buffer, );
      strcat(p, buffer);
      SetWindowText(GetDlgItem(GetParent(hWnd), IDC_EDIT2), p);
      free(p);
      return ;
    }
    return ;
  }
}
//=======================信息对话框代码结束====================================================================================//

效果图:

【转】第一个MiniGUI程序:模仿QQ界面

【转】第一个MiniGUI程序:模仿QQ界面

(chenzhuoyou)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。

转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201004/9078.html]

上一篇:nat模式下更改网络环境, 虚拟机中Linux无法上网的问题


下一篇:[转]Android:布局实例之模仿QQ登录界面