|
|
|
|
|
|
|
|
Freeing up DLLs, avoiding suspend mode, and listbox tricks (continued)
Also, the desktop requires that the data being put on the clipboard be allocated with GlobalAlloc. Windows CE doesn't support GlobalAlloc, so LocalAlloc with the LMEM_MOVEABLE flag should be used.
The following code snippet shows how to work around Windows CE's shortcomings and put the clipboard APIs to work:
/*
Put a text buffer on the clipboard
*/
BOOL PutTextOnClipboard(HWND hwnd, LPTSTR pszText)
{
BOOL bSuccess = FALSE;
if ( IsWindow(hwnd) && OpenClipboard(hwnd) )
{
EmptyClipboard();
LPTSTR pszCopy = (LPTSTR)LocalAlloc(LMEM_MOVEABLE, (_tcslen(pszText)+1) * sizeof(TCHAR));
if ( pszCopy )
{
_tcscpy(pszCopy, pszText);
UINT uiFormat;
#ifdef UNICODE
uiFormat = CF_UNICODETEXT;
#else
uiFormat = CF_TEXT;
#endif
bSuccess = (SetClipboardData(uiFormat, pszCopy) != NULL);
// if the clipboard doesn't own the data, we need to free it
if ( bSuccess == FALSE )
LocalFree(pszCopy);
}
CloseClipboard();
}
return bSuccess;
}
|
That's all we have room for this month. I look forward to hearing about what ails you (regarding development for CE, that is), at poweranswers@bsquare.com.
Andrew Tucker works on developer tools for Windows CE at bSQUARE Corporation. He has been writing code for Windows since 1991 and has published articles in C/C++ Users Journal, Dr Dobbs Journal, and Windows Developer Journal. He recently co-authored SAMS Teach Yourself Windows CE Programming in 24 Hours. Andrew has a BSCS from Seattle Pacific University and is working on a MSCS at the University of Washington. He can be reached at poweranswers@bsquare.com.
|
|
|
|
|
|
|
|
|
|
|