📄 ybjj.cpp
字号:
// YBJJ.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#pragma comment(lib,"wsock32.lib")
#pragma comment(lib,"msimg32.lib")
#include "GLOBAL.h"
//Code Section
#include "CopyRight.h"
void SplashWindow()
{
RECT rect;
HBITMAP hbm;
BITMAP bm;
WNDCLASS wc = {0};
// Load the bitmap and fill out a BITMAP structure for it
hbm = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SPLASH));
GetObject(hbm, sizeof(bm), &bm);
DeleteObject(hbm);
// Get the extents of the desktop window
GetWindowRect(GetDesktopWindow(), &rect);
// Fill in window class structure with parameters that describe
// the main window.
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProcSplash;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszClassName = _T("YBJJ-SPLASH");
// Register the window class and return success/failure code.
RegisterClass(&wc);
// Create a centered window the size of our bitmap
hSplash = CreateWindowEx(WS_EX_TOOLWINDOW,_T("YBJJ-SPLASH"), NULL, WS_POPUP ,
(rect.right / 2) - (bm.bmWidth / 2),
(rect.bottom / 2) - (bm.bmHeight / 2),
bm.bmWidth,
bm.bmHeight,
NULL, NULL, hInst, NULL);
if (!hSplash) return;
SetWindowPos(hSplash, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
//ShowWindow(hSplash, SW_SHOW);
AnimateWindow(hSplash,500,AW_BLEND);
UpdateWindow(hSplash);
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
#ifdef _DEBUG
//CRT 内存泄漏检测
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag( tmpFlag );
#endif
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance))
{
return FALSE;
}
// Perform Splash Window
SplashWindow();
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_YBJJ);
//hDlgQuery=CreateDialog(hInst, (LPCTSTR)IDD_QUERYBOX, hMain, (DLGPROC)QueryProc);
hDlgCancel=false;
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (m) DestroyMenu(m);
if (m2) DestroyMenu(m2);
closesocket(hSocket);
WSACleanup();
return msg.wParam;
ExitProcess(0);
}
/*****************************************************************************
* *
* HPALETTE CreateSpectrumPalette() *
* *
* Parameter: *
* *
* (none) *
* *
* Return Value: *
* *
* HPALETTE - Returns a handle to a spectrum palette or NULL if it *
* fails. *
* *
* Description: *
* *
* This function will build a palette with a spectrum of colors. It is *
* useful when you want to display a number of DIBs each with a different *
* palette yet still have an a good selection of colors for the DIBs to map *
* to. *
* *
*****************************************************************************/
/*HPALETTE CreateSpectrumPalette()
{
HPALETTE hPal;
LPLOGPALETTE lplgPal;
BYTE red, green, blue;
int i;
lplgPal = (LPLOGPALETTE)GlobalAlloc(GPTR, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * MAXPALETTE);
if (!lplgPal)
return NULL;
lplgPal->palVersion = PALVERSION;
lplgPal->palNumEntries = MAXPALETTE;
red = green = blue = 0;
for (i = 0; i < MAXPALETTE; i++) {
lplgPal->palPalEntry[i].peRed = red;
lplgPal->palPalEntry[i].peGreen = green;
lplgPal->palPalEntry[i].peBlue = blue;
lplgPal->palPalEntry[i].peFlags = (BYTE)0;
if (!(red += 32))
if (!(green += 32))
blue += 64;
}
hPal = CreatePalette(lplgPal);
GlobalFree(lplgPal);
return hPal;
}*/
/*****************************************************************************
* *
* HPALETTE CreatePaletteFromRGBQUAD(LPRGBQUAD rgbqPalette, WORD wEntries) *
* *
* Parameter: *
* *
* LPRGBQUAD - pointer to RGBQUADs *
* WORD - the number of RGBQUADs we are pointing to *
* *
* Return Value: *
* *
* HPALETTE - returns a handle to a palette or NULL if it failes *
* *
* Description: *
* *
* This function will build a valid HPALETTE when given an array of RGBQUADs *
* *
*****************************************************************************/
/*HPALETTE CreatePaletteFromRGBQUAD(LPRGBQUAD rgbqPalette, WORD wEntries)
{
HPALETTE hPal;
LPLOGPALETTE lplgPal;
int i;
lplgPal = (LPLOGPALETTE)GlobalAlloc(GPTR, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * wEntries);
if (!lplgPal)
return NULL;
lplgPal->palVersion = PALVERSION;
lplgPal->palNumEntries = wEntries;
for (i=0; i<wEntries; i++) {
lplgPal->palPalEntry[i].peRed = rgbqPalette[i].rgbRed;
lplgPal->palPalEntry[i].peGreen = rgbqPalette[i].rgbGreen;
lplgPal->palPalEntry[i].peBlue = rgbqPalette[i].rgbBlue;
lplgPal->palPalEntry[i].peFlags = 0;
}
hPal = CreatePalette(lplgPal);
GlobalFree(lplgPal);
return hPal;
}*/
/*****************************************************************************
* *
* void ShowBitmap(HWND hWnd, DWORD dwResId) *
* *
* Parameter: *
* *
* HWND - handle of the target window *
* DWORD - the ID of the resource bitmap to display *
* *
* Description: *
* *
* This function loads and displays a resource bitmap into a specified window *
* *
*****************************************************************************/
void ShowBitmap(HWND hWnd, DWORD dwResId,HDC hdcWindow)
{
HBITMAP hBitmap;
// HPALETTE hPalette;
HDC hdcMemory;
BITMAP bm;
RECT rect;
// RGBQUAD rgbq[256];
// Get the extents of our window
GetClientRect(hWnd, &rect);
// Load the resource as a DIB section
hBitmap = (HBITMAP)LoadImage(hInst,
MAKEINTRESOURCE(dwResId),
IMAGE_BITMAP,
0,0,
LR_CREATEDIBSECTION);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
// Create a DC to hold our surface and selct our surface into it
hdcMemory = CreateCompatibleDC(hdcWindow);
SelectObject(hdcMemory, hBitmap);
// Retrieve the color table (if there is one) and create a palette
// that reflects it
/* if (GetDIBColorTable(hdcMemory, 0, 256, rgbq))
hPalette = CreatePaletteFromRGBQUAD(rgbq, 256);
else
hPalette = CreateSpectrumPalette();
// Select and realize the palette into our window DC
SelectPalette(hdcWindow,hPalette,FALSE);
RealizePalette(hdcWindow);*/
/* BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.AlphaFormat = 0;
bf.SourceConstantAlpha = Alpha;
AlphaBlend(hdcWindow,0,0,rect.right,rect.bottom,hdcMemory, 0, 0, bm.bmWidth, bm.bmHeight,bf);*/
// Display the bitmap
// SetStretchBltMode(hdcWindow, COLORONCOLOR);
//StretchBlt(hdcWindow, 0, 0, rect.right, rect.bottom,hdcMemory, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
BitBlt(hdcWindow, 0, 0, rect.right, rect.bottom,hdcMemory, 0, 0, SRCCOPY);
// Clean up our objects
DeleteDC(hdcMemory);
DeleteObject(hBitmap);
ReleaseDC(hWnd, hdcWindow);
// DeleteObject(hPalette);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance)
{
WORD wVersion = MAKEWORD(2, 2);
WSADATA wsaData;
RECT rect;
hInst = hInstance; // Store instance handle in our global variable
//============================================
// 检查日期和时间
//============================================
SYSTEMTIME st;
GetLocalTime(&st);
if (st.wYear!=2008 )
{
if ( MessageBox(0,_T("建议您使用最新版本,您仍然要继续吗?"),szTitle,MB_ICONQUESTION|MB_YESNO)==IDNO) return false;
}
//============================================
// 初始化公共控件和Socket
//============================================
InitCommonControls();
if (WSAStartup(wVersion, &wsaData))
{
MessageBox(0,_T("初始化失败,您的电脑上无法运行此软件"),szTitle,MB_ICONERROR);
lout(_T("初始化失败,您的电脑上无法运行此软件\r\n"));
}
//============================================
// 创建字体,主窗口,弹出菜单,显示屏,状态栏
//============================================
hFont=CreateFont(12,0,0,0,400,0,0,0, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,_T("宋体"));
GetClientRect(GetDesktopWindow(),&rect);
hMain = CreateWindow(_T("CLASS_YBJJ"), szTitle, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, rect.right/2-250, rect.bottom/2-157, 500,315, NULL, NULL, hInstance, NULL);
m=LoadMenu(hInst,(LPCTSTR)IDR_TRAY);
m2=LoadMenu(hInst,(LPCTSTR)IDR_QUERY);
hLCD=CreateWindowEx(NULL,_T("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_READONLY | WS_VSCROLL,5, 5, 480, 240, hMain, NULL, hInstance, NULL);//LCD
SendMessage(hMain,WM_SETFONT,(unsigned int)hFont,1);
SendMessage(hLCD,WM_SETFONT,(unsigned int)hFont,1);
hStatusBar=CreateStatusWindow(WS_VISIBLE|WS_CHILD,0,hMain,IDC_STATUSBAR);
//int iWidth[]={200,-1};
//SendMessage(hStatusBar,SB_SETPARTS,2,(LPARAM)&iWidth);
SendMessage(hStatusBar,SB_SETTEXT,0,(LPARAM)_T("爱生活,爱烟白,http://bbs.bjtu.org"));
if (!hMain || !hLCD || !m || !m2 || !hStatusBar)
{
return FALSE;
}
//============================================
// 初始化全局变量
//============================================
ZeroMemory(&mystatus,sizeof(struct_mystatus));
ZeroMemory(&http_head_custom,sizeof(struct_http_head));
now_http_head=&http_head2;
g_iServer = IDM_SERVER_AUTO;
g_iTimeOut = 20;
g_iMaxThread = 30;
g_iCountThread = 0;
//============================================
// 版权信息
//============================================
CopyRight();
//============================================
// 禁止使用“本机服务器”菜单
//============================================
#ifdef _DEBUG
PostMessage(hMain,WM_COMMAND,IDM_SERVER_DEBUG,0);
#else
EnableMenuItem(GetMenu(hMain),IDM_SERVER_DEBUG,MF_DISABLED |MF_GRAYED| MF_BYCOMMAND);
#endif
#ifdef _DEBUG
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=hMain;
tnd.uID=IDR_MAINFRAME;
tnd.uFlags=NIF_MESSAGE | NIF_ICON |NIF_TIP | 0x10; //NIF_INFO==0x10
lstrcpy(tnd.szInfo,_T("_DEBUG标签已设置"));
lstrcpy(tnd.szInfoTitle ,_T("_DEBUG"));
tnd.uTimeout = 10;
tnd.dwInfoFlags =0x01; //NIIF_INFO==0x01
tnd.uCallbackMessage=WM_TRAY; //用户自定义的消息,即鼠标在任务栏上程序图标上动作时图标发送的消息
tnd.hIcon=LoadIcon(hInst, (LPCTSTR)IDI_YBJJ);
lstrcpy(tnd.szTip ,szTitle);
Shell_NotifyIcon(NIM_ADD,&tnd);//向任务栏添加图标
//SendMessage(hMain,WM_COMMAND,IDM_AUTO,0);
now_http_head=&http_head1;
//GetDefault("xk1.loginwindow",4);
#endif
return TRUE;
}
LRESULT CALLBACK WndProcSplash(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// static char Alpha;
switch (message) {
case WM_CREATE:
// Alpha=0;
// Set the timer for the specified number of ms
// SetTimer(hWnd, 1, 15, NULL);
SetTimer(hWnd, 2, 5000, NULL);
break;
// Handle the palette messages in case
// another app takes over the palette
/* case WM_PALETTECHANGED:
if ((HWND) wParam == hWnd)
return 0;
case WM_QUERYNEWPALETTE:
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
return TRUE;*/
// Destroy the window if...
case WM_LBUTTONDOWN: // ...the user pressed the left mouse button
case WM_RBUTTONDOWN: // ...the user pressed the right mouse button
DestroyWindow(hWnd); // Close the window
break;
case WM_TIMER: // ...the timer timed out
switch(wParam)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -