📄 telpanel.c
字号:
#include "telpanel.h"static BITMAP bkgnd;static char *xmBmpName[]={"DL.png","TA.png","OA.png","NA.png", "RD.png", "RT.png"};static char *xmTitle[]={"拨打电话","已拨电话","已接来电","未接来电","通话记录","返 回"};static XMBUTTON xmButton [BTM_NUM];static int myLoadBitmap (BITMAP* bm, const char* filename){ char full_path [MAX_PATH + 1]; #ifndef _PASS#define _PASS strcpy (full_path, "./image/telpanel/"); strcat (full_path, filename); #endif return LoadBitmap (HDC_SCREEN, bm, full_path);}static int WhichBox(int x,int y){ int i; for (i=0;i<BTM_NUM;i++) { if ((x>xmButton[i].x)&&(x<xmButton[i].x+xmButton[i].w) &&(y>xmButton[i].y)&&(y<xmButton[i].y+xmButton[i].h)) return i; } return -1;}static int changeMode(HWND hWnd,int x,int y,int mode){ int btm=WhichBox(x,y); int i; RECT rect; static int lastbtm=-1; static int lastmode=BTM_FLAT; if ((btm==lastbtm)&&(mode==lastmode)) return btm; for (i=0;i<BTM_NUM;i++) { if(xmButton[i].mode==BTM_FLAT) continue; xmButton[i].mode=BTM_FLAT; rect.left=xmButton[i].x; rect.right=xmButton[i].x+xmButton[i].w; rect.top=xmButton[i].y; rect.bottom=xmButton[i].y+xmButton[i].h; InvalidateRect(hWnd,&rect,FALSE); } if (btm!=-1) { xmButton[btm].mode=mode; rect.left=xmButton[btm].x; rect.right=xmButton[btm].x+xmButton[btm].w; rect.top=xmButton[btm].y; rect.bottom=xmButton[btm].y+xmButton[btm].h; InvalidateRect(hWnd,&rect,FALSE); } if(btm!=lastbtm) InvalidateRect(hWnd,&rect,FALSE); lastbtm = btm; lastmode = mode; return btm; }static int TelPanelProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ static int lastdown=-1; switch (message) { case MSG_CREATE: { } break; case MSG_LBUTTONDOWN: { lastdown = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_DOWN ); //InvalidateRect(hWnd,NULL,FALSE); } break; case MSG_LBUTTONUP: { int up = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_FLAT ); //InvalidateRect(hWnd,NULL,FALSE); if(up==-1) break; if(up==lastdown) { switch(up) { case IDC_BUTTON_DL : DialDialog(hWnd); break ; case IDC_BUTTON_TA : TelAlreadyDialog(hWnd); break ; case IDC_BUTTON_OA: OkAnswerDialog(hWnd); break ; case IDC_BUTTON_NA: NotAnswerDialog(hWnd); break ; case IDC_BUTTON_RD: RecordDialog(hWnd); break ; case IDC_BUTTON_RT : DestroyMainWindow (hWnd); PostQuitMessage (hWnd); break ; } } } break; case MSG_MOUSEMOVE: { changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_UP ); //InvalidateRect (hWnd,NULL,FALSE); } break; case MSG_PAINT: { HDC hdc; RECT rc; int i; hdc = BeginPaint (hWnd); GetWindowRect(hWnd,&rc); FillBoxWithBitmap (hdc,0, 0, 320, 206, &bkgnd); for(i=0;i<BTM_NUM;i++) { if(xmButton[i].mode == BTM_UP) Draw3DUpThickFrame (hdc, xmButton[i].x, xmButton[i].y , xmButton[i].x+xmButton[i].w,xmButton[i].y+xmButton[i].h, PIXEL_black); else if(xmButton[i].mode == BTM_DOWN) Draw3DDownThickFrame (hdc, xmButton[i].x, xmButton[i].y , xmButton[i].x+xmButton[i].w,xmButton[i].y+xmButton[i].h, PIXEL_black); FillBoxWithBitmap (hdc, xmButton[i].x+xmButton[i].bmpx, xmButton[i].y+xmButton[i].bmpy, 0, 0, &xmButton[i].bitmap); SetBkMode(hdc, BM_TRANSPARENT); //这两个函数如果不放在这的话背景图片显示有问题 SetTextColor(hdc, PIXEL_red); TextOut(hdc,xmButton[i].x+xmButton[i].titlex,xmButton[i].y+xmButton[i].titley, xmButton[i].title); } EndPaint (hWnd,hdc); } return 0; case MSG_CLOSE: { int i; for(i=0;i<BTM_NUM;i++) UnloadBitmap(&(xmButton[i].bitmap)); UnloadBitmap(&bkgnd); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } } return DefaultMainWinProc (hWnd, message, wParam, lParam);}static void initBTMs(void){ int i,j; for(i=0;i<BTM_NUM;i++) { xmButton[i].x=20+(i%3)*105; xmButton[i].y=3+((int)(i/3))*100; xmButton[i].h=81; //设置高亮框的高度 xmButton[i].w=67; //设置高亮框的宽度 xmButton[i].bmpx=3; //图片在高亮框中的相对定点x,y坐标 xmButton[i].bmpy=2; strcpy(xmButton[i].title,xmTitle[i]); j=strlen(xmButton[i].title); xmButton[i].titlex=(9-j)*3; xmButton[i].titley=64; myLoadBitmap (&(xmButton[i].bitmap),xmBmpName [i]); }}static void InitTelPanelInfo (PMAINWINCREATE pCreateInfo, HWND hWnd){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE ; pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE;; pCreateInfo->spCaption = "手机通讯"; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = TelPanelProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = 320; pCreateInfo->by = 216; pCreateInfo->iBkColor = PIXEL_lightwhite; pCreateInfo->dwAddData = (DWORD)0; pCreateInfo->hHosting = hWnd;}int TelPanel(HWND hWnd){ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd; initBTMs(); InitTelPanelInfo (&CreateInfo, hWnd); if (LoadBitmap (HDC_SCREEN, &bkgnd, "./image/background/bkgnd29.jpg"))//HDC_SCREEN:屏幕设备,加载图片必须在CreateMainWindow(&CreateInfo)之前 return -1; hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; while( GetMessage(&Msg, hMainWnd) ) { TranslateMessage(&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -