📄 picshow.c
字号:
static void switchstyle(HWND hWnd){ int full; cancelsel(hWnd); showstyle = (showstyle + 1) % 3; full = (showstyle + 1) * (showstyle + 1); if (showstyle) { int oldsel = cursel; cursel = (firstpic + cursel) % full; firstpic = (firstpic + oldsel) / full * full; disppic (hWnd, pichead + firstpic, DISPNUM); drawframe(hWnd); } else { firstpic = firstpic + cursel; cursel = 0; disppic (hWnd, pichead + firstpic, DISPNUM); }}static void OptMenu(HWND hwnd){ HDC hdc; dispmenu = 1; hdc = GetClientDC(hwnd); SetPenColor (hdc, RGB2Pixel (hdc, 250, 250, 250)); Rectangle(hdc, rcMenu[0].left, rcMenu[0].top, rcMenu[0].right, rcMenu[0].bottom); SetBkMode (hdc, BM_TRANSPARENT); SetTextColor (hdc, RGB2Pixel(hdc, 250, 250, 250));//#ifdef MGDEMO_ENGLISH
// TextOut (hdc, rcMenu[1].left + 5, rcMenu[1].top, "Information");
// TextOut (hdc, rcMenu[2].left + 5, rcMenu[2].top, "Delete");
// TextOut (hdc, rcMenu[3].left + 5, rcMenu[3].top, "as Wallpaper");
//#else
TextOut (hdc, rcMenu[1].left + 5, rcMenu[1].top, "信息"); TextOut (hdc, rcMenu[2].left + 5, rcMenu[2].top, "删除"); TextOut (hdc, rcMenu[3].left + 5, rcMenu[3].top, "存储为壁纸");//#endif ReleaseDC(hdc);}static void cancelmenu(HWND hwnd){ int w = rcMenu[0].right - rcMenu[0].left + 1, h = rcMenu[0].bottom - rcMenu[0].top + 1; RECT *rect = NULL; HDC hdc; hdc = GetClientDC(hwnd); BitBlt(mdc, rcMenu[0].left, rcMenu[0].top, w, h, hdc, rcMenu[0].left, rcMenu[0].top, 0); if (showstyle == 0) goto exit; else if (showstyle == 1) rect = frame2x2; else if (showstyle == 2) rect = frame3x3; SetPenColor (hdc, RGB2Pixel(hdc, 255, 255, 255)); Rectangle (hdc, rect[cursel].left - 1, rect[cursel].top - 1, rect[cursel].right + 1, rect[cursel].bottom + 1);exit: ReleaseDC(hdc); dispmenu = 0;}static void selmenuopt(HWND hwnd, int x, int y){ int i; if (!dispmenu) return; for (i = 1; i < 4; i++) { if (PtInRect(&rcMenu[i], x, y)) { switch (i) { case 1://#ifdef MGDEMO_ENGLISH// printf("Information");//#else printf("信息");//#endif break; case 2://#ifdef MGDEMO_ENGLISH// printf("Delete");//#else printf("删除");//#endif break; case 3://#ifdef MGDEMO_ENGLISH// printf("save as Wallpaper");//#else printf("存储为壁纸");//#endif break; } break; } }}static void hideface(HWND hwnd){ HDC hdc; RECT *rect = NULL; hdc = GetClientDC(hwnd); BitBlt(mdc, 0, 0, 320, 240, hdc, 0, 0, 0); hidemenu = 1; if (showstyle == 0) goto exit; else if (showstyle == 1) rect = frame2x2; else if (showstyle == 2) rect = frame3x3; SetPenColor (hdc, RGB2Pixel(hdc, 250, 250, 250)); Rectangle (hdc, rect[cursel].left - 1, rect[cursel].top - 1, rect[cursel].right + 1, rect[cursel].bottom + 1);exit: ReleaseDC(hdc);}static void pictureshow_button_deal (HWND hWnd, int index){ switch (index) { case 0: switchstyle(hWnd); InvalidateRect (hWnd, &rcButton [0], FALSE); if (dispmenu) cancelmenu(hWnd); break; case 1: if (!dispmenu) OptMenu(hWnd); break; case 2: hideface(hWnd); if (dispmenu) cancelmenu(hWnd); break; }}static void pictureshow_deal_click (HWND hWnd, int x, int y){ int i; if (dispmenu) { cancelmenu(hWnd); return; } for (i = 0; i < 3; i++) { if (PtInRect (&rcButton [i], x, y)) { pictureshow_button_deal (hWnd, i); break; } }}static void refreshmenu(HDC hdc){ int i;//#ifdef MGDEMO_ENGLISH// const char *chStyle[] = {"Single", "2x2 Mode", "3x3 Mode"};//#else const char *chStyle[] = {"单 幅", "2x2格式", "3x3格式"};//#endif char *picname = pichead[firstpic + cursel]; if (hidemenu) return; SetBkMode (hdc, BM_TRANSPARENT); SetPenColor (hdc, RGB2Pixel (hdc, 250, 250, 250)); for (i = 0; i < 3; i++) Rectangle (hdc, rcButton [i].left, rcButton [i].top, rcButton [i].right, rcButton [i].bottom); if (showstyle < 0 || showstyle > 2) return; SetTextColor (hdc, RGB2Pixel(hdc, 250, 250, 250)); TextOut (hdc, 30, 220, chStyle[showstyle]);//#ifdef MGDEMO_ENGLISH
// TextOut (hdc, 146, 220, "Option");
// TextOut (hdc, 250, 220, "Hide");
//#else
TextOut (hdc, 146, 220, "选项"); TextOut (hdc, 250, 220, "隐藏");//#endif //BitBlt (mdc, 0, 4, 320, 12, hdc, 0, 4, 0); DrawText(hdc, picname, -1, &rcButton[3], DT_CENTER);}void initjpeg(HWND hwnd){ HDC hdc; hdc = GetClientDC(hwnd); mdc = CreateCompatibleDCEx(hdc, 320, 240); ReleaseDC(hdc);}static int pictureshowWinProc (HWND hWnd, int message, WPARAM wparam, LPARAM lparam){ switch (message){ case MSG_CREATE: initframe(); initjpeg(hWnd); disppic(hWnd, pichead + firstpic, DISPNUM); break; case MSG_ACTIVE: return 0; case MSG_SHOWWINDOW: return 0; case MSG_SIZECHANGING: { RECT* rcResult = (RECT*)lparam; rcResult->top = 0; rcResult->left = 0; rcResult->right = 320; rcResult->bottom = 240; return 0; } case MSG_CLOSE: hidemenu = 0; DeleteMemDC(mdc); DestroyAllControls(hWnd); DestroyMainWindow(hWnd); break; case MSG_PAINT: { HDC hDC; hDC = BeginPaint (hWnd); refreshmenu(hDC); EndPaint (hWnd, hDC); return 0; } case MSG_KEYDOWN: switch (wparam) { case SCANCODE_F1: pictureshow_button_deal (hWnd, 0); break; case SCANCODE_F2: if (hidemenu) { hidemenu = 0; InvalidateRect(hWnd, NULL, FALSE); } pictureshow_button_deal (hWnd, 1); break; case SCANCODE_F3: if (hidemenu) { hidemenu = 0; InvalidateRect(hWnd, NULL, FALSE); } else pictureshow_button_deal (hWnd, 2); break; case SCANCODE_CURSORBLOCKRIGHT: lfsel(hWnd, 1); break; case SCANCODE_CURSORBLOCKLEFT: lfsel(hWnd, 0); break; case SCANCODE_CURSORBLOCKUP: updownsel(hWnd, 0); break; case SCANCODE_CURSORBLOCKDOWN: updownsel(hWnd, 1); break; case SCANCODE_ENTER: case SCANCODE_KEYPADENTER: if (dispmenu) { cancelmenu(hWnd); return 0; } else fullpic(hWnd); break; case SCANCODE_ESCAPE: if (dispmenu) { cancelmenu(hWnd); return 0; } SendMessage(hWnd, MSG_CLOSE, 0, 0); break; } break; case MSG_LBUTTONDOWN: { int x = LOWORD(lparam); int y = HIWORD(lparam); mousesel(hWnd, x, y); selmenuopt(hWnd, x, y); if (hidemenu) { hidemenu = 0; InvalidateRect(hWnd, NULL, FALSE); } else pictureshow_deal_click (hWnd, x, y); break; } case MSG_COMMAND: { break; } } return DefaultMainWinProc (hWnd, message, wparam, lparam);}static int init_create_pictureshow_win (HWND hHosting){ MAINWINCREATE CreateInfo; HWND hWnd; CreateInfo.dwStyle = WS_VISIBLE; CreateInfo.spCaption = ""; CreateInfo.dwExStyle = WS_EX_TOPMOST; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor(0); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = pictureshowWinProc; CreateInfo.lx = 0; CreateInfo.ty = 0; CreateInfo.rx = 320; CreateInfo.by = 240; //CreateInfo.iBkColor = RGB2Pixel (HDC_SCREEN, 0x86, 0x99, 0xcc); //CreateInfo.iBkColor = RGB2Pixel (HDC_SCREEN, 198, 205, 242); CreateInfo.iBkColor = RGB2Pixel(HDC_SCREEN, 0, 0, 0); CreateInfo.dwAddData = 0; CreateInfo.hHosting = hHosting; hWnd = CreateMainWindow(&CreateInfo); if(hWnd == HWND_INVALID) { printf ("--------create_pictureshow_win failure\n"); return 1; } hPictureShow = hWnd; ShowWindow(hWnd, SW_SHOWNORMAL); return 0;}void create_pictureshow_win(HWND hWnd, char **picname, int pic, int count){ firstpic = pic; picnum = count; cursel = 0; pichead = picname; showstyle = 0; init_create_pictureshow_win(hWnd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -