⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notepadshow.c

📁 minigui PDA系统 可实现手机功能
💻 C
字号:
#include <stdio.h> 
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <string.h>
#include "notepad.h"
#include "../../mybuttonreg.h"
#define IDC_TOOLS_NOTEPAD_SHOW_STATIC_TITLE			720
#define IDC_TOOLS_NOTEPAD_SHOW_STATIC_TEXT			721
#define IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TITLE			722
#define IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TEXT			723
#define IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK		724
#define IDC_TOOLS_NOTEPAD_SHOW_BUTTON_QUIT			725
#define MSG_NOTEPAD_ADD				1114
//#define NOTEPADDAT	"/data/notepad.dat" 

static BITMAP rework_pushed;
static BITMAP rework_unpushed;
static BITMAP rework_mousemove;

static BITMAP quit_pushed;
static BITMAP quit_unpushed;
static BITMAP quit_mousemove;

static BITMAP jpg_bkgnd_NS;

HWND hNoteShow;
HWND hCtrl_rework;
HWND hCtrl_quit;

static void emNSLoadBitmap()
{
	LoadBitmap (HDC_SCREEN, &rework_pushed, "image/button/tool_rework_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &rework_unpushed, "image/button/tool_rework_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &rework_mousemove, "image/button/tool_rework_mousemove.jpg");	
	   
	LoadBitmap (HDC_SCREEN, &quit_pushed, "image/button/tool_quit_pushed.jpg");
       LoadBitmap (HDC_SCREEN, &quit_unpushed, "image/button/tool_quit_unpushed.jpg");
       LoadBitmap (HDC_SCREEN, &quit_mousemove, "image/button/tool_quit_mousemove.jpg");
	   
}
static void emNSUnLoadBitmap()
{
	 UnloadBitmap (&rework_pushed);
        UnloadBitmap (&rework_unpushed);
        UnloadBitmap (&rework_mousemove);
		
	 UnloadBitmap (&quit_pushed);
        UnloadBitmap (&quit_unpushed);
        UnloadBitmap (&quit_mousemove);
}
static void NoteShow_notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{		
	if ( hwnd == hCtrl_rework&& nc == MYBUTTON_PUSHED)
	{		
		//SetWindowAdditionalData(hwnd, (DWORD)&rework_pushed);
	}
	if ( hwnd == hCtrl_rework && nc == BN_CLICKED&&id==IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&rework_unpushed);
		SendNotifyMessage(hNoteShow,IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK,0,0);
	}
	if( hwnd == hCtrl_rework && nc == MYBUTTON_MOUSEMOVE)
	{	
		//SetWindowAdditionalData(hwnd, (DWORD)&rework_mousemove);
	}
	//-----------------------------------------------------------
	if ( hwnd == hCtrl_quit&& nc == MYBUTTON_PUSHED)
	{		
		//SetWindowAdditionalData(hwnd, (DWORD)&quit_pushed);
	}
	if ( hwnd == hCtrl_quit && nc == BN_CLICKED&&id==IDC_TOOLS_NOTEPAD_SHOW_BUTTON_QUIT)
	{
		//SetWindowAdditionalData(hwnd, (DWORD)&quit_unpushed);
		SendNotifyMessage(hNoteShow,MSG_CLOSE,0,0);
	}
	if( hwnd == hCtrl_quit && nc == MYBUTTON_MOUSEMOVE)
	{	
		//SetWindowAdditionalData(hwnd, (DWORD)&quit_mousemove );
	}
//-----------------------------------------------------------
	InvalidateRect (hwnd, NULL, TRUE);
}
//------------------------------------------------------
int place;
int size;
HWND fWnd;
FILE *fp;

static int Notepad_Show(HWND hWnd)
{
	if((fp=fopen(NOTEPADDAT,"r"))==NULL)
	{
		MessageBox(hWnd,"the file open failed","",MB_OK | MB_ICONINFORMATION);
 		return;
	}	

	fread(notepad,sizeof(struct NOTEPAD),1000,fp);
	
	SetWindowText(GetDlgItem(hWnd,IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TITLE),notepad[place].topic);
	SetWindowText(GetDlgItem(hWnd,IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TEXT),notepad[place].content);
		
	fclose(fp);
}

static int Notepad_Rework(HWND hWnd)
{
	if((fp = fopen(NOTEPADDAT,"r"))==NULL)
	{
		MessageBox(hWnd,"the file open failed","",MB_OK | MB_ICONINFORMATION);
 		return;
	}
	
	size = fread(notepad,sizeof(struct NOTEPAD),1000,fp);
	fclose(fp);
	
	GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TITLE),notepad[place].topic,sizeof(notepad[place].content));
 	GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TEXT),notepad[place].content,sizeof(notepad[place].content)); 

	if((strlen(notepad[place].topic)>50) || (strlen(notepad[place].topic)== 0))
	{
		MessageBox(hWnd,"请输入正确的标题","",MB_OK | MB_ICONINFORMATION);
		return;
	}	

	if(strlen(notepad[place].content)>200)
	{
		MessageBox(hWnd,"内容超出范围","",MB_OK | MB_ICONINFORMATION);
		return;
	}

	if((fp = fopen(NOTEPADDAT,"w"))==NULL)
	{
		MessageBox(hWnd,"the file open failed","",MB_OK | MB_ICONINFORMATION);
 		return;
	}	

	fwrite(notepad,sizeof(struct NOTEPAD),size,fp);	
	fclose(fp);

	SendNotifyMessage(fWnd,MSG_NOTEPAD_ADD,0,0L);
}

static int NoteShowProc(HWND hNoteShow, int message, WPARAM wParam, LPARAM lParam)
{
	    HDC hdc = (HDC)wParam;
	    const RECT* clip = (const RECT*) lParam;
	    BOOL fGetDC = FALSE;
	    RECT rcTemp;
    	switch (message) 
    	{
	    	case MSG_CREATE:
		{
			//emNSLoadBitmap();
				CreateWindow (CTRL_STATIC,
					"标题:",
					WS_VISIBLE | SS_CENTER,
					IDC_TOOLS_NOTEPAD_SHOW_STATIC_TITLE,
					10, 10, 40, 20,
					hNoteShow,
					0);

				CreateWindow (CTRL_STATIC,
					"内容:",
					WS_VISIBLE | SS_CENTER,
					IDC_TOOLS_NOTEPAD_SHOW_STATIC_TEXT,
					10, 40, 40, 20,
					hNoteShow,
					0);

				CreateWindow (CTRL_SLEDIT,
					"",
					WS_VISIBLE | WS_TABSTOP | WS_BORDER,
					IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TITLE,
					50, 10, 150, 20,
					hNoteShow,
					0);
	
				CreateWindow (CTRL_MLEDIT,
					"",
					WS_VISIBLE | ES_AUTOWRAP| WS_VSCROLL,
					IDC_TOOLS_NOTEPAD_SHOW_SLEDIT_TEXT,
					50, 40, 150, 110,
					hNoteShow,
					0);
         /*   hCtrl_rework= CreateWindowEx(CTRL_MYBUTTON, 
								 "修改",
								WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,
								IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK,
								240, 20, 60, 25,
								hNoteShow,
								(DWORD)&rework_unpushed);*/
		hCtrl_rework =CreateWindow ("button",
				                          "修改",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                          IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK,
								240, 20, 60, 25,
								hNoteShow, 0);

         /*   hCtrl_quit= CreateWindowEx(CTRL_MYBUTTON, 
								 "返回",
								WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,
								IDC_TOOLS_NOTEPAD_SHOW_BUTTON_QUIT,
								240, 70, 60, 25,
								hNoteShow,
								(DWORD)&quit_unpushed);*/
		hCtrl_quit =CreateWindow ("button",
				                          "返回",
				                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
				                         IDC_TOOLS_NOTEPAD_SHOW_BUTTON_QUIT,
								240, 70, 60, 25,
								hNoteShow,0);
			
		SetNotificationCallback ( hCtrl_rework, NoteShow_notify_proc);
		SetNotificationCallback ( hCtrl_quit, NoteShow_notify_proc );
				Notepad_Show(hNoteShow);	
		}
		break;
			case MSG_MOUSEMOVE:
				//SetWindowAdditionalData( hCtrl_rework, (DWORD)&rework_unpushed );
				InvalidateRect (hCtrl_rework, NULL, TRUE);
				//SetWindowAdditionalData( hCtrl_quit, (DWORD)&quit_unpushed );
				InvalidateRect (hCtrl_quit, NULL, TRUE);
				break;
		case MSG_ERASEBKGND:
	    		if (hdc == 0) {
				hdc = GetClientDC (hNoteShow);
				fGetDC = TRUE;
	 		   }       
		    
	    		if (clip) {
				rcTemp = *clip;
				ScreenToClient (hNoteShow, &rcTemp.left, &rcTemp.top);
				ScreenToClient (hNoteShow, &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_NS);
	    		if (fGetDC)
				ReleaseDC (hdc);
	 		   return 0;
	//-----------------------------------------------------------			
				case IDC_TOOLS_NOTEPAD_SHOW_BUTTON_REWORK:
					Notepad_Rework(hNoteShow);
					//emNSUnLoadBitmap();
					DestroyMainWindow (hNoteShow);
       	 				PostQuitMessage (hNoteShow);
					break;
	
//---------------------------------------------------------------	
	
    		case MSG_CLOSE:
		{	
				//emNSUnLoadBitmap();
       	 		DestroyMainWindow (hNoteShow);
       	 		PostQuitMessage (hNoteShow);
        			return 0;
		}
    	}
    	return DefaultMainWinProc(hNoteShow, message, wParam, lParam);
}


static int NotepadShow(HWND hNote,int index)
{
    	MSG Msg;
    	MAINWINCREATE CreateInfo;
	RegisterMyButtonControl ();
	place = index;
	CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE;
    	CreateInfo.dwExStyle = WS_EX_NONE;
    	CreateInfo.spCaption = "查看记事本";
    	CreateInfo.hMenu = 0;
    	CreateInfo.hCursor = GetSystemCursor(IDC_ARROW);
    	CreateInfo.hIcon = 0;
    	CreateInfo.MainWindowProc = NoteShowProc;
    	CreateInfo.lx = 0; 
    	CreateInfo.ty = 0;
    	CreateInfo.rx = 320;
    	CreateInfo.by = 216;
    	CreateInfo.iBkColor = GetWindowElementColor (BKC_CONTROL_DEF);
    	CreateInfo.dwAddData = 0;
    	CreateInfo.hHosting=hNote;  
		LoadBitmap (HDC_SCREEN, &jpg_bkgnd_NS, "./image/background/bkgnd29.jpg"); 
    	hNoteShow=CreateMainWindow(&CreateInfo); 
    	ShowWindow(hNoteShow,SW_SHOWNORMAL);
    	while(GetMessage(&Msg,hNoteShow)) 
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    	MainWindowThreadCleanup(hNoteShow);
		UnloadBitmap (&jpg_bkgnd_NS);
	UnregisterMyButtonControl ();
    	return 0;    
}



⌨️ 快捷键说明

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