getmessage.c

来自「minigui PDA系统 可实现手机功能」· C语言 代码 · 共 345 行

C
345
字号
#ifndef _GETMESSAGE_C
#define _GETMESSAGE_C
#include "msgCom.h"
#include "fileMessage.h"
#include "message.h"
#include "../mybuttonreg.h"
#include "../telbook/telbook.h"

#define  IDC_GM_LIST        0x415b
#define  IDC_GM_READ      0x415c#define  IDC_GM_DEL      0x415d#define  IDC_GM_RETURN	     0x415e

static BITMAP read_pushed;
static BITMAP read_unpushed;
static BITMAP read_mousemove;

static BITMAP del_pushed;
static BITMAP del_unpushed;
static BITMAP del_mousemove;

static BITMAP return_pushed;
static BITMAP return_unpushed;
static BITMAP return_mousemove;

BITMAP jpg_bkgnd_GM;

HWND GMhWnd;
HWND 	hCtrl_read;
HWND 	hCtrl_del;
HWND 	hCtrl_return;

/*static void emLoadBitmap()
{
	LoadBitmap (HDC_SCREEN, &read_pushed, "image/button/msg_read_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &read_unpushed, "image/button/msg_read_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &read_mousemove, "image/button/msg_read_mousemove.jpg");	

	LoadBitmap (HDC_SCREEN, &del_pushed, "image/button/msg_del_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &del_unpushed, "image/button/msg_del_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &del_mousemove, "image/button/msg_del_mousemove.jpg");

	LoadBitmap (HDC_SCREEN, &return_pushed, "image/button/msg_return_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &return_unpushed, "image/button/msg_return_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &return_mousemove, "image/button/msg_return_mousemove.jpg");	
}
static void emUnLoadBitmap()
{
	 UnloadBitmap (&read_pushed);
        UnloadBitmap (&read_unpushed);
        UnloadBitmap (&read_mousemove);

	 UnloadBitmap (&del_pushed);
        UnloadBitmap (&del_unpushed);
        UnloadBitmap (&del_mousemove);

	 UnloadBitmap (&return_pushed);
        UnloadBitmap (&return_unpushed);
        UnloadBitmap (&return_mousemove);
}
*/
////////////////////////////收信箱////////////////////////////////////
static void gm_notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{		
	if ( hwnd == hCtrl_read&& nc == MYBUTTON_PUSHED)
	{		
		SetWindowAdditionalData(hwnd, (DWORD)&read_pushed);
	}
	if ( hwnd == hCtrl_read &&nc == BN_CLICKED&&id==IDC_GM_READ)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&read_unpushed);
		SendNotifyMessage(GMhWnd,IDC_GM_READ,0,0);
	}
	if( hwnd == hCtrl_read && nc == MYBUTTON_MOUSEMOVE)
	{	
		SetWindowAdditionalData(hwnd, (DWORD)&read_mousemove);
	}
//-----------------------------------------------------------
	if ( hwnd == hCtrl_del&& nc == MYBUTTON_PUSHED)
	{		
		SetWindowAdditionalData(hwnd, (DWORD)&del_pushed);
	}
	if ( hwnd == hCtrl_del && nc == BN_CLICKED&&id==IDC_GM_DEL)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&del_unpushed);
		SendNotifyMessage(GMhWnd,IDC_GM_DEL,0,0);
	}
	if( hwnd == hCtrl_del && nc == MYBUTTON_MOUSEMOVE)
	{	
		SetWindowAdditionalData(hwnd, (DWORD)&del_mousemove );
	}
//-----------------------------------------------------------------------	
	if ( hwnd == hCtrl_return&& nc == MYBUTTON_PUSHED)
	{		
		//SetWindowAdditionalData(hwnd, (DWORD)&return_pushed);
	}
	if ( hwnd == hCtrl_return&&nc == BN_CLICKED&&id==IDC_GM_RETURN)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
		SendNotifyMessage(GMhWnd,MSG_CLOSE,0,0);
	}
	if( hwnd == hCtrl_return && nc == MYBUTTON_MOUSEMOVE)
	{	
		//SetWindowAdditionalData(hwnd, (DWORD)&return_mousemove );
	}
//---------------------------------------------------------------------------
	InvalidateRect (hwnd, NULL, TRUE);
}
///////////////////////////////////////////////////////////////////////
static int GetMSGProc(HWND GMhWnd, int message, WPARAM wParam, LPARAM lParam)
{
	Note telbook;
	int ifname = 0;
	  int i;
	  int j;
	  int k;
	  static int index_del;
	  msg getMsgArry[100];
	    HDC hdc = (HDC)wParam;
	    const RECT* clip = (const RECT*) lParam;
	    BOOL fGetDC = FALSE;
	    RECT rcTemp;
    switch(message)
    {
        case MSG_CREATE:
		//emLoadBitmap();
/*             CreateWindow (CTRL_LISTBOX,
                    "",WS_VISIBLE | WS_VSCROLL |WS_HSCROLL| WS_BORDER | LBS_NOTIFY ,
                    IDC_GM_LIST,20,30,180,135,GMhWnd,0); */
               CreateWindowEx (CTRL_LISTBOX,
                    "",WS_VISIBLE | WS_VSCROLL |WS_HSCROLL| WS_BORDER | LBS_NOTIFY ,WS_EX_TRANSPARENT,
                    IDC_GM_LIST,20,30,180,135,GMhWnd,0);
		//		hCtrl_read = CreateWindowEx(CTRL_MYBUTTON, 
		//								"读取",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_GM_READ, 220,30,80,28, GMhWnd, (DWORD)&read_unpushed);
				hCtrl_read =CreateWindow ("button",
				                          "读取",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                          IDC_GM_READ,
				                          220,30,80,28,GMhWnd, 0);
			//	hCtrl_del = CreateWindowEx(CTRL_MYBUTTON, 
			//							"删除",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_GM_DEL, 220,80,80,28, GMhWnd, (DWORD)&del_unpushed);
				hCtrl_del =CreateWindow ("button",
				                          "删除",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                          IDC_GM_DEL,
				                          220,80,80,28, GMhWnd, 0);
			    //   hCtrl_return = CreateWindowEx(CTRL_MYBUTTON, 
				//						"返回",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_GM_RETURN, 220,130,80,28, GMhWnd, (DWORD)&return_unpushed);
				hCtrl_return =CreateWindow ("button",
				                          "返回",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                          IDC_GM_RETURN,
				                           220,130,80,28, GMhWnd, 0);
			SetNotificationCallback ( hCtrl_read, gm_notify_proc );
			SetNotificationCallback ( hCtrl_del, gm_notify_proc );
			SetNotificationCallback ( hCtrl_return, gm_notify_proc );	

	      /*		GetMsgFp=fopen( "data/GetMsg.txt", "r" );
	           	rewind(GetMsgFp);
			i=0;	
        		 while(!feof(GetMsgFp))
        		 {
        		 	 fread(&GetMsgTxt,sizeof(msg),1,GetMsgFp);
        		 	 printf ("****************************\n");
					 printf ( "GetMgsTxt%s\n", GetMsgTxt.number);
					 printf ( "GetMgsTxt%s\n", GetMsgTxt.time);
					 printf ( "GetMgsTxt%s\n", GetMsgTxt.txt);
				printf ("**************************\n");
				strcat ( GetMsgTxt.number, "   ");
				strcat ( GetMsgTxt.number, GetMsgTxt.time );
        		 	 SendMessage(GetDlgItem(GMhWnd,IDC_GM_LIST),LB_ADDSTRING,0,(LPARAM)GetMsgTxt.number);
        		 	 i++;
					 printf ("!!!!!!!!!i=%d\n",i);
        		 }
        		 SendDlgItemMessage(GMhWnd,IDC_GM_LIST,LB_DELETESTRING,i,0);
        		 fclose(GetMsgFp);
        		 */
			GetMsgFp=fopen("data/GetMsg.txt","r");
			TelBookFp=fopen("data/phonebook.dat","r");
	           	rewind(GetMsgFp);
			i=0;	
        		 while(!feof(GetMsgFp))
        		 {
        		 	 fread(&GetMsgTxt,sizeof(msg),1,GetMsgFp);
				rewind (TelBookFp);
				ifname = 0;
				while (!feof(TelBookFp))
				{
					fread (&telbook, sizeof(Note),1,TelBookFp);
					if ( strcmp ( &GetMsgTxt.number[3], telbook.phone ) ==0 )
					{	strcpy ( listName, telbook.name );
						ifname = 1;
						break;
					}
					
				}
				if ( ifname == 0 )
				{
					strcpy ( listName, GetMsgTxt.number );
					strcat ( listName, "   ");
					strcat ( listName, &GetMsgTxt.time[4]  );
				}
				else if ( ifname == 1 )
				{
					strcat ( listName,"   ");
					strcat ( listName, &GetMsgTxt.time[4] );
				}
				SendMessage(GetDlgItem(GMhWnd,IDC_GM_LIST),LB_ADDSTRING,0,(LPARAM)listName);
        		 	 i++;
					 printf ("!!!!!!!!!i=%d\n",i);
        		 }
        		 SendDlgItemMessage(GMhWnd,IDC_GM_LIST,LB_DELETESTRING,i,0);
        		 fclose(GetMsgFp);	
			fclose (TelBookFp);
             return 0;
		/*	case MSG_MOUSEMOVE:
				SetWindowAdditionalData( hCtrl_read, (DWORD)&read_unpushed );
				InvalidateRect (hCtrl_read, NULL, TRUE);
				SetWindowAdditionalData( hCtrl_del, (DWORD)&del_unpushed );
				InvalidateRect (hCtrl_del, NULL, TRUE);
				SetWindowAdditionalData( hCtrl_return, (DWORD)&return_unpushed );
				InvalidateRect (hCtrl_return, NULL, TRUE);
				break;
*/
		case MSG_ERASEBKGND:
	    		if (hdc == 0) {
				hdc = GetClientDC (GMhWnd);
				fGetDC = TRUE;
	 		   }       
		    
	    		if (clip) {
				rcTemp = *clip;
				ScreenToClient (GMhWnd, &rcTemp.left, &rcTemp.top);
				ScreenToClient (GMhWnd, &rcTemp.right, &rcTemp.bottom);
				IncludeClipRect (hdc, &rcTemp);
	    		}

//	  		  FillBoxWithBitmap (hdc, rcTemp.left, rcTemp.top, 0, 0, &jpg_bkgnd_GM);
			FillBoxWithBitmap (hdc, 0, 0, 320, 192, &jpg_bkgnd_GM);
	    		if (fGetDC)
				ReleaseDC (hdc);
	 		   return 0;
                 case IDC_GM_READ:			 	
                	    GetMsgIndex = SendMessage (GetDlgItem(GMhWnd, IDC_GM_LIST), LB_GETCURSEL, 0, 0); 
                 	    printf("index ==========%d\n",GetMsgIndex);
				 if ( GetMsgIndex < 0 )
				   {
				   	MessageBox (GMhWnd,"请选择要读信息", "短信",MB_OK | MB_ICONINFORMATION);
					break;
				   }
				    ReadMSG(GMhWnd);
                 	    return 0;
                  case IDC_GM_DEL:
                 	    GetMsgFp = fopen("data/GetMsg.txt","r");
                 	    index_del = SendMessage (GetDlgItem(GMhWnd, IDC_GM_LIST), LB_GETCURSEL, 0, 0);
				if ( index_del < 0 )
			    	{
				MessageBox (GMhWnd,"无删除项!", "短信",MB_OK | MB_ICONINFORMATION);
				break;
				}
		            if(MessageBox(GMhWnd,"确实要删除该短信吗?","收信箱",MB_YESNO|MB_ICONQUESTION)==IDNO)
            		     {          	
 					break;              		
            		    }	   
                 	    SendDlgItemMessage(GMhWnd,IDC_GM_LIST,LB_DELETESTRING,index_del,0);
                 	    i=0;
                 	    while(!feof(GetMsgFp))
                 	    {
                 	    	fread(&GetMsgTxt,sizeof(msg),1,GetMsgFp);
                 	    	strcpy(getMsgArry[i].number, GetMsgTxt.number );
				strcpy(getMsgArry[i].time, GetMsgTxt.time );
                 	    	strcpy(getMsgArry[i].txt, GetMsgTxt.txt );
                 	    	i++;
                 	    }
                 	    fclose(GetMsgFp);
                 	    for(j=0;j<i-1;j++)
                 	    {
                 	    	if(j==index_del)
                 	    		{
                 	    		   strcpy(getMsgArry[index_del].number,getMsgArry[index_del+1].number);
                 	    		   strcpy(getMsgArry[index_del].time,getMsgArry[index_del+1].time);
                 	    		   strcpy(getMsgArry[index_del].txt,getMsgArry[index_del+1].txt);
                 	    			 index_del++;	 
                 	    		}
                 	    }
                 	    GetMsgFp=fopen("data/GetMsg.txt","w");
                 	    rewind(GetMsgFp);
                 	    for(k=0;k<j-1;k++)
                 	    {
                 	    fwrite(&getMsgArry[k],sizeof(msg),1,GetMsgFp);
                 	    }
                 	    fclose(GetMsgFp);
                 	     return 0;	     
                 	     
         case MSG_DESTROY:
        	   DestroyAllControls(GMhWnd);
             return 0; 
        case MSG_CLOSE:
             DestroyMainWindow(GMhWnd);
             PostQuitMessage(GMhWnd);
	     	//emUnLoadBitmap ();
             return 0;
    }
    return DefaultMainWinProc(GMhWnd,message,wParam,lParam);
}
//^^^^^^^^^^^^^^^^^^^收信箱^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
int  GetMSG(HWND hWnd)
{
    MSG Msg;
    MAINWINCREATE CreateInfo;
    RegisterMyButtonControl ();
	
    CreateInfo.dwStyle=WS_VISIBLE | WS_BORDER | WS_CAPTION;
    CreateInfo.dwExStyle=WS_EX_NONE;
    CreateInfo.spCaption="收信箱";
    CreateInfo.hMenu=0;
    CreateInfo.hCursor=GetSystemCursor(IDC_ARROW);
    CreateInfo.hIcon=0;
    CreateInfo.MainWindowProc=GetMSGProc;
    CreateInfo.lx=0;
    CreateInfo.ty=0;
    CreateInfo.rx=320;
    CreateInfo.by=216;
    CreateInfo.iBkColor=GetWindowElementColor (BKC_CONTROL_DEF);
    CreateInfo.dwAddData=0;
    CreateInfo.hHosting=hWnd;

    LoadBitmap (HDC_SCREEN, &jpg_bkgnd_GM, "./image/background/bkgnd29.jpg");
    GMhWnd=CreateMainWindow(&CreateInfo); 
    ShowWindow(GMhWnd,SW_SHOWNORMAL);
    while(GetMessage(&Msg,GMhWnd)) 
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    MainWindowThreadCleanup(GMhWnd);
    UnloadBitmap (&jpg_bkgnd_GM);
    UnregisterMyButtonControl ();
    return 0;    
}

///////////////////////收信箱//////////////////////////////////////////////////
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?