📄 connect.c
字号:
case WM_MOUSEMOVE:
if (pClientData != NULL) {
SetCursor((pClientData->wantsInput || broadcasting) ?
(squelched ? boltCursor : earCursor) :
phoneCursor);
}
break;
case WM_PAINT:
{
#define DCOL 11
PAINTSTRUCT psPaint;
HDC hdc;
HBITMAP ibmap = NULL;
int active = hwnd == ((HWND) LOWORD(SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L))),
resized = FALSE;
hdc = BeginPaint(hwnd, &psPaint);
if (pClientData != NULL) {
if (pClientData->face_stat == FScomplete &&
pClientData->face_bmp != NULL) {
int bx, by;
RECT cr, wr;
BITMAPFILEHEADER *bfh;
BITMAPINFOHEADER *bmi;
char _huge *bits;
HPALETTE bpal = NULL, opal;
int i;
LPLOGPALETTE lp;
BITMAPINFO *bh;
unsigned short *palidx;
LPSTR lpalette;
unsigned short *savepal;
#ifdef TRACE_FACE
{ char s[256];
wsprintf(s, "Paint %04X: %s\r\n", hwnd, pClientData->szHost);
OutputDebugString(s);
}
#endif
pClientData->face_shown = FALSE;
savepal = (unsigned short *) GlobalAllocPtr(GPTR,
sizeof(LOGPALETTE) +
sizeof(PALETTEENTRY) * 256 +
sizeof(short) * 256);
if (savepal == NULL) {
goto face_failed;
}
lpalette = ((LPSTR) savepal) + 256 * sizeof(short);
GetWindowRect(hwnd, &wr);
GetClientRect(hwnd, &cr);
bfh = (BITMAPFILEHEADER *) pClientData->face_bmp;
bmi = (BITMAPINFOHEADER *) (pClientData->face_bmp + sizeof(BITMAPFILEHEADER));
bh = (BITMAPINFO *) bmi;
bx = (int) bmi->biWidth;
by = (int) bmi->biHeight;
if (bmi->biClrUsed == 0) {
bmi->biClrUsed = 1L << bmi->biBitCount;
}
bits = (char *) (pClientData->face_bmp + bfh->bfOffBits);
lp = (LOGPALETTE *) lpalette;
palidx = (unsigned short *) bh->bmiColors;
memcpy(savepal, palidx, 256 * sizeof(short));
lp->palVersion = 0x0300;
lp->palNumEntries = (WORD) bmi->biClrUsed;
for (i = 0; i < ((int) bmi->biClrUsed); i++) {
lp->palPalEntry[i].peRed = bh->bmiColors[i].rgbRed;
lp->palPalEntry[i].peGreen = bh->bmiColors[i].rgbGreen;
lp->palPalEntry[i].peBlue = bh->bmiColors[i].rgbBlue;
lp->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
// if (active) {
// palidx[i] = (unsigned short) i;
// }
}
bpal = CreatePalette(lp);
if (active && bpal != NULL) {
opal = SelectPalette(hdc, bpal, FALSE);
RealizePalette(hdc);
}
ibmap = CreateDIBitmap(hdc, bmi, CBM_INIT,
bits, (BITMAPINFO *) bmi, DIB_RGB_COLORS);
memcpy(palidx, savepal, 256 * sizeof(short));
if (ibmap != NULL) {
HDC hMemDC;
HBITMAP obmap;
HPALETTE mopal;
hMemDC = CreateCompatibleDC(hdc);
if (bpal != NULL) {
mopal = SelectPalette(hMemDC, bpal, FALSE);
}
obmap = SelectObject(hMemDC, ibmap);
if (bx <= cr.right && by <= cr.bottom) {
BitBlt(hdc, (cr.right - bx) / 2, (cr.bottom - by) / 2,
bx, by, hMemDC, 0, 0, SRCCOPY);
} else {
int nx, ny;
double xshrink = ((double) bx) / cr.right,
yshrink = ((double) by) / cr.bottom;
#ifdef TRACE_FACE
OutputDebugString("Yick!!! Had to stretch face bitmap.\r\n");
#endif
if (xshrink > yshrink) {
nx = cr.right;
ny = (int) (by / xshrink);
} else {
ny = cr.bottom;
nx = (int) (bx / yshrink);
}
SetStretchBltMode(hdc, STRETCH_DELETESCANS);
StretchBlt(hdc, (cr.right - nx) / 2, (cr.bottom - ny) / 2, nx, ny,
hMemDC, 0, 0, bx, by, SRCCOPY);
}
SelectObject(hMemDC, obmap);
DeleteObject(ibmap);
if (bpal != NULL) {
if (active) {
SelectPalette(hdc, opal, FALSE);
}
SelectPalette(hMemDC, mopal, FALSE);
DeleteObject(bpal);
}
DeleteDC(hMemDC);
pClientData->face_shown = TRUE;
}
GlobalFreePtr(savepal);
}
face_failed:
if (!pClientData->face_shown) {
int n = 0;
RECT cr;
HFONT ofont;
char cryptoModes[256];
ofont = SelectObject(hdc, GetStockObject(ANSI_VAR_FONT));
SetBkColor(hdc, GetSysColor(COLOR_MENU));
SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
WinPrintf(hdc, n, 1, pClientData->modemConnection ?
rstring(IDS_T_DIAL_STRING) : rstring(IDS_T_HOST));
WinPrintf(hdc, n++, DCOL, pClientData->szHost);
if (pClientData->modemConnection) {
WinPrintf(hdc, n, 1, rstring(IDS_T_MODEM_CONNECTION_L));
} else {
WinPrintf(hdc, n, 1, rstring(IDS_T_ADDRESS));
WinPrintf(hdc, n++, DCOL, Format(48),
inet_ntoa(pClientData->inetSock.sin_addr),
pClientData->port);
}
// Transmitting ?
WinPrintf(hdc, n++, 1, pClientData->wantsInput ? rstring(IDS_T_TRANSMITTING) :
rstring(IDS_T_BLANKTRANSMIT));
// Transmission protocol
WinPrintf(hdc, n, 1, Format(71));
WinPrintf(hdc, n++, DCOL, rstring(IDS_PROTOCOL_TYPES + pClientData->protocol));
// Encryption modes
cryptoModes[0] = 0;
#define showCrypto(m, s) if ((m)) { if (cryptoModes[0] != 0) { strcat(cryptoModes, "+"); } strcat(cryptoModes, rstring(s)); }
showCrypto(pClientData->aes_spec, IDS_CRYPTO_AES);
showCrypto(pClientData->deskey[0], IDS_CRYPTO_DES);
showCrypto(pClientData->ideakey[0], IDS_CRYPTO_IDEA);
showCrypto(pClientData->opgpkey[0], pk_package == GPG ? IDS_PF_PUBLIC_KEY_GPG : IDS_CRYPTO_PGP);
showCrypto(pClientData->blowfish_spec, IDS_CRYPTO_BLOWFISH);
showCrypto(pClientData->otpFileName[0], IDS_CRYPTO_KEYFILE);
if (cryptoModes[0] != 0) {
WinPrintf(hdc, n, 1, Format(79));
WinPrintf(hdc, n++, DCOL, cryptoModes);
}
// If in conference, names of users
if ((pClientData->uname != NULL) &&
((pClientData->uname[0] & 0xFF) == 0xFF)) {
LPSTR sp, np;
int nl = 0;
WinPrintf(hdc, n, 1, Format(74));
sp = pClientData->uname + 1;
while (TRUE) {
np = strstr(sp, ", ");
if (np != NULL) {
*np = 0;
}
WinPrintf(hdc, n++, DCOL, "%s", sp);
if (np != NULL) {
*np = ',';
sp = np + 2;
} else {
break;
}
nl++;
/* Too many in conference causes a crash I cannot reproduce
Limit to 8 names shown for now. */
if (nl >= 8) {
WinPrintf(hdc, n++, DCOL, "...");
break;
}
}
} else { // Not in conference. Details of single user
// User name
if ((pClientData->uname != NULL) && (pClientData->uname[0])) {
WinPrintf(hdc, n, 1, Format(69));
WinPrintf(hdc, n++, DCOL, "%s", pClientData->uname);
}
// User's E-mail address
if (pClientData->email[0]) {
WinPrintf(hdc, n, 1, Format(70));
WinPrintf(hdc, n++, DCOL, "%s", pClientData->email);
}
// User's client program name
if (pClientData->szRemoteProgram[0]) {
WinPrintf(hdc, n, 1, Format(77));
WinPrintf(hdc, n++, DCOL, "%s", pClientData->szRemoteProgram);
}
}
#ifdef SHOW_STATE
/* It's nice to show the state, but costly to update on
every packet. */
WinPrintf(hdc, n, 1, "State:");
WinPrintf(hdc, n++, DCOL, "%s", stateToString(pClientData->state));
switch (pClientData->state) {
case Idle:
WinPrintf(hdc, n++, 1, blankit);
WinPrintf(hdc, n++, 1, blankit);
break;
case Transferring:
WinPrintf(hdc, n, 1, "File: ");
WinPrintf(hdc, n++, DCOL, "%s", pClientData->szFile);
WinPrintf(hdc, n, 1, "Bytes sent:");
WinPrintf(hdc, n++, DCOL, "%lu", pClientData->cbSent);
break;
case PlayingReceivedAudio:
WinPrintf(hdc, n, 1, "Bytes received:");
WinPrintf(hdc, n++, DCOL, "%lu", pClientData->cbReceived);
break;
}
#endif
SelectObject(hdc, ofont);
GetClientRect(hwnd, &cr);
if (cr.bottom != (n * tmHeight + 5)) {
RECT wr;
GetWindowRect(hwnd, &wr);
SetWindowPos(hwnd, HWND_TOP,
0, 0, wr.right - wr.left,
((wr.bottom - wr.top) - cr.bottom) +
(n * tmHeight + 5), SWP_NOMOVE | SWP_NOZORDER);
resized = TRUE;
//OutputDebugString("Resized connection window.\r\n");
}
}
#undef DCOL
}
EndPaint(hwnd, &psPaint);
if (resized) {
/* Oops--we resized the window after finishing the paint.
Now we have to invalidate it again so it will be
repainted in the new size. */
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
}
}
break;
case WM_MDIACTIVATE:
if (wParam == FALSE || IsIconic(hwnd)) {
break;
}
if (pClientData != NULL && pClientData->face_shown) {
HDC hdc;
BITMAPINFOHEADER *bmi;
HPALETTE bpal = NULL, opal;
int i;
LPLOGPALETTE lp;
BITMAPINFO *bh;
LPSTR lpalette;
#ifdef TRACE_FACE
{ char s[256];
wsprintf(s, "MDI activate %04X: %s\r\n", hwnd, pClientData->szHost);
OutputDebugString(s);
}
#endif
lpalette = GlobalAllocPtr(GPTR, sizeof(LOGPALETTE) +
sizeof(PALETTEENTRY) * 256);
if (lpalette != NULL) {
bmi = (BITMAPINFOHEADER *) (pClientData->face_bmp + sizeof(BITMAPFILEHEADER));
bh = (BITMAPINFO *) bmi;
lp = (LOGPALETTE *) lpalette;
lp->palVersion = 0x0300;
lp->palNumEntries = (WORD) bmi->biClrUsed;
for (i = 0; i < ((int) bmi->biClrUsed); i++) {
lp->palPalEntry[i].peRed = bh->bmiColors[i].rgbRed;
lp->palPalEntry[i].peGreen = bh->bmiColors[i].rgbGreen;
lp->palPalEntry[i].peBlue = bh->bmiColors[i].rgbBlue;
lp->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
}
bpal = CreatePalette(lp);
if (bpal != NULL) {
hdc = GetDC(hwnd);
opal = SelectPalette(hdc, bpal, FALSE);
i = RealizePalette(hdc);
SelectPalette(hdc, opal, FALSE);
DeleteObject(bpal);
ReleaseDC(hwnd, hdc);
if (i > 0) {
HWND oldwin;
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
oldwin = (HWND) wParam;
if (oldwin != NULL) {
InvalidateRect(oldwin, NULL, TRUE);
UpdateWindow(oldwin);
}
}
return i;
}
GlobalFreePtr(lpalette);
}
}
break;
#ifdef ASYNC_OUTPUT
case WM_SOCKET_SELECT:
if (pClientData != NULL) {
pClientData->outputSocketBusy = FALSE;
}
#ifdef OVERLOAD
{ char s[80];
wsprintf(s, "WM_SOCKET_SELECT Event = %d, Error = %d\r\n",
WSAGETSELECTEVENT(lParam), WSAGETSELECTERROR(lParam));
OutputDebugString(s);
}
#endif
case WM_SOCKET_CONTROL:
return 0;
#endif
case WM_SOCKET_ASYNC:
if (pClientData != NULL) {
if (WSAGETASYNCERROR(lParam) == 0) {
LPHOSTENT host;
host = (LPHOSTENT) pClientData->hostBuffer;
SetWindowText(hwnd, pClientData->localLoopback ?
rstring(IDS_T_LOOPBACK) : host->h_name);
strcpy(pClientData->szHost, host->h_name);
changeAudioState(hwnd, pClientData);
#ifdef SHOW_GET_HOST_NAME_ERROR
} else {
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(27),
pClientData->szHost, WSAGETASYNCERROR(lParam),
SockerrToString(WSAGETASYNCERROR(lParam)));
#endif
}
}
pClientData->getNameTask = NULL;
break;
/* Send text chat message as an RTCP APP packet on the control
channel. This is available only if the user is sending in
Speak Freely protocol. */
case WM_CHAT_TEXT_SEND:
if (protocolSent == PROTOCOL_SPEAKFREE) {
char v[256];
LPSTR chat_text = (LPSTR) lParam;
int l, n = strlen(chat_text);
l = rtp_make_app(v, ssrc, TRUE, RTCP_APP_TEXT_CHAT, chat_text);
// Set Speak Freely protocol flag in packet
v[0] = (char) ((v[0] & 0x3F) | (1 << 6));
sendSessionCtrl(pClientData, v, l);
}
break;
ca
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -