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

📄 winmain.c

📁 最新IAR6.4软集成开发环境及破解文件
💻 C
📖 第 1 页 / 共 4 页
字号:
    break;
  case WM_LBUTTONUP:
  case WM_LBUTTONDOWN:
  case WM_MOUSEMOVE:
    {
      int fwKeys = wParam;        // key flags 
      if ((xPos < 0) | (yPos < 0)
        | (xPos > LCD_GetDevCap(LCD_DEVCAP_XSIZE))
        | (yPos > LCD_GetDevCap(LCD_DEVCAP_YSIZE)))
      {
        xPos = -1;
        yPos = -1;
        fwKeys = 0;
      }
      LCDSIM_SetMouseState(xPos, yPos, fwKeys);
    }
  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

/*********************************************************************
*
*       _CreateWndLCDInfo
*/
static void _CreateWndLCDInfo(int LayerIndex) {
  int NumColors, DeltaMode;
  int x, y;
  char ac[80];
  HWND hWnd;
  int xSizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
  int ySizeFrame = GetSystemMetrics(SM_CYSIZEFRAME);
  int ySizeCaption = GetSystemMetrics(SM_CYCAPTION);
  DeltaMode = LCD_GetDeltaModeEx(LayerIndex);
  x = _GetXSizePhys() + xSizeFrame * 2;
  y = LayerIndex * 100;
  wsprintf(ac, "Colors #%d", LayerIndex);
  if (DeltaMode) {
    NumColors = 1 << LCD_GetBitsPerPixel_L0Ex(LayerIndex);
  } else {
    NumColors = LCD_GetNumColorsEx(LayerIndex);
  }
  if (NumColors > 256) {
    hWnd = CreateWindow(acClassNameLCDInfo, ac,
                             WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 
                             | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CHILD | WS_CLIPSIBLINGS,
                             x, y, 
                             128 + xSizeFrame * 2, 
                             128 + ySizeFrame * 2 + ySizeCaption,
                             _hWndMain, NULL, _hInst, NULL);
  } else {
    int ysize;
    ysize = (NumColors + 15) / 16 *10 + 30;       
    hWnd = CreateWindow(acClassNameLCDInfo, ac,
                        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 
                        | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CHILD | WS_CLIPSIBLINGS,
                        x, y, 
                        160 + 10,
                        ysize,
                        _hWndMain, NULL, _hInst, NULL);
    SetTimer(hWnd, 0, 20, NULL);
  }
  SetWindowLong(hWnd, GWL_USERDATA, LayerIndex);
  ShowWindow(hWnd, SW_SHOW);
} 

/*********************************************************************
*
*       _CreateWndLCD
*/
static void _CreateWndLCD(void) {
  int  i;
  int  NumDisplays = LCD_GetNumLayers();
  int  xSizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
  int  ySizeFrame = GetSystemMetrics(SM_CYSIZEFRAME);
  int  ySizeCaption = GetSystemMetrics(SM_CYCAPTION);
  char acTitle[200];
  for (i = 0; i < NumDisplays; i++) {
    int  XSize = _GetXSizePhysEx(i);
    int  YSize = _GetYSizePhysEx(i);
    int  BPP   = LCD_GetBitsPerPixel_L0Ex(i);
    int  FixedPalette = LCD_GetFixedPaletteEx(i);
    HWND hWnd;
    wsprintf(acTitle, "LCD #%d %d*%d %dbpp, FixedPalette %d", i, XSize, YSize, BPP, FixedPalette);
    hWnd = CreateWindow(acClassNameLCD, acTitle,
                        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
                        | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CHILD | WS_CLIPSIBLINGS,
                        20 * i, 20 * i, XSize * _MagX + 2 * xSizeFrame, YSize * _MagY + ySizeCaption + 2 * ySizeFrame,
                        _hWndMain, NULL, _hInst, NULL);
    SetWindowLong(hWnd, GWL_USERDATA, i);
    ShowWindow(hWnd, SW_SHOW);
    _CreateWndLCDInfo(i);
  }
}

/*********************************************************************
*
*       About box
*/
static LRESULT CALLBACK _About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  switch (message) {
  case WM_INITDIALOG:
    {
      char acBuffer[80];
      sprintf(acBuffer, "About %s", BRANDING_GetAppNameLong());
      SetWindowText(hDlg, acBuffer);
      SetDlgItemText(hDlg, IDC_APPNAME, BRANDING_GetAppNameShort());
      sprintf(acBuffer, "Version: %s", GUI_GetVersionString());
      SetDlgItemText(hDlg, IDC_VERSION, acBuffer);
      SetDlgItemText(hDlg, IDC_COPYRIGHT, BRANDING_GetCopyright());
    }
    return TRUE;
  case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
      EndDialog(hDlg, LOWORD(wParam));
      return TRUE;
    }
    break;
  }
  return FALSE;
}

/*********************************************************************
*
*       _MainWnd_Command
*/
static int _MainWnd_Command(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  int wmId    = LOWORD(wParam); 
//  int wmEvent = HIWORD(wParam);
// Parse the menu selections:
  switch (wmId) {
    case ID_EDIT_COPY:                _OnCopy(0);                                                          break;  // TBD: Use LayerIndex
    case ID_VIEW_LCD:                 _CreateWndLCD();                                                     break;
    case ID_VIEW_LCDINFO:             _CreateWndLCDInfo(0);                                                break;
    case IDM_ABOUT:                   DialogBox(_hInst, (LPCTSTR)IDD_ABOUTBOX, _hWndMain, (DLGPROC)_About); break;
    case IDM_EXIT:                    DestroyWindow(hWnd);                                                 break;
    case ID_FILE_STARTAPPLICATION:    _THREAD_StartApplication();                                          break;
    case ID_FILE_STOPAPPLICATION:     _THREAD_StopApplication();                                           break;
    case ID_FILE_CONTINUEAPPLICATION: _THREAD_ContinueApplication();                                       break;
    case ID_VIEW_LOG:                 _LOG_Create(_hInst, hWnd);                                           break;
    default: return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

/*********************************************************************
*
*       _HandleKeyEvents
*/
void _HandleKeyEvents(UINT Msg, WPARAM wParam) {
  int Key;
  switch (Msg) {
    case WM_KEYUP:
      Key = _VirtKey2Key(wParam);
      if (Key) {
        GUI_StoreKeyMsg(Key, 0);
      } else {
        if ((Key = _Keydown2ASCII(wParam)) != 0) {
          GUI_StoreKeyMsg(Key, 0);
        }
      }
      break;
    case WM_KEYDOWN:
      Key = _VirtKey2Key(wParam);
      if (Key) {
        GUI_StoreKeyMsg(Key, 1);
      } else {
        if ((Key = _Keydown2ASCII(wParam)) != 0) {
          GUI_StoreKeyMsg(Key, 1);
        }
      }
      break;
  }
}

/*********************************************************************
*
*       _WndProcDevice
*/
static LRESULT CALLBACK _WndProcDevice(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  HDC hdc;
  PAINTSTRUCT ps;
  RECT r;
  static int CaptureOn = 0;
  static int xPosOld, yPosOld;
  int xPos = (signed short)LOWORD(lParam);  // horizontal position of cursor
  int yPos = (signed short)HIWORD(lParam);  // vertical position of cursor
  _HandleKeyEvents(message, wParam);
  switch (message) {
  case WM_CREATE:
    CreateWindow(acClassNameLCD, "LCD window", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
                           _xPosLCD, _yPosLCD, _GetXSizePhys() * _MagX, _GetYSizePhys() * _MagY,
                           hWnd, NULL, _hInst, NULL);
    _SetBitmapRegion(hWnd, _ahBmpDevice[0], _rgbTransparent, 0);
    _FindHardkeys(_ahBmpDevice[1], _rgbTransparent);
    { int i;
      for (i = 0; i < countof(_aHardkey); i++) {
        if ((_aHardkey[i].x1 > _aHardkey[i].x0) && (_aHardkey[i].y1 > _aHardkey[i].y0)) {
          HWND hWndHardkey = CreateWindow(acClassNameHardkey, "Hardkey", WS_CHILD | WS_CLIPSIBLINGS
                                          | WS_VISIBLE,
                                          _aHardkey[i].x0,  _aHardkey[i].y0,
                                          _aHardkey[i].x1 - _aHardkey[i].x0 + 1,
                                          _aHardkey[i].y1 - _aHardkey[i].y0 + 1,
                                          hWnd, NULL, _hInst, NULL);
          SetWindowLong(hWndHardkey, GWL_USERDATA, i);
        }
      }
    }
    break;
  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps); {
      HDC hdcImage = CreateCompatibleDC(hdc); {
        SelectObject(hdcImage, _ahBmpDevice[0]);
        BitBlt(hdc, 0, 0, 1000, 1000, hdcImage, 0, 0, SRCCOPY);
        } DeleteDC(hdcImage);
    } EndPaint(hWnd, &ps);
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
// Handle mouse events
  case WM_RBUTTONDOWN:
    { POINT Point;
      Point.x = xPos;
      Point.y = yPos;
      ClientToScreen(hWnd, &Point);
      TrackPopupMenu(_hMenuPopup, TPM_RIGHTBUTTON, Point.x, Point.y, 0, hWnd, NULL);
    }
    break;
// Handle mouse events
  case WM_LBUTTONDOWN:
    SetCapture(hWnd);
    CaptureOn = 1;
    xPosOld = xPos;
    yPosOld = yPos;
    break;
  case WM_LBUTTONUP:
    ReleaseCapture();
    CaptureOn =0;
    break;
  case WM_COMMAND:
    return _MainWnd_Command(hWnd, message, wParam, lParam);
  case WM_MOUSEMOVE:
    GetWindowRect(hWnd, &r);
    if (CaptureOn) {
      int xDiff, yDiff;
      xDiff = xPos - xPosOld;
      yDiff = yPos - yPosOld;
      if (xDiff | yDiff) {
        MoveWindow(hWnd, r.left + xDiff, r.top + yDiff, r.right - r.left, r.bottom - r.top, 1);
      }
    }
    break;
  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

/*********************************************************************
*
*       _WndProcHardkey
*/
static LRESULT CALLBACK _WndProcHardkey(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  HDC hdc;
  PAINTSTRUCT ps;
  int xPos = (signed short)LOWORD(lParam);  // horizontal position of cursor
  int yPos = (signed short)HIWORD(lParam);  // vertical position of cursor
  unsigned int Index    = GetWindowLong(hWnd, GWL_USERDATA);
  switch (message) {
  case WM_CREATE:
    _SetBitmapRegion(hWnd, _ahBmpDevice[1], _rgbTransparent, 1);
    break;
  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps); {
      HDC hdcImage = CreateCompatibleDC(hdc); {
        if (Index < countof(_aHardkey)) {
          SelectObject(hdcImage, _ahBmpDevice[_aHardkey[Index].IsPressed]);
          BitBlt(hdc, 0, 0, 1000, 1000, hdcImage, _aHardkey[Index].x0, _aHardkey[Index].y0, SRCCOPY);
        }
      } DeleteDC(hdcImage);
    } EndPaint(hWnd, &ps);
    break;
// Handle mouse events
  case WM_RBUTTONDOWN:
    { POINT Point;
      Point.x = xPos;
      Point.y = yPos;
      ClientToScreen(hWnd, &Point);
      TrackPopupMenu(_hMenuPopup, TPM_RIGHTBUTTON, Point.x, Point.y, 0, _hWndMain, NULL);
    }
    break;
// Handle mouse events
  case WM_LBUTTONDOWN:
    SetCapture(hWnd);
    if (Index < countof(_aHardkey)) {
      SIM_HARDKEY_CB* cb = _aHardkey[Index].pfCallback;
      if (_aHardkey[Index].Mode == 0) {
        _aHardkey[Index].IsPressed = 1;
      } else {
        _aHardkey[Index].IsPressed ^= 1;
      }
      if (cb) {
        (*cb)(Index, 1);
      }
      InvalidateRect(hWnd, NULL, TRUE);
    }
    break;
  case WM_LBUTTONUP:
    ReleaseCapture();
    if (Index < countof(_aHardkey)) {
      SIM_HARDKEY_CB* cb = _aHardkey[Index].pfCallback;
      if (_aHardkey[Index].Mode == 0) {
        _aHardkey[Index].IsPressed = 0;
      }
      if (cb) {
        (*cb)(Index, 0);
      }
      InvalidateRect(hWnd, NULL, TRUE);
    }
    break;
  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

/*********************************************************************
*
*       _WndProcLCDInfo
*/
static LRESULT CALLBACK _WndProcLCDInfo(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  HDC hDC;
  PAINTSTRUCT ps;
  int NumColors, DeltaMode;
  int xSize = 32;
  int ySize = 16;
  static U16 aBits[32*16];
  static BITMAPINFO BitmapInfo;
  static int BitmapCreated;
  unsigned int LayerIndex = GetWindowLong(hWnd, GWL_USERDATA);
  DeltaMode = LCD_GetDeltaModeEx(LayerIndex);
  if (DeltaMode) {
    NumColors = 1 << LCD_GetBitsPerPixel_L0Ex(LayerIndex);
  } else {
    NumColors = LCD_GetNumColorsEx(LayerIndex);
  }
  switch (message) {
  case WM_PAINT:
    {
      hDC = BeginPaint(hWnd, &ps); {
        if (NumColors <= 256) {
          int i;
          for (i = 0; i < NumColors; i++) {
            int x0 =     10 * (i % 16);
            int y0 = 2 + 10 * (i / 16);
            int x1 = x0 + 8;
            int y1 = y0 + 8;
            HGDIOBJ hbPrev;
            U32 Color = LCDSIM_Index2Color(i, LayerIndex);
            HBRUSH hb = CreateSolidBrush(RGB(Color&255,      // Red component
                                             255&(Color>>8), // Green component
                                             Color>>16));    // Blue component
            hbPrev = SelectObject(hDC, hb);
            Rectangle (hDC, x0, y0, x1, y1);
            SelectObject(hDC, hbPrev);
            DeleteObject(hb);
          }
        } else {
          RECT Rect;
          if (!BitmapCreated) {
            memset(&BitmapInfo, 0, sizeof(BITMAPINFO));
            memset(aBits, 0, sizeof(aBits));
            BitmapInfo.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
            BitmapInfo.bmiHeader.biWidth       = 32;
            BitmapInfo.bmiHeader.biHeight      = 16;
            BitmapInfo.bmiHeader.biPlanes      = 1;
            BitmapInfo.bmiHeader.biBitCount    = 16;
            BitmapInfo.bmiHeader.biCompression = BI_RGB;
            {
              int Color;
              for (Color = 0; Color < 8; Color++) {
                U8 r = (Color & 0x01) >> 0;
                U8 g = (Color & 0x02) >> 1;
                U8 b = (Color & 0x04) >> 2;
                int x;
                for (x = 0; x < xSize; x++) {
                  int xx = 31 - x;
                  int rr = r * xx;
                  int gg = g * xx;
                  int bb = b * xx;
                  U16 BlackValue = (rr << 10) + (gg << 5) +  bb;
                  U16 WhiteValue = ((r ? 0x1f : x) << 10) + ((g ? 0x1f : x) <<  5) +  (b ? 0x1f : x);
                  int BlackIndex = Color * 2 * xSize + x;
                  int WhiteIndex = BlackIndex + xSize;
                  aBits[BlackIndex] = BlackValue;
                  aBits[WhiteIndex] = WhiteValue;
                }
              }
            }
            BitmapCreated = 1;
          }
          GetClientRect(hWnd, &Rect);
          SetStretchBltMode(hDC, COLORONCOLOR);
          StretchDIBits(hDC,            // hDC
                        0,              // DestX
                        0,              // DestY
                        Rect.right,     // nDestWidth
                        Rect.bottom,    // nDestHeight
                        0,              // SrcX
                        0,              // SrcY
                        xSize,          // wSrcWidth
                        ySize,          // wSrcHeight
                        aBits,          // lpBits
                        &BitmapInfo,    // lpBitsInfo
                        DIB_RGB_COLORS, // wUsage
                        SRCCOPY);
        }
      } EndPaint(hWnd, &ps);
    }
    break;
  case WM_TIMER:
    if (_aLUTModifyCnt[LayerIndex] != LCDSIM_GetModifyCntInfo(LayerIndex)) {
      _aLUTModifyCnt[LayerIndex] = LCDSIM_GetModifyCntInfo(LayerIndex);
      InvalidateRect(hWnd, NULL, FALSE);
    }
    break;
  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

/*********************************************************************
*
*       _InitMenu
*/
static void _InitMenu(HMENU hMenu) {
  int EnableStop      = (_THREAD_IsRunning() & !_THREAD_IsSuspended()) ? 0 : MF_GRAYED;
  int EnableContinue  = (_THREAD_IsRunning() &  _THREAD_IsSuspended()) ? 0 : MF_GRAYED;
  EnableMenuItem(hMenu, ID_FILE_STOPAPPLICATION,     MF_BYCOMMAND|EnableStop);
  EnableMenuItem(hMenu, ID_FILE_CONTINUEAPPLICATION, MF_BYCOMMAND|EnableContinue);
}

/*********************************************************************
*
*       _MainWnd_OnTimer
*/
static void _MainWnd_OnTimer(HWND hWnd) {
  static char acTitle[200];
  static char acTitleNew[200];
  strcpy(acTitleNew, BRANDING_GetAppNameLong());
  if (_THREAD_IsRunning()) {
    if (_THREAD_IsSuspended()) {
      strcat(acTitleNew, "(Suspended)");
    } else {
      strcat(acTitleNew, "(Executing)");
    }
  } else {
    strcat(acTitleNew, "(Terminated)");
  }

⌨️ 快捷键说明

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