VOID PROGRAM_ModifyProgram(HLOCAL hProgram) { PROGRAM *program = LocalLock(hProgram); CHAR szName[MAX_PATHNAME_LEN]; CHAR szCmdLine[MAX_PATHNAME_LEN]; CHAR szIconFile[MAX_PATHNAME_LEN]; CHAR szWorkDir[MAX_PATHNAME_LEN]; lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN); lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN); lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN); lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN); if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile, &program->hIcon, &program->nIconIndex, &program->nHotKey, &program->nCmdShow, MAX_PATHNAME_LEN)) return; MAIN_ReplaceString(&program->hName, szName); MAIN_ReplaceString(&program->hCmdLine, szCmdLine); MAIN_ReplaceString(&program->hIconFile, szIconFile); MAIN_ReplaceString(&program->hWorkDir, szWorkDir); SetWindowText(program->hWnd, szName); UpdateWindow(program->hWnd); GRPFILE_WriteGroupFile(program->hGroup); return; }
LPCSTR PROGRAM_ProgramName(HLOCAL hProgram) { PROGRAM *program; if (!hProgram) return(0); program = LocalLock(hProgram); return(LocalLock(program->hName)); }
BOOL GRPFILE_WriteGroupFile(HLOCAL hGroup) { CHAR szPath[MAX_PATHNAME_LEN]; PROGGROUP *group = LocalLock(hGroup); OFSTRUCT dummy; HFILE file; BOOL ret; GRPFILE_ModifyFileName(szPath, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN, group->bFileNameModified); /* Try not to overwrite original files */ /* group->bOverwriteFileOk == TRUE only if a file has the modified format */ if (!group->bOverwriteFileOk && OpenFile(szPath, &dummy, OF_EXIST) != HFILE_ERROR) { /* Original file exists, try `.gr' extension */ GRPFILE_ModifyFileName(szPath, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN, TRUE); if (OpenFile(szPath, &dummy, OF_EXIST) != HFILE_ERROR) { /* File exists. Do not overwrite */ MAIN_MessageBoxIDS_s(IDS_FILE_NOT_OVERWRITTEN_s, szPath, IDS_INFO, MB_OK); return FALSE; } /* Inform about the modified file name */ if (IDCANCEL == MAIN_MessageBoxIDS_s(IDS_SAVE_GROUP_AS_s, szPath, IDS_INFO, MB_OKCANCEL | MB_ICONINFORMATION)) return FALSE; } { /* Warn about the (possible) incompatibility */ CHAR msg[MAX_PATHNAME_LEN + 200]; wsprintf(msg, "Group files written by this DRAFT Program Manager " "possibly cannot be read by the Microsoft Program Manager!!\n" "Are you sure to write %s?", szPath); if (IDOK != MessageBox(Globals.hMainWnd, msg, "WARNING", MB_OKCANCEL | MB_DEFBUTTON2)) return FALSE; } /* Open file */ file = _lcreat(szPath, 0); if (file != HFILE_ERROR) { ret = GRPFILE_DoWriteGroupFile(file, group); _lclose(file); } else ret = FALSE; if (!ret) MAIN_MessageBoxIDS_s(IDS_FILE_WRITE_ERROR_s, szPath, IDS_ERROR, MB_OK); return(ret); }
LPCSTR GROUP_GroupName(HLOCAL hGroup) { PROGGROUP *group; if (!hGroup) return(0); group = LocalLock(hGroup); return(LocalLock(group->hName)); }
unsigned long NEAR PASCAL MyQueryValue(HKEY hKey, PSTR pSubKey, HANDLE *hBuf) { HANDLE hTemp; PSTR pBuf; WORD wBufSize = BLOCKLEN; unsigned long result = ERROR_OUTOFMEMORY; LONG lSize; if(!(*hBuf=LocalAlloc(LMEM_MOVEABLE, wBufSize))) goto Error1; if(!(pBuf=LocalLock(*hBuf))) goto Error2; while((lSize=wBufSize, (result=RegQueryValue(hKey, pSubKey, pBuf, &lSize)) ==ERROR_SUCCESS) && (WORD)lSize>wBufSize-10) { LocalUnlock(*hBuf); wBufSize += BLOCKLEN; if(!(hTemp=LocalReAlloc(*hBuf, wBufSize, LMEM_MOVEABLE))) { result = ERROR_OUTOFMEMORY; goto Error2; } pBuf = LocalLock(*hBuf=hTemp); } LocalUnlock(*hBuf); if(result!=ERROR_SUCCESS || !lSize) goto Error2; goto Error1; Error2: LocalFree(*hBuf); *hBuf = NULL; Error1: return(result); }
unsigned long NEAR PASCAL MyEnumKey(HKEY hKey, WORD wIndex, HANDLE *hBuf) { HANDLE hTemp; PSTR pBuf; WORD wBufSize = BLOCKLEN, wSize; unsigned long result = ERROR_OUTOFMEMORY; if(!(*hBuf=LocalAlloc(LMEM_MOVEABLE, wBufSize))) goto Error1; if(!(pBuf=LocalLock(*hBuf))) goto Error2; while((result=RegEnumKey(hKey, wIndex, pBuf, (DWORD)wBufSize)) ==ERROR_SUCCESS && (wSize=lstrlen(pBuf))>wBufSize-10) { LocalUnlock(*hBuf); wBufSize += BLOCKLEN; if(!(hTemp=LocalReAlloc(*hBuf, wBufSize, LMEM_MOVEABLE))) { result = ERROR_OUTOFMEMORY; goto Error2; } pBuf = LocalLock(*hBuf=hTemp); } LocalUnlock(*hBuf); if(result!=ERROR_SUCCESS || !wSize) goto Error2; goto Error1; Error2: LocalFree(*hBuf); *hBuf = NULL; Error1: return(result); }
static VOID HandleSetHandlePrintHex(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam) { LPVOID pMem; HANDLE hNewBuffer; int ret; LocalFree((HLOCAL)SendMessage(handle, EM_GETHANDLE, 0, 0L)); if (UnicodeUsed) { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 100); pMem = LocalLock(hNewBuffer); strcpyw_((wchar_t*)pMem,NewTextW); } else { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,50); pMem = LocalLock(hNewBuffer); strcpy_((char*)pMem,NewText); } LocalUnlock(pMem); hNewBuffer = LocalHandle(pMem); /* Updates the buffer and displays new buffer */ ret = SendMessage(handle, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L); htoa(ret,&TextBuffer[8]); PrintTextXY(TextBuffer,ResultX,ResultY,16); }
VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile) { PROGRAM *program = LocalLock(hProgram); PROGGROUP *group = LocalLock(program->hGroup); group->hActiveProgram = 0; if (program->hPrior) ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext; else ((PROGGROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext; if (program->hNext) ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior; if (bUpdateGrpFile) GRPFILE_WriteGroupFile(program->hGroup); DestroyWindow(program->hWnd); #if 0 if (program->hIcon) DestroyIcon(program->hIcon); #endif LocalFree(program->hName); LocalFree(program->hCmdLine); LocalFree(program->hIconFile); LocalFree(program->hWorkDir); LocalFree(hProgram); }
// --------------------------------------------------------------------------- // HBITMAP __fastcall TForm1::SPI_LoadImage(String fileName) { /* 対応プラグインの検索 */ for (int i = 0; i < hSPI->Count; i++) { // プラグイン関数の取得 SPI_ISSUPPORTED spi_issupported = (SPI_ISSUPPORTED) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_ISSUPPORTED); SPI_GETPICTURE spi_getpicture = (SPI_GETPICTURE) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_GETPICTURE); if (spi_issupported == NULL || spi_getpicture == NULL) { continue; } // File内容をロードする HANDLE handle; // = NULL; if ((handle = CreateFile_Read(fileName.w_str())) == INVALID_HANDLE_VALUE) { return NULL; } DWORD filesize = GetFileSize(handle, NULL), readsize; LPSTR data = (LPSTR) Heap_Malloc(filesize); SetFilePointer(handle, 0, NULL, FILE_BEGIN); if (!ReadFile(handle, data, filesize, &readsize, NULL)) { CloseHandle(handle); } CloseHandle(handle); // ロードできる形式かどうかをチェックする if (spi_issupported(AnsiString(fileName).c_str(), (DWORD) data) == 0) { Heap_Free(data); continue; } // 画像を展開する HLOCAL info, bm; if (spi_getpicture(data, filesize, 1, &info, &bm, NULL, 0) != 0) { Heap_Free(data); } LPBITMAPINFO bmpinfo = (LPBITMAPINFO) LocalLock(info); // BITMAPINFO構造体 LPBYTE bmbits = (LPBYTE) LocalLock(bm); // 画像データ // 取得した情報からBITMAPハンドルを生成する HDC dc = GetDC(0); HBITMAP bitmap = CreateDIBitmap(dc, &bmpinfo->bmiHeader, CBM_INIT, bmbits, bmpinfo, DIB_RGB_COLORS); ReleaseDC(0, dc); // Free etc... LocalUnlock(info); LocalFree(info); LocalUnlock(bm); LocalFree(bm); Heap_Free(data); return bitmap; } return NULL; }
/* MDIWndProc */ LRESULT CALLBACK MDIWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HANDLE hInfo; PINFO pInfo; MSG msg; EventRecord macEvent; LONG thePoints = GetMessagePos(); PAINTSTRUCT ps; msg.hwnd = hwnd; msg.message = message; msg.wParam = wParam; msg.lParam = lParam; msg.time = GetMessageTime(); msg.pt.x = LOWORD(thePoints); msg.pt.y = HIWORD(thePoints); WinEventToMacEvent(&msg, &macEvent); switch (message) { case WM_CREATE: case WM_MDICREATE: break; case WM_DESTROY: hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL){ if (pInfo->gi) // close the graphic import component CloseComponent(pInfo->gi); // Destroy our port association DestroyPortAssociation((CGrafPort *)GetHWNDPort(pInfo->hwndChildWindow)); } LocalUnlock(hInfo); } break; // Draw our graphic case WM_PAINT: BeginPaint(hwnd, &ps); hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL) GraphicsImportDraw(pInfo->gi); LocalUnlock(hInfo); } EndPaint(hwnd, &ps); break; default: return DefMDIChildProc(hwnd, message, wParam, lParam); } return DefMDIChildProc(hwnd, message, wParam, lParam); }
VOID PROGRAM_ExecuteProgram(HLOCAL hProgram) { PROGRAM *program = LocalLock(hProgram); LPSTR lpszCmdLine = LocalLock(program->hCmdLine); /* FIXME set working directory from program->hWorkDir */ WinExec(lpszCmdLine, program->nCmdShow); if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd); }
VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove) { PROGRAM *program = LocalLock(hProgram); PROGGROUP *fromgroup = LocalLock(program->hGroup); HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName), LocalLock(fromgroup->hName), bMove); if (!hGroup) return; /* FIXME shouldn't be necessary */ OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd); if (!PROGRAM_AddProgram(hGroup, #if 0 CopyIcon(program->hIcon), #else program->hIcon, #endif LocalLock(program->hName), program->x, program->y, LocalLock(program->hCmdLine), LocalLock(program->hIconFile), program->nIconIndex, LocalLock(program->hWorkDir), program->nHotKey, program->nCmdShow)) return; GRPFILE_WriteGroupFile(hGroup); if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE); }
HLOCAL GRPFILE_ReadGroupFile(LPCSTR lpszPath) { CHAR szPath_gr[MAX_PATHNAME_LEN]; BOOL bFileNameModified = FALSE; OFSTRUCT dummy; HLOCAL hBuffer, hGroup; INT size; /* if `.gr' file exists use that */ GRPFILE_ModifyFileName(szPath_gr, lpszPath, MAX_PATHNAME_LEN, TRUE); if (OpenFile(szPath_gr, &dummy, OF_EXIST) != HFILE_ERROR) { lpszPath = szPath_gr; bFileNameModified = TRUE; } /* Read the whole file into a buffer */ if (!GRPFILE_ReadFileToBuffer(lpszPath, &hBuffer, &size)) { MAIN_MessageBoxIDS_s(IDS_GRPFILE_READ_ERROR_s, lpszPath, IDS_ERROR, MB_YESNO); return(0); } /* Interpret buffer */ hGroup = GRPFILE_ScanGroup(LocalLock(hBuffer), size, lpszPath, bFileNameModified); if (!hGroup) MAIN_MessageBoxIDS_s(IDS_GRPFILE_READ_ERROR_s, lpszPath, IDS_ERROR, MB_YESNO); LocalFree(hBuffer); return(hGroup); }
static void Adjust4FillFactors(HWND hwnd) /* Function: Adjusts the maximum values of limits that are affected by the changes in fill factors. Parameters: hwnd - Handle of dialog window Returns: None. */ { INFOOFFSET infoIdx = GetSelectedStructure(hwnd); STRUCTINFO info; HLOCAL hmem = GetProp(hwnd, SZINFODEF); LPSTRUCTINFO lpinfo = LocalLock(hmem); info.nIngresVersion= GetOIVers(); GetDialogInfo(hwnd, &info); /* ** BUG #112863 : in r3 the row width can be 256K and row can span page! */ if (info.nIngresVersion < OIVERS_30) { if (info.dwPageSize == 65536L) lpinfo[infoIdx].nRowWidth = 32767L; else lpinfo[infoIdx].nRowWidth = info.dwPageSize - GetPageOverHead(info.iPageType) - GetRowOverHead(info.iPageType); } LocalUnlock(hmem); }
/* * getItemMsg - find the hint message for the specified menu item */ static msg_id getItemMsg( statwnd *wnd, ctl_id menuid ) { int i; HWND hint; HLOCAL hinfo; HintWndInfo *info; const MenuItemHint *hinttable; msg_id msgid; hint = GetHintHwnd( wnd ); hinfo = GetProp( hint, HINT_PROP_ID ); info = LocalLock( hinfo ); hinttable = info->hints; msgid = HINT_EMPTY; if( hinttable != NULL ) { for( i = 0; i < info->hint_num_items; i++ ) { if( hinttable[i].menuid == menuid ) { msgid = hinttable[i].msgid; break; } } } LocalUnlock( hinfo ); return( msgid ); } /* getItemMsg */
/* * SizeHintBar - resize the hint bar */ WORD SizeHintBar( statwnd *wnd ) { HLOCAL hinfo; HintWndInfo *info; HFONT font; HFONT oldfont; HDC dc; SIZE sz; RECT area; HWND hint; hint = GetHintHwnd( wnd ); hinfo = GetProp( hint, HINT_PROP_ID ); info = LocalLock( hinfo ); dc = GetDC( hint ); font = GetMonoFont(); oldfont = SelectObject( dc, font ); GetTextExtentPoint( dc, "A", 1, &sz ); SelectObject( dc, oldfont ); ReleaseDC( hint, dc ); GetClientRect( info->parent, &area ); area.top = area.bottom - sz.cy - TOTAL_VERT; MoveWindow( hint, area.left, area.top, area.right - area.left, area.bottom - area.top, TRUE ); updateHintText( wnd, info->curmsg ); GetWindowRect( hint, &area ); LocalUnlock( hinfo ); return( (WORD)( area.bottom - area.top ) ); } /* SizeHintBar */
HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup) { PROGGROUP *group; if (!hGroup) return(0); group = LocalLock(hGroup); return(group->hPrograms); }
HWND GROUP_GroupWnd(HLOCAL hGroup) { PROGGROUP *group; if (!hGroup) return(0); group = LocalLock(hGroup); return(group->hWnd); }
HLOCAL GROUP_NextGroup(HLOCAL hGroup) { PROGGROUP *group; if (!hGroup) return(0); group = LocalLock(hGroup); return(group->hNext); }
void CStationDlg::OnClickedDecodeh(void) { CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1); int i,j; cetodo->GetSel(i,j); // NT SPECIFIC HLOCAL h = cetodo->GetHandle(); LPCTSTR lpszText = (LPCTSTR)LocalLock(h); char res[1000]; strncpy(res,&(lpszText[i]),j-i); SetDlgItemText(IDC_DECDEC,res); unsigned short f; unsigned char *pf; unsigned int b1,b2; pf = (unsigned char *)&f; sscanf(res,"%x %x",&b1,&b2); pf[0] = b1; pf[1] = b2; CString sres; sres.Format("%04X = %d",f,f); SetDlgItemText(IDC_DECFLOAT,sres); LocalUnlock(h); // END OF NT SPECIFIC }
void CStationDlg::OnClickedDecodesel(void) { CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1); int i,j; cetodo->GetSel(i,j); // NT SPECIFIC HLOCAL h = cetodo->GetHandle(); LPCTSTR lpszText = (LPCTSTR)LocalLock(h); char res[1000]; strncpy(res,&(lpszText[i]),j-i);res[j-i] = 0; CString sres = res; sres.Replace("\r\n",""); SetDlgItemText(IDC_DECDEC,sres); float f; unsigned char *pf; unsigned int b1,b2,b3,b4; pf = (unsigned char *)&f; sscanf(sres,"%x %x %x %x",&b1,&b2,&b3,&b4); pf[0] = b1; pf[1] = b2; pf[2] = b3; pf[3] = b4; sres.Format("%g",f); SetDlgItemText(IDC_DECFLOAT,sres); LocalUnlock(h); // END OF NT SPECIFIC }
void * iC_emalloc(unsigned nbytes) /* check return from malloc */ { void * bp; #ifdef _WINDOWS #if defined(_LARGE_) || defined(_HUGE_) GLOBALHANDLE hglobal; if ((hglobal = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nbytes)) == 0) { err(1, "%s", iC_progname); /* hard ERROR */ } bp = GlobalLock(hglobal); /* actual pointer */ #else LOCALHANDLE hlocal; if ((hlocal = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, nbytes)) == 0) { err(1, "%s", iC_progname); /* hard ERROR */ } bp = LocalLock(hlocal); /* actual pointer */ #endif #else if ((bp = malloc(nbytes)) == NULL) { err(1, "%s", iC_progname); /* hard ERROR */ } #endif memset(bp, 0, nbytes); /* when free() is used memory can be non zero */ return bp; } /* iC_emalloc */
void COTPPancel::OnViewPublicKey() { // TODO: Add your control notification handler code here CViewPublicKey dlg; if(dlg.DoModal() == IDOK) { //Save PublicKey to file CFile file; CFileException fError; if(m_PublicKeyFileName.IsEmpty() == TRUE) { return; } file.Open(m_PublicKeyFileName.GetBuffer(0),CFile::modeWrite,&fError); if(fError.m_cause != CFileException::none) //file error { HLOCAL hlocal = NULL; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER,NULL,fError.m_lOsError,0,(LPTSTR)&hlocal,0,NULL); CString errorout = (LPTSTR)LocalLock(hlocal); AfxMessageBox(errorout,MB_OK|MB_ICONERROR); return; } file.Write(gPublicKey.bytePublicKey,GOZONE_PUBLICKEY_LEN); file.Close(); } }
HLOCAL PROGRAM_NextProgram(HLOCAL hProgram) { PROGRAM *program; if (!hProgram) return(0); program = LocalLock(hProgram); return(program->hNext); }
void near *lmem_realloc( /**********************/ void *mem, unsigned size ) { #ifdef PLAT_OS2 return( realloc( mem, (size_t) size ) ); #else HANDLE hld; void near *ptr; if( mem != NULL ) { hld = _wpi_getlocalhdl( mem ); if( hld ) { LocalUnlock( hld ); hld = LocalReAlloc( hld, size, LMEM_MOVEABLE ); if( hld ) { ptr = LocalLock( hld ); return( ptr ); } } } else { return( lmem_alloc( size ) ); } return( NULL ); #endif }
void * LocalAllocPtr(UINT flags, UINT size) { HLOCAL hlocal; hlocal = LocalAlloc(flags, size+1); return (char *)LocalLock(hlocal); }
void ProcessWatch::WriteToLog(TCHAR *strToWrite, int id, BOOL isError) { string strWrite = UnicodeToANSI(strToWrite); char time[128] = {}; if(isError) { HLOCAL hlocal = NULL; DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); BOOL fOk = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, id, systemLocale, (PTSTR)&hlocal, 0, NULL); if(fOk && (hlocal != NULL)) { GetTime(time, sizeof(time)); m_file << "[" << time << "]" << " ERROR: " << (PCTSTR)LocalLock(hlocal) << endl; LocalFree(hlocal); } } else { GetTime(time, sizeof(time)); m_file << "[" << time << "]" << strWrite.c_str() << endl; } }
void *SubAlloc(WORD wSeg, unsigned size) /* wSeg is the global segment's selector */ { HANDLE hBlock; /* better be a stack variable */ void *Block; /* better be a stack variable */ #if MEMTRACE WORD RealSize = 0;/* better be a stack variable */ #endif SWITCH_DS(wSeg) hBlock = LocalAlloc (LMEM_FIXED | LMEM_NOCOMPACT, size); /* no point attempting compaction: everything is FIXED in this heap! */ if (hBlock) { Block = (void*)(LPSTR)LocalLock (hBlock); #if MEMTRACE RealSize = LocalSize (hBlock); #endif } RESTORE_DS #if MEMTRACE mtr[mtrx].m_func = MTR_SUBALLOC; mtr[mtrx].m_ptr.m_block = hBlock ? Block : NULL; mtr[mtrx].m_size = RealSize; mtr[mtrx++].m_optimseg = OptimumSeg; #endif if (hBlock) return Block; /* success ! */ else return NULL; /* failure!! */ } /* SubAlloc */
BOOL CStatusBar::Create(int x, int y, int iWidth, int iHeight, DWORD dwStyle, int nParts) { BOOL bRet = FALSE; LPINT lpParts; RECT rcClient; int nWidth = 0; m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, dwStyle, x, y, iWidth, iHeight, m_hParent, m_hMenu, m_hInst, NULL); if (!m_hwndStatus) { return bRet; } GetClientRect(m_hParent, &rcClient); //allocates the specified number of bytes from the heap m_hLoc = LocalAlloc(LHND, sizeof(int) * nParts); lpParts = (LPINT)LocalLock(m_hLoc); nWidth = (rcClient.right - rcClient.left) / nParts; for (int i = 0; i < nParts; i++) { lpParts[i] = nWidth; nWidth += nWidth; } SendMessage(m_hwndStatus, SB_SETPARTS, (WPARAM)nParts, (LPARAM)lpParts); LocalUnlock(m_hLoc); LocalFree(m_hLoc); bRet = TRUE; return bRet; }
//*********************************************************************** // // void GetResultStr() // // This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on. // //*********************************************************************** void GetResultStr( HWND hwnd ) { LONG bufLen; // Storage for length of result str. LPSTR lpResultStr; // Pointer to result string. HIMC hIMC; // Input context handle. HLOCAL hMem; // Memory handle. // // If fail to get input context handle then do nothing. // if ( !( hIMC = ImmGetContext( hwnd ) ) ) return; // // Determines how much memory space to store the result string. // Applications should call ImmGetCompositionString with // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer // length. // if ( ( bufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void *)NULL, (DWORD) 0 ) ) <= 0 ) goto exit2; // // Allocates memory with bufLen+1 bytes to store the result // string. Here we allocale on more byte to put null character. // if ( !( hMem = LocalAlloc( LPTR, (int)bufLen + 1 ) ) ) goto exit2; if ( !( lpResultStr = (LPSTR) LocalLock( hMem ) ) ) goto exit1; // // Reads in the result string. // ImmGetCompositionString( hIMC, GCS_RESULTSTR, lpResultStr, bufLen ); // // Displays the result string. // DisplayResultString( hwnd, lpResultStr ); LocalUnlock( hMem ); exit1: LocalFree( hMem ); exit2: ImmReleaseContext( hwnd, hIMC ); }