iconbar.c

来自「提供了zip压缩解压缩的源代码 对于需要这方面的朋友希望有用」· C语言 代码 · 共 559 行 · 第 1/2 页

C
559
字号
        (HMENU) NULL,        (HINSTANCE) hInst,        NULL);WinAssert(hWndButtonBar);ShowWindow(hWndButtonBar, SW_SHOW);GetClientRect(hWndButtonBar, &rect);Height = rect.bottom;BtnSeparator = 1;   /* Set distance between buttons back to 1 */BtnMult = (float)BTNWIDTH; /* Reset multiplier to original setting */Width = (int)(BtnMult*dxChar);WinAssert(hWndParent);#ifdef RESIZE_BUTTONSGetClientRect(hWndParent, &rect);if (((Width * NUMOFBUTTONS) + NUMOFBUTTONS) > rect.right)   {   while (BtnMult > MIN_BTN_WIDTH)      {      BtnMult = (float)(BtnMult - 0.1);      Width = (int)(BtnMult*dxChar);      if (((Width * NUMOFBUTTONS) + NUMOFBUTTONS) < rect.right)         continue;      }   }/* Last ditch effort to get all the buttons on the screen */if (((Width * NUMOFBUTTONS) + NUMOFBUTTONS) > rect.right)   {   BtnSeparator = 0;   }#endifx = BtnSeparator;for (lpIB = lpButton; lpIB->idBtn != 0; lpIB++)    {    if (lpIB->idBtn == -1)       continue;    (lpIB->hWndBtn) = CreateWindow("BUTTON", "",                      WS_VISIBLE | BS_OWNERDRAW | WS_CHILD,                      x, 0,                      Width, Height,                      hWndButtonBar,                      (HMENU) lpIB->idBtn, (HINSTANCE) hInst, NULL );    SubClassButton (lpIB->hWndBtn, SubClassBtnProc);    x += Width + BtnSeparator;    }/* WARNING: The order here MUST be the same order as is used above   where the various buttons are created, otherwise you will   get strange results as buttons are given different handles than   intended. */i = 0;hArchive       = Buttons[i++].hWndBtn;hOpen          = Buttons[i++].hWndBtn;hExtract       = Buttons[i++].hWndBtn;hUnzipToDir    = Buttons[i++].hWndBtn;hSelectAll     = Buttons[i++].hWndBtn;hDeselectAll   = Buttons[i++].hWndBtn;hSelectPattern = Buttons[i++].hWndBtn;#ifdef MAX_BUTTONShDisplay       = Buttons[i++].hWndBtn;hTest          = Buttons[i++].hWndBtn;hZipInfo       = Buttons[i++].hWndBtn;hShowComment   = Buttons[i++].hWndBtn;hCopyArchive   = Buttons[i++].hWndBtn;hMoveArchive   = Buttons[i++].hWndBtn;hRenameArchive = Buttons[i++].hWndBtn;hMakeDir       = Buttons[i++].hWndBtn;#endifhDeleteArchive = Buttons[i++].hWndBtn;hClearStatus   = Buttons[i++].hWndBtn;hStatusButton  = Buttons[i++].hWndBtn;hExit          = Buttons[i++].hWndBtn;hHelp          = Buttons[i].hWndBtn;return;}void MoveButtons(void){int x = BtnSeparator;for (lpIB = Buttons; lpIB->idBtn != 0; lpIB++)    {    WinAssert(lpIB->hWndBtn);    MoveWindow(lpIB->hWndBtn, x, 0, Width, Height, FALSE);    x += Width + BtnSeparator;    }}LRESULT WINAPI ButtonBarWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){HPEN             hPen, hOldPen;HBRUSH           hBrush;LPDRAWITEMSTRUCT lpdis;HDC              hdcMem;HBITMAP          hBitmap;long             flag;int              i;switch(message)   {   case WM_COMMAND:        SendMessage(hWndButtonBarOwner, message, wParam, lParam);        return(FALSE);   case WM_DRAWITEM:        lpdis = (LPDRAWITEMSTRUCT) lParam;        lpIB = Buttons;        for (i=0;;i++)           {           if (lpIB[i].idBtn == 0)               return (FALSE); /* Not one of our controls */           if (lpIB[i].idBtn == (signed int)lpdis->CtlID)               break;          /* Found the right control */           }        if (lpIB[i].idBtn == IDM_STATUS)           {           if (!lstrcmp(lpIB[i].hBMP, "STATUS_BUTTON\0"))              {              lpIB[i].ButtonHelp = "Hide Edit/Status Window\0";              lpIB[i].hBMP = "LTSTATUS_BUTTON\0";              ModifyMenu(hMenu, IDM_MAX_STATUS, MF_BYCOMMAND |                 MF_ENABLED, IDM_MAX_STATUS,                 "Hide Edit/Status Window");              /* If we do a ShowWindow(hWndStatic, SW_SHOWNA) (which is what                 you would expect to do), if you hide, then unhide the status                 window, then minimize the main application, the status                 window will remain up. Hence this little tap dance here.               */                ShowWindow(hWndStatic, SW_SHOW);              SetActiveWindow(hWndMain);              }           else              {              lpIB[i].ButtonHelp = "Show Edit/Status Window\0";              lpIB[i].hBMP = "STATUS_BUTTON\0";              ModifyMenu(hMenu, IDM_MAX_STATUS, MF_BYCOMMAND |                 MF_ENABLED, IDM_MAX_STATUS,                 "Show Edit/Status Window");              ShowWindow(hWndStatic, SW_HIDE);              }           }        lpdis->rcItem.right = Width;        lpdis->rcItem.bottom = Height;        lpdis->rcItem.right--;        lpdis->rcItem.bottom--;        hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));        FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);        DeleteObject(hBrush);        hOldPen = SelectObject(lpdis->hDC, GetStockObject(BLACK_PEN));        MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top, NULL);        LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);        LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.bottom);        LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom);        LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);        SelectObject(lpdis->hDC, hOldPen);        lpdis->rcItem.left++;        lpdis->rcItem.right--;        lpdis->rcItem.top++;        lpdis->rcItem.bottom--;        if (!IsWindowEnabled(lpIB[i].hWndBtn))           {           flag = SRCINVERT;  /* "Gray" out button */           }        else           {           flag = SRCCOPY;           }        if (lpdis->itemState & ODS_SELECTED)           {           /* Button has been depressed - make it look depressed */           hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);           hOldPen = SelectObject(lpdis->hDC, hPen);           MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);           LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);           LineTo(lpdis->hDC, lpdis->rcItem.right, lpdis->rcItem.top);           SelectObject(lpdis->hDC, hOldPen);           DeleteObject(hPen);           hdcMem = CreateCompatibleDC(lpdis->hDC);           hBitmap = LoadBitmap(hInst, lpIB[i].hBMP);           hOldPen = SelectObject(hdcMem, hBitmap);           StretchBlt(lpdis->hDC,   /* device to be drawn */              lpdis->rcItem.left+2, /* x upper left destination */              lpdis->rcItem.top+2,  /* y upper left destination */              lpdis->rcItem.right - lpdis->rcItem.left -2, /* width */              lpdis->rcItem.bottom - lpdis->rcItem.top - 2,/* height */              hdcMem, /* source bitmap */              0,      /* x upper left source */              0,      /* y upper left source */              32,     /* source bitmap width */              32,     /* source bitmap height */              flag);           SelectObject(hdcMem, hOldPen);           DeleteDC(hdcMem);           DeleteObject(hBitmap);           }        else           {           if (lpIB[i].idBtn == IDM_STATUS)              {              if (!lstrcmp(lpIB[i].hBMP, "STATUS_BUTTON\0"))                 lpIB[i].hBMP = "LTSTATUS_BUTTON\0";              else                 lpIB[i].hBMP = "STATUS_BUTTON\0";              }           /* Draw button */           hOldPen = SelectObject(lpdis->hDC, GetStockObject(WHITE_PEN));           MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);           LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);           LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);           SelectObject(lpdis->hDC, hOldPen);           hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);           hOldPen = SelectObject(lpdis->hDC, hPen);           MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);           LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.bottom);           LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);           SelectObject(lpdis->hDC, hOldPen);           DeleteObject(hPen);           hdcMem = CreateCompatibleDC(lpdis->hDC);           hBitmap = LoadBitmap(hInst, lpIB[i].hBMP);           hOldPen = SelectObject(hdcMem, hBitmap);           StretchBlt(lpdis->hDC,              lpdis->rcItem.left+2,              lpdis->rcItem.top+2,              lpdis->rcItem.right - lpdis->rcItem.left -2,              lpdis->rcItem.bottom - lpdis->rcItem.top - 2,              hdcMem,              0,              0,              32,              32,              flag); /* This flag makes it look either enabled or greyed */           SelectObject(hdcMem, hOldPen);           DeleteDC(hdcMem);           DeleteObject(hBitmap);           }        return TRUE;/* This section draws a line around the button bar to highlight. It was decided   to take this out from the application, but the code is left here for those   who want this feature.              case WM_PAINT:        {        RECT             rect;        PAINTSTRUCT      ps;                BeginPaint(hWnd, &ps);        WinAssert(hWnd);        GetClientRect(hWnd, &rect);        hOldPen = SelectObject(ps.hdc, GetStockObject(WHITE_PEN));        MoveToEx(ps.hdc, rect.left, rect.top, NULL);        LineTo(ps.hdc, rect.right+1, rect.top);        SelectObject(ps.hdc, hOldPen);        hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);        hOldPen = SelectObject(ps.hdc, hPen);        MoveToEx(ps.hdc, rect.left, rect.bottom-2, NULL);        LineTo(ps.hdc, rect.right+1, rect.bottom-2);        SelectObject(ps.hdc, hOldPen);        DeleteObject(hPen);        hPen = CreatePen( PS_SOLID, 1, BLACK_PEN);        hOldPen = SelectObject(ps.hdc, hPen);        MoveToEx(ps.hdc, rect.left, rect.bottom-1, NULL);        LineTo(ps.hdc, rect.right+1, rect.bottom-1);        SelectObject(ps.hdc, hOldPen);        DeleteObject(hPen);        EndPaint(hWnd, &ps);        return (FALSE);        }*/   default:      return(DefWindowProc(hWnd, message, wParam, lParam));   }}

⌨️ 快捷键说明

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