editmessage.c

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

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

#define IDC_EMTXT_LIST 0X1003
#define IDC_EMBUT_CHANGE 0X1004#define IDC_EMBUT_DEL 0X1005#define IDC_EMBUT_RETURN 0X1006

/*static BITMAP ch_pushed;
static BITMAP ch_unpushed;
static BITMAP ch_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_EM;

HWND EMhWnd;//窗口句柄

HWND 	hCtrl_ch;
HWND 	hCtrl_del;
HWND 	hCtrl_return;
/*static void emLoadBitmap()
{
	LoadBitmap (HDC_SCREEN, &ch_pushed, "image/button/msg_ch_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &ch_unpushed, "image/button/msg_ch_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &ch_mousemove, "image/button/msg_ch_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 (&ch_pushed);
        UnloadBitmap (&ch_unpushed);
        UnloadBitmap (&ch_mousemove);

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

	 UnloadBitmap (&return_pushed);
        UnloadBitmap (&return_unpushed);
        UnloadBitmap (&return_mousemove);
}
*/
//////////////////////////草稿箱///////////////////////////////////////////////////
static void em_notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{		
	if ( hwnd == hCtrl_ch&& nc == MYBUTTON_PUSHED)
	{		
		//SetWindowAdditionalData(hwnd, (DWORD)&ch_pushed);
	}
	if ( hwnd == hCtrl_ch &&  nc == BN_CLICKED&&id==IDC_EMBUT_CHANGE)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&ch_unpushed);
		SendNotifyMessage(EMhWnd,IDC_EMBUT_CHANGE,0,0);
	}
	if( hwnd == hCtrl_ch && nc == MYBUTTON_MOUSEMOVE)
	{	
		//SetWindowAdditionalData(hwnd, (DWORD)&ch_mousemove);
	}
//-----------------------------------------------------------
	if ( hwnd == hCtrl_del&& nc == MYBUTTON_PUSHED)
	{		
		//SetWindowAdditionalData(hwnd, (DWORD)&del_pushed);
	}
	if ( hwnd == hCtrl_del && nc == BN_CLICKED&&id==IDC_EMBUT_DEL)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&del_unpushed);
		SendNotifyMessage(EMhWnd,IDC_EMBUT_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_EMBUT_RETURN)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
		SendNotifyMessage(EMhWnd,MSG_CLOSE,0,0);
	}
	if( hwnd == hCtrl_return && nc == IDC_EMBUT_RETURN)
	{	
		//SetWindowAdditionalData(hwnd, (DWORD)&return_mousemove );
	}
//---------------------------------------------------------------------------
	InvalidateRect (hwnd, NULL, TRUE);
}
/////////////////////
static int EditMSGProc(HWND EMhWnd, int message, WPARAM wParam, LPARAM lParam){
	Note telbook;
	int ifname = 0;
	  int i;	  int j;	  int k;	  static int index;	  static int index_del;
	  msg editMsgArry[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_EMTXT_LIST,20,30,180,135,EMhWnd,0); *///
              CreateWindowEx (CTRL_LISTBOX,
                    "",WS_VISIBLE | WS_VSCROLL | WS_HSCROLL|WS_BORDER | LBS_NOTIFY ,WS_EX_TRANSPARENT,
                    IDC_EMTXT_LIST,20,30,180,135,EMhWnd,0);
 				//hCtrl_ch = CreateWindowEx(CTRL_MYBUTTON, 
				//						"修改",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_EMBUT_CHANGE, 220,30,80,28, EMhWnd, (DWORD)&ch_unpushed);
				hCtrl_ch =CreateWindow ("button",
				                          "修改",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                          IDC_EMBUT_CHANGE,
				                          220,30,80,28,EMhWnd, 0);
				//hCtrl_del = CreateWindowEx(CTRL_MYBUTTON, 
				//						"删除",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_EMBUT_DEL, 220,80,80,28, EMhWnd, (DWORD)&del_unpushed);
				hCtrl_del =CreateWindow ("button",
                          "删除",
                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
                          IDC_EMBUT_DEL,
                          220,80,80,28, EMhWnd, 0);
			     //  hCtrl_return = CreateWindowEx(CTRL_MYBUTTON, 
				//						"返回",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_EMBUT_RETURN, 220,130,80,28, EMhWnd, (DWORD)&return_unpushed);
				hCtrl_return =CreateWindow ("button",
                          "返回",
                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
                          IDC_EMBUT_RETURN,
                          220,130,80,28,EMhWnd, 0);
			SetNotificationCallback ( hCtrl_ch, em_notify_proc );
			SetNotificationCallback ( hCtrl_del, em_notify_proc );
			SetNotificationCallback ( hCtrl_return, em_notify_proc );
			
		/*	EditMsgFp=fopen("data/EditMsg.txt","r");
	           	rewind(EditMsgFp);
			i=0;	
        		 while(!feof(EditMsgFp))
        		 {
        		 	 fread(&EditMsgTxt,sizeof(msg),1,EditMsgFp);
				strcat ( EditMsgTxt.number, "  " );
				strcat ( EditMsgTxt.number, &EditMsgTxt.time[4] );
        		 	 SendMessage(GetDlgItem(EMhWnd,IDC_EMTXT_LIST),LB_ADDSTRING,0,(LPARAM)EditMsgTxt.number);
        		 	 i++;
					 printf ("!!!!!!!!!i=%d\n",i);
        		 }
        		 SendDlgItemMessage(EMhWnd,IDC_EMTXT_LIST,LB_DELETESTRING,i,0);
        		 fclose(EditMsgFp);	
        		 */
			EditMsgFp=fopen("data/EditMsg.txt","r");
			TelBookFp=fopen("data/phonebook.dat","r");
	           	rewind(EditMsgFp);
			i=0;	
        		 while(!feof(EditMsgFp))
        		 {
        		 	 fread(&EditMsgTxt,sizeof(msg),1,EditMsgFp);
				rewind (TelBookFp);
				ifname = 0;
				while (!feof(TelBookFp))
				{
					fread (&telbook, sizeof(Note),1,TelBookFp);
					if ( strcmp ( EditMsgTxt.number, telbook.phone ) ==0 )
					{	strcpy ( listName, telbook.name );
						ifname = 1;
						break;
					}
					
				}
				if ( ifname == 0 )
				{
					strcpy ( listName, EditMsgTxt.number );
					strcat ( listName, "   ");
					strcat ( listName, &EditMsgTxt.time[4]  );
				}
				else if ( ifname == 1 )
				{
					strcat ( listName,"   ");
					strcat ( listName, &EditMsgTxt.time[4] );
				}
				SendMessage(GetDlgItem(EMhWnd,IDC_EMTXT_LIST),LB_ADDSTRING,0,(LPARAM)listName);
        		 	 i++;
					 printf ("!!!!!!!!!i=%d\n",i);
        		 }
        		 SendDlgItemMessage(EMhWnd,IDC_EMTXT_LIST,LB_DELETESTRING,i,0);
        		 fclose(EditMsgFp);	
			fclose (TelBookFp);												
             return 0;
    /* 		case MSG_PAINT:
				hdc = BeginPaint (EMhWnd);
				FillBoxWithBitmap (hdc,0, 0, 320, 192, &jpg_bkgnd_EM);
				EndPaint (EMhWnd,hdc);
				break;*/
			/*case MSG_MOUSEMOVE:
				SetWindowAdditionalData( hCtrl_ch, (DWORD)&ch_unpushed );
				InvalidateRect (hCtrl_ch, 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 (EMhWnd);
				fGetDC = TRUE;
	 		   }       
		    
	    		if (clip) {
				rcTemp = *clip;
				ScreenToClient (EMhWnd, &rcTemp.left, &rcTemp.top);
				ScreenToClient (EMhWnd, &rcTemp.right, &rcTemp.bottom);
				IncludeClipRect (hdc, &rcTemp);
	    		}

//	  		  FillBoxWithBitmap (hdc, rcTemp.left, rcTemp.top, 0, 0, &jpg_bkgnd_EM);
			FillBoxWithBitmap (hdc, 0, 0, 320, 192, &jpg_bkgnd_EM);
	    		if (fGetDC)
				ReleaseDC (hdc);
	 		   return 0;
                 case IDC_EMBUT_CHANGE:
			 EditMsgIndex = SendMessage (GetDlgItem(EMhWnd, IDC_EMTXT_LIST), LB_GETCURSEL, 0, 0); 
                 	   	 printf("editindex ==========%d\n",EditMsgIndex);
				
			 if ( EditMsgIndex<0 )
			   {
				MessageBox (EMhWnd,"无可读信息", "短信",MB_OK | MB_ICONINFORMATION);
				break;
			   }
			 EditMsgFp=fopen("data/EditMsg.txt","r");
			 while(EditMsgIndex+1)
			 	{
        		 	 fread(&EditMsgTxt,sizeof(msg),1,EditMsgFp);
					 EditMsgIndex--;
			 	}
			 fclose (EditMsgFp);
			 		newmsflag = 2;
				 	NewMSG(EMhWnd);
                 	    return 0;
                 case IDC_EMBUT_DEL:                    	    EditMsgFp = fopen("data/EditMsg.txt","r");
                 	    index_del = SendMessage (GetDlgItem(EMhWnd, IDC_EMTXT_LIST), LB_GETCURSEL, 0, 0);
			    if ( index_del < 0 )
			    	{
				MessageBox (EMhWnd,"无删除项!", "短信",MB_OK | MB_ICONINFORMATION);
				break;
				}
		            if(MessageBox(EMhWnd,"确实要删除该短信吗?","草稿箱",MB_YESNO|MB_ICONQUESTION)==IDNO)
            		     {          	
 					break;              		
            		    }
                 	    SendDlgItemMessage(EMhWnd,IDC_EMTXT_LIST,LB_DELETESTRING,index_del,0);
                 	    i=0;
                 	    while(!feof(EditMsgFp))
                 	    {
                 	    	fread(&EditMsgTxt,sizeof(msg),1,EditMsgFp);
                 	    	strcpy(editMsgArry[i].number, EditMsgTxt.number );
				strcpy(editMsgArry[i].time, EditMsgTxt.time );
                 	    	strcpy(editMsgArry[i].txt, EditMsgTxt.txt );
                 	    	i++;
                 	    }
                 	    fclose(EditMsgFp);
                 	    for(j=0;j<i-1;j++)
                 	    {
                 	    	if(j==index_del)
                 	    		{
                 	    		   strcpy(editMsgArry[index_del].number,editMsgArry[index_del+1].number);
                 	    		   strcpy(editMsgArry[index_del].time,editMsgArry[index_del+1].time);
                 	    		   strcpy(editMsgArry[index_del].txt,editMsgArry[index_del+1].txt);
                 	    			 index_del++;	 
                 	    		}
                 	    }
                 	    EditMsgFp=fopen("data/EditMsg.txt","w");
                 	    rewind(EditMsgFp);
                 	    for(k=0;k<j-1;k++)
                 	    {
                 	    fwrite(&editMsgArry[k],sizeof(msg),1,EditMsgFp);
                 	    }
                 	    fclose(EditMsgFp); 
                 	     return 0;	     
         case MSG_DESTROY:        	   DestroyAllControls(EMhWnd);             return 0;         case MSG_CLOSE:
	   //   emUnLoadBitmap ();
             DestroyMainWindow(EMhWnd);             PostQuitMessage(EMhWnd);
             return 0;    }    return DefaultMainWinProc(EMhWnd,message,wParam,lParam);}//^^^^^^^^^^^^^^^^^^^^^^草稿箱^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^int EditMSG(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=EditMSGProc;    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_EM, "./image/background/bkgnd29.jpg"); 
    EMhWnd=CreateMainWindow(&CreateInfo);     ShowWindow(EMhWnd,SW_SHOWNORMAL);
    while(GetMessage(&Msg,EMhWnd)) 
    {        TranslateMessage(&Msg);        DispatchMessage(&Msg);    }    MainWindowThreadCleanup(EMhWnd);
    UnloadBitmap (&jpg_bkgnd_EM);
    UnregisterMyButtonControl ();
    return 0; 	}

////////////////////////////////草稿箱//////////////////////////////////
#endif

⌨️ 快捷键说明

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