uconvert.c
来自「<Win2k系统编程>源码.次数为国人自编,内容丰富,还是不错的.」· C语言 代码 · 共 1,469 行 · 第 1/4 页
C
1,469 行
BYTE temp;
if (pDestinationData == NULL) return FALSE;
end = nBytesDestination - 2;
for (i = 0; i<= end; i+=2) {
temp = pDestinationData[i];
pDestinationData[i] = pDestinationData[i+1];
pDestinationData[i+1] = temp;
}
if (GetWindowTextLength (hwndByteOrder1) == 0)
SetWindowText (hwndByteOrder1,
LoadResourceString(IDS_BYTE_ORDER_REVERSED));
else
SetWindowText (hwndByteOrder1, szBlank);
} break;
/**********************************************************************\
* WM_COMMAND, MID_CLEARDESTINATION
*
* Clear the destination information. May cause data to be lost.
\**********************************************************************/
case MID_CLEARDESTINATION:
SetWindowText (hwndSize1, szBlank);
SetWindowText (hwndName1, szBlank);
SetWindowText (hwndByteOrder1, szBlank);
pDestinationData= ManageMemory (MMFREE, MMDESTINATION, 0, pDestinationData);
break;
/**********************************************************************\
* WM_COMMAND, MID_CLEARSOURCE
*
* Clear the SOURCE information. May cause data to be lost.
\**********************************************************************/
case MID_CLEARSOURCE:
SetWindowText (hwndSize0, szBlank);
SetWindowText (hwndName0, szBlank);
SetWindowText (hwndByteOrder0, szBlank);
pSourceData= ManageMemory (MMFREE, MMSOURCE, 0, pSourceData);
break;
/******************************************************************\
* WM_COMMAND, MID_INSTALLTABLES
*
\******************************************************************/
case MID_INSTALLTABLES:
DialogBox (hInst, TEXT("InstallTableDlg"), hwnd, (DLGPROC)InstallTableProc);
break;
/* Simply call WinHelp to display the OnLine help file. */
case MID_HELP:
WinHelp( hwnd, szHelpPathName, HELP_INDEX, (DWORD) NULL );
break;
/* No-op Window procedure to simply display the dialog box. */
case MID_ABOUT:
ShellAbout (hwnd, TEXT("UConvert"), NULL, LoadIcon (hInst, TEXT("uconvertIcon")));
break;
/* Just close the window. */
case MID_EXIT:
PostMessage (hwnd, WM_CLOSE, 0,0);
break;
} /* end switch (LOWORD(wParam)) */
break; /* end WM_COMMAND */
default: break;
} /* end switch */
return (DefWindowProc(hwnd, message, wParam, lParam));
}
/**************************************************************************\
*
* function: IsUnicode()
*
* HACK... eventually use a proper function for IsUnicode
* Use function from unipad?
*
\**************************************************************************/
BOOL IsUnicode (PBYTE pb)
{
return (IsBOM (pb));
}
/**************************************************************************\
*
* function: IsBOM()
*
* true iff pb points to a Byte Order Mark.
*
\**************************************************************************/
BOOL IsBOM (PBYTE pb)
{
if ((*pb == 0xFF) & (*(pb+1) == 0xFE)) // BOM
return TRUE;
else
return FALSE;
}
/**************************************************************************\
*
* function: IsRBOM()
*
* true iff pb points to a reversed Byte Order Mark.
*
\**************************************************************************/
BOOL IsRBOM (PBYTE pb)
{
if ((*pb == 0xFE) & (*(pb+1) == 0xFF)) // RBOM
return TRUE;
else
return FALSE;
}
/**************************************************************************\
*
* function: framechildwindow()
*
* Simply draw a 3D frame around child window.
*
\**************************************************************************/
VOID framechildwindow (HDC hdc, HWND hwndParent, HWND hwndChild)
{
RECT rect;
GetWindowRect (hwndChild, &rect);
/* minor hack... assumes RECT is two points, right field starting first */
ScreenToClient (hwndParent, (LPPOINT)&rect);
ScreenToClient (hwndParent, (LPPOINT)&(rect.right));
InflateRect (&rect, 1, 1);
FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
InflateRect (&rect, -1, -1);
SelectObject (hdc, GetStockObject (WHITE_PEN));
MoveToEx (hdc, rect.right, rect.top, NULL);
LineTo (hdc,rect.right, rect.bottom);
LineTo (hdc,rect.left, rect.bottom);
return;
}
/**************************************************************************\
*
* function: underlinechildwindow()
*
* Underline child window.
*
\**************************************************************************/
VOID underlinechildwindow (HDC hdc, HWND hwndParent, HWND hwndChild)
{
RECT rect;
GetWindowRect (hwndChild, &rect);
/* minor hack... assumes RECT is two points, right field starting first */
ScreenToClient (hwndParent, (LPPOINT)&rect);
ScreenToClient (hwndParent, (LPPOINT)&(rect.right));
InflateRect (&rect, 1, 1);
rect.top = rect.bottom-1;
FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
SelectObject (hdc, GetStockObject (WHITE_PEN));
MoveToEx (hdc, rect.right, rect.bottom, NULL);
LineTo (hdc,rect.left, rect.bottom);
return;
}
/**************************************************************************\
*
* function: createwindows()
*
* Create the child windows and pass the handles back in parameters.
* Each Window is created relative to (inside of) prect.
* top is a spacial pointer to the Y coordinate of the next window.
*
\**************************************************************************/
VOID createwindows(PRECT prect,
HWND hwndParent,
HWND* hwndLabel,
HWND* hwndName,
HWND* hwndSize,
HWND* hwndCodePage,
HWND* hwndByteOrder,
HWND* hwndButton)
{
int top;
top = prect->top;
*hwndLabel = CreateWindow(
TEXT("STATIC"),
szBlank,
WS_CHILD | WS_VISIBLE | SS_CENTER,
prect->left,
top,
prect->right - prect->left,
WHEIGHT,
hwndParent, NULL, hInst, 0);
top += WHEIGHT*5/2;
*hwndName = CreateWindow(
TEXT("STATIC"),
szBlank,
WS_CHILD | WS_VISIBLE | SS_RIGHT,
prect->left,
top,
prect->right - prect->left,
WHEIGHT,
hwndParent, NULL, hInst, 0);
top += WHEIGHT*2;
*hwndSize = CreateWindow(
TEXT("STATIC"),
szBlank,
WS_CHILD | WS_VISIBLE | SS_LEFT,
prect->left,
top,
(prect->right - prect->left) *3/4,
WHEIGHT,
hwndParent, NULL, hInst, 0);
top += WHEIGHT*2;
*hwndCodePage = CreateWindow(
TEXT("STATIC"),
szBlank,
WS_CHILD | WS_VISIBLE | SS_LEFT,
prect->left,
top,
(prect->right - prect->left) *3/4,
WHEIGHT,
hwndParent, NULL, hInst, 0);
top += WHEIGHT*2;
*hwndByteOrder = CreateWindow(
TEXT("STATIC"),
szBlank,
WS_CHILD | WS_VISIBLE | SS_LEFT,
prect->left,
top,
(prect->right - prect->left) *3/4,
WHEIGHT,
hwndParent, NULL, hInst, 0);
top += WHEIGHT*2;
*hwndButton = CreateWindow(
TEXT("BUTTON"),
TEXT("ViewText"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
prect->left,
top,
prect->right - prect->left,
WHEIGHT*9/7,
hwndParent, NULL, hInst, 0);
return;
}
/**************************************************************************\
*
* function: ManageMemory()
*
* Do all memory management here for the source and destination pointers.
* We also enable/disable the "View..." buttons to reflect existence of data.
*
*
* PARAMETERS
*
* message : {MMALLOC, MMFREE}
* Alloc when requested by MMALLOC, and free the existing, passed in, pointer.
* Free when requested by MMFREE.
* sourcedestination : {MMSOURCE, MMDESTINATION}
* nBytes - number to alloc on MMALLOC messages.
* p - old pointer to be freed.
*
*
* GLOBALS
*
* hwndButton0, hwndButton1
*
\**************************************************************************/
LPVOID ManageMemory (UINT message, UINT sourcedestination, DWORD nBytes, LPVOID p)
{
switch (message) {
case MMFREE :
if (sourcedestination == MMSOURCE)
EnableWindow (hwndButton0, FALSE);
else if (sourcedestination == MMDESTINATION)
EnableWindow (hwndButton1, FALSE);
if (p != NULL) GlobalFree (GlobalHandle (p));
return NULL;
break;
case MMALLOC :
if (sourcedestination == MMSOURCE)
EnableWindow (hwndButton0, TRUE);
else if (sourcedestination == MMDESTINATION)
EnableWindow (hwndButton1, TRUE);
if (p != NULL) GlobalFree (GlobalHandle (p));
p = (LPVOID) GlobalAlloc (GPTR, nBytes);
return p;
break;
} /* end switch (message) */
return NULL;
}
/**************************************************************************\
*
* function: LoadResourceString()
*
* Loads a resource string from string table and returns a pointer
* to the string.
*
* PARAMETERS: wID - resource string id
*
\**************************************************************************/
LPTSTR LoadResourceString(UINT wID)
{
static TCHAR szBuf[512];
LoadString((HANDLE)GetModuleHandle(NULL),wID,szBuf,sizeof(szBuf));
return szBuf;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?