welcome.c

来自「一个类似windows」· C语言 代码 · 共 826 行 · 第 1/2 页

C
826
字号
      hwndDefaultTopic = 0;
      nDefaultTopic = -1;
      SendMessage(hwndCloseButton, WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
    }
  else
    {
      hwndCloseButton = 0;
    }

  /* Create checkbox */
  nLength = LoadString(hInstance, IDS_CHECKTEXT,szText,80);
  if (nLength > 0)
    {
      hfontCheckButton = CreateFont(-10,0,0,0,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,
				    OUT_DEFAULT_PRECIS,
				    CLIP_DEFAULT_PRECIS,
				    DEFAULT_QUALITY,
				    FF_DONTCARE,
				    TEXT("Tahoma"));

      hwndCheckButton = CreateWindow(TEXT("BUTTON"),
				     szText,
				     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
				     rcLeftPanel.left + 8,
				     rcLeftPanel.bottom - 8 - 13,
				     rcLeftPanel.right - rcLeftPanel.left - 16,
				     13,
				     hWnd,
				     (HMENU)IDC_CHECKBUTTON,
				     hInstance,
				     NULL);
      SendMessage(hwndCheckButton, WM_SETFONT, (WPARAM)hfontCheckButton, MAKELPARAM(TRUE,0));
    }
  else
    {
      hwndCheckButton = 0;
      hfontCheckButton = 0;
    }

  return 0;
}


static LRESULT
OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  if (LOWORD(wParam) == IDC_CLOSEBUTTON)
    {
      DestroyWindow(hWnd);
    }
  else if ((LOWORD(wParam) < 10))
    {
      if (RunApplication(LOWORD(wParam)) == FALSE)
	{
	  DestroyWindow(hWnd);
	}
    }
  return 0;
}


static VOID
PaintBanner(HDC hdc, LPRECT rcPanel)
{
  HBITMAP hOldBitmap;
  HBRUSH hOldBrush;

  /* Title bitmap */
  hOldBitmap = SelectObject(hdcMem, hTitleBitmap);
  BitBlt(hdc,
	 rcPanel->left,
	 rcPanel->top,
	 rcPanel->right - rcPanel->left,
	 rcPanel->bottom - 3,
	 hdcMem, 0, 0, SRCCOPY);
  SelectObject(hdcMem, hOldBitmap);

  /* Dark blue line */
  hOldBrush = SelectObject(hdc, hbrDarkBlue);
  PatBlt(hdc,
	 rcPanel->left,
	 rcPanel->bottom - 3,
	 rcPanel->right - rcPanel->left,
	 3,
	 PATCOPY);

  SelectObject(hdc, hOldBrush);
}


static LRESULT
OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  HPEN hPen;
  HPEN hOldPen;
  HDC hdc;
  PAINTSTRUCT ps;
  HBITMAP hOldBitmap = 0;
  HBRUSH hOldBrush;
  HFONT hOldFont;
  RECT rcTitle, rcDescription;
  TCHAR szTopicTitle[80];
  TCHAR szTopicDesc[256];
  int nLength;
  BITMAP bmpInfo;
  TCHAR version[50];

  hdc = BeginPaint(hWnd, &ps);

  /* Banner panel */
  PaintBanner(hdc, &rcTitlePanel);

  /* Left panel */
  hOldBrush = SelectObject (hdc, hbrLightBlue);
  PatBlt(hdc,
	 rcLeftPanel.left,
	 rcLeftPanel.top,
	 rcLeftPanel.right - rcLeftPanel.left,
	 rcLeftPanel.bottom - rcLeftPanel.top,
	 PATCOPY);
  SelectObject(hdc, hOldBrush);

  /* Right panel */
  hOldBrush = SelectObject (hdc, WHITE_BRUSH);
  PatBlt(hdc,
	 rcRightPanel.left,
	 rcRightPanel.top,
	 rcRightPanel.right - rcRightPanel.left,
	 rcRightPanel.bottom - rcRightPanel.top,
	 PATCOPY);
  SelectObject(hdc, hOldBrush);

  /* Draw dark verical line */
  hPen = CreatePen(PS_SOLID, 0, DARK_BLUE);
  hOldPen = SelectObject(hdc, hPen);
  MoveToEx(hdc, rcRightPanel.left, rcRightPanel.top, NULL);
  LineTo(hdc, rcRightPanel.left, rcRightPanel.bottom);
  SelectObject(hdc, hOldPen);
  DeleteObject(hPen);

  /* Draw topic bitmap */
  if ((nTopic == -1) && (hDefaultTopicBitmap != 0))
    {
      GetObject(hDefaultTopicBitmap, sizeof(BITMAP), &bmpInfo);
      hOldBitmap = SelectObject (hdcMem, hDefaultTopicBitmap);
      BitBlt(hdc,
	     rcRightPanel.right - bmpInfo.bmWidth,
	     rcRightPanel.bottom - bmpInfo.bmHeight,
	     bmpInfo.bmWidth,
	     bmpInfo.bmHeight,
	     hdcMem,
	     0,
	     0,
	     SRCCOPY);
    }
  else if ((nTopic != -1) && (hTopicBitmap[nTopic] != 0))
    {
      GetObject(hTopicBitmap[nTopic], sizeof(BITMAP), &bmpInfo);
      hOldBitmap = SelectObject (hdcMem, hTopicBitmap[nTopic]);
      BitBlt(hdc,
	     rcRightPanel.right - bmpInfo.bmWidth,
	     rcRightPanel.bottom - bmpInfo.bmHeight,
	     bmpInfo.bmWidth,
	     bmpInfo.bmHeight,
	     hdcMem,
	     0,
	     0,
	     SRCCOPY);
    }

  if (nTopic == -1)
    {
      nLength = LoadString(hInstance, IDS_DEFAULTTOPICTITLE, szTopicTitle, 80);
    }
  else
    {
      nLength = LoadString(hInstance, IDS_TOPICTITLE0 + nTopic, szTopicTitle, 80);
      if (nLength == 0)
	nLength = LoadString(hInstance, IDS_DEFAULTTOPICTITLE, szTopicTitle, 80);
    }

  if (nTopic == -1)
    {
      nLength = LoadString(hInstance, IDS_DEFAULTTOPICDESC, szTopicDesc, 256);
    }
  else
    {
      nLength = LoadString(hInstance, IDS_TOPICDESC0 + nTopic, szTopicDesc, 256);
      if (nLength == 0)
	nLength = LoadString(hInstance, IDS_DEFAULTTOPICDESC, szTopicDesc, 256);
    }

  SetBkMode(hdc, TRANSPARENT);

  /* Draw version information */
  wsprintf(version, TEXT("ReactOS %d.%d.%d"),
    KERNEL_VERSION_MAJOR,
    KERNEL_VERSION_MINOR,
    KERNEL_VERSION_PATCH_LEVEL);

  rcTitle.left = rcLeftPanel.left + 8;
  rcTitle.right = rcLeftPanel.right - 5;
  rcTitle.top = rcLeftPanel.bottom - 40;
  rcTitle.bottom = rcLeftPanel.bottom - 5;
  hOldFont = SelectObject(hdc, hfontTopicDescription);
  DrawText(hdc, version, -1, &rcTitle, DT_BOTTOM | DT_CALCRECT | DT_SINGLELINE);
  DrawText(hdc, version, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE);
  SelectObject(hdc, hOldFont);

  /* Draw topic title */
  rcTitle.left = rcRightPanel.left + 12;
  rcTitle.right = rcRightPanel.right - 8;
  rcTitle.top = rcRightPanel.top + 8;
  rcTitle.bottom = rcTitle.top + 57;
  hOldFont = SelectObject(hdc, hfontTopicTitle);
  DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP | DT_CALCRECT);

  SetTextColor(hdc, DARK_BLUE);
  DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP);

  /* Draw topic description */
  rcDescription.left = rcRightPanel.left + 12;
  rcDescription.right = rcRightPanel.right - 8;
  rcDescription.top = rcTitle.bottom + 8;
  rcDescription.bottom = rcRightPanel.bottom - 20;

  SelectObject(hdc, hfontTopicDescription);
  SetTextColor(hdc, 0x00000000);
  DrawText(hdc, szTopicDesc, -1, &rcDescription, DT_TOP | DT_WORDBREAK);

  SetBkMode(hdc, OPAQUE);
  SelectObject(hdc, hOldFont);

  SelectObject (hdcMem, hOldBrush);
  SelectObject (hdcMem, hOldBitmap);

  EndPaint(hWnd, &ps);

  return 0;
}


static LRESULT
OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
  HPEN hPen, hOldPen;
  HBRUSH hOldBrush;
  TCHAR szText[80];
  int iBkMode;

  if (lpDis->hwndItem == hwndCloseButton)
    {
      DrawFrameControl(lpDis->hDC,
		       &lpDis->rcItem,
		       DFC_BUTTON,
		       DFCS_BUTTONPUSH | DFCS_FLAT);
    }
  else
    {
      if (lpDis->CtlID == (ULONG)nTopic)
	hOldBrush = SelectObject(lpDis->hDC, hbrRightPanel);
      else
	hOldBrush = SelectObject(lpDis->hDC, hbrLightBlue);

      PatBlt(lpDis->hDC,
	     lpDis->rcItem.left,
	     lpDis->rcItem.top,
	     lpDis->rcItem.right,
	     lpDis->rcItem.bottom,
	     PATCOPY);
      SelectObject(lpDis->hDC, hOldBrush);

      hPen = CreatePen(PS_SOLID, 0, DARK_BLUE);
      hOldPen = SelectObject(lpDis->hDC, hPen);
      MoveToEx(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.bottom-1, NULL);
      LineTo(lpDis->hDC, lpDis->rcItem.right, lpDis->rcItem.bottom-1);
      SelectObject(lpDis->hDC, hOldPen);
      DeleteObject(hPen);

      InflateRect(&lpDis->rcItem, -10, -4);
      OffsetRect(&lpDis->rcItem, 0, 1);
      GetWindowText(lpDis->hwndItem, szText, 80);
      SetTextColor(lpDis->hDC, 0x00000000);
      iBkMode = SetBkMode(lpDis->hDC, TRANSPARENT);
      DrawText(lpDis->hDC, szText, -1, &lpDis->rcItem, DT_TOP | DT_LEFT | DT_WORDBREAK);
      SetBkMode(lpDis->hDC, iBkMode);
    }

  return 0;
}


static LRESULT
OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  if (nTopic != -1)
    {
      nTopic = -1;
      SetFocus(hWnd);
      InvalidateRect(hwndMain, &rcRightPanel, TRUE);
    }

  return 0;
}


static LRESULT
OnCtlColorStatic(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  if ((HWND)lParam == hwndCheckButton)
    {
      SetBkColor((HDC)wParam, LIGHT_BLUE);
      return((LRESULT)hbrLightBlue);
    }

  return 0;
}


static LRESULT
OnActivate(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  nTopic = -1;
  InvalidateRect(hwndMain, &rcRightPanel, TRUE);

  return(0);
}


static LRESULT
OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  int i;

  for (i=0;i<10;i++)
    {
      if (hwndTopicButton[i] != 0)
	DestroyWindow(hwndTopicButton[i]);
    }

  if (hwndCloseButton != 0)
    DestroyWindow(hwndCloseButton);

  if (hwndCheckButton != 0)
    DestroyWindow(hwndCheckButton);

  DeleteDC(hdcMem);

  /* delete bitmaps */
  DeleteObject(hDefaultTopicBitmap);
  DeleteObject(hTitleBitmap);
  for (i=0;i<10;i++)
    {
      if (hTopicBitmap[i] != 0)
	DeleteObject(hTopicBitmap[i]);
    }

  DeleteObject(hfontTopicTitle);
  DeleteObject(hfontTopicDescription);
  DeleteObject(hfontTopicButton);

  if (hfontCheckButton != 0)
    DeleteObject(hfontCheckButton);

  DeleteObject(hbrLightBlue);
  DeleteObject(hbrDarkBlue);
  DeleteObject(hbrRightPanel);

  return 0;
}


INT_PTR CALLBACK
MainWndProc(HWND hWnd,
	    UINT uMsg,
	    WPARAM wParam,
	    LPARAM lParam)
{
  switch(uMsg)
    {
      case WM_CREATE:
	return(OnCreate(hWnd, wParam, lParam));

      case WM_COMMAND:
	return(OnCommand(hWnd, wParam, lParam));

      case WM_ACTIVATE:
	return(OnActivate(hWnd, wParam, lParam));

      case WM_PAINT:
	return(OnPaint(hWnd, wParam, lParam));

      case WM_DRAWITEM:
	return(OnDrawItem(hWnd, wParam, lParam));

      case WM_CTLCOLORSTATIC:
	return(OnCtlColorStatic(hWnd, wParam, lParam));

      case WM_MOUSEMOVE:
	return(OnMouseMove(hWnd, wParam, lParam));

      case WM_DESTROY:
	OnDestroy(hWnd, wParam, lParam);
	PostQuitMessage(0);
	return(0);
    }

  return(DefWindowProc(hWnd, uMsg, wParam, lParam));
}

/* EOF */

⌨️ 快捷键说明

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