📄 commctrl.c
字号:
* Failure: 0
*/
HBITMAP WINAPI
CreateMappedBitmap (HINSTANCE hInstance, INT_PTR idBitmap, UINT wFlags,
LPCOLORMAP lpColorMap, INT iNumMaps)
{
HGLOBAL hglb;
HRSRC hRsrc;
LPBITMAPINFOHEADER lpBitmap, lpBitmapInfo;
UINT nSize, nColorTableSize, iColor;
RGBQUAD *pColorTable;
INT i, iMaps, nWidth, nHeight;
HDC hdcScreen;
HBITMAP hbm;
LPCOLORMAP sysColorMap;
COLORREF cRef;
COLORMAP internalColorMap[4] =
{{0x000000, 0}, {0x808080, 0}, {0xC0C0C0, 0}, {0xFFFFFF, 0}};
/* initialize pointer to colortable and default color table */
if (lpColorMap) {
iMaps = iNumMaps;
sysColorMap = lpColorMap;
}
else {
internalColorMap[0].to = GetSysColor (COLOR_BTNTEXT);
internalColorMap[1].to = GetSysColor (COLOR_BTNSHADOW);
internalColorMap[2].to = GetSysColor (COLOR_BTNFACE);
internalColorMap[3].to = GetSysColor (COLOR_BTNHIGHLIGHT);
iMaps = 4;
sysColorMap = (LPCOLORMAP)internalColorMap;
}
hRsrc = FindResourceW (hInstance, (LPWSTR)idBitmap, (LPWSTR)RT_BITMAP);
if (hRsrc == 0)
return 0;
hglb = LoadResource (hInstance, hRsrc);
if (hglb == 0)
return 0;
lpBitmap = (LPBITMAPINFOHEADER)LockResource (hglb);
if (lpBitmap == NULL)
return 0;
if (lpBitmap->biSize >= sizeof(BITMAPINFOHEADER) && lpBitmap->biClrUsed)
nColorTableSize = lpBitmap->biClrUsed;
else if (lpBitmap->biBitCount <= 8)
nColorTableSize = (1 << lpBitmap->biBitCount);
else
nColorTableSize = 0;
nSize = lpBitmap->biSize + nColorTableSize * sizeof(RGBQUAD);
lpBitmapInfo = (LPBITMAPINFOHEADER)GlobalAlloc (GMEM_FIXED, nSize);
if (lpBitmapInfo == NULL)
return 0;
RtlMoveMemory (lpBitmapInfo, lpBitmap, nSize);
pColorTable = (RGBQUAD*)(((LPBYTE)lpBitmapInfo)+(UINT)lpBitmapInfo->biSize);
for (iColor = 0; iColor < nColorTableSize; iColor++) {
for (i = 0; i < iMaps; i++) {
cRef = RGB(pColorTable[iColor].rgbRed,
pColorTable[iColor].rgbGreen,
pColorTable[iColor].rgbBlue);
if ( cRef == sysColorMap[i].from) {
#if 0
if (wFlags & CBS_MASKED) {
if (sysColorMap[i].to != COLOR_BTNTEXT)
pColorTable[iColor] = RGB(255, 255, 255);
}
else
#endif
pColorTable[iColor].rgbBlue = GetBValue(sysColorMap[i].to);
pColorTable[iColor].rgbGreen = GetGValue(sysColorMap[i].to);
pColorTable[iColor].rgbRed = GetRValue(sysColorMap[i].to);
break;
}
}
}
nWidth = (INT)lpBitmapInfo->biWidth;
nHeight = (INT)lpBitmapInfo->biHeight;
hdcScreen = GetDC (NULL);
hbm = CreateCompatibleBitmap (hdcScreen, nWidth, nHeight);
if (hbm) {
HDC hdcDst = CreateCompatibleDC (hdcScreen);
HBITMAP hbmOld = SelectObject (hdcDst, hbm);
LPBYTE lpBits = (LPBYTE)(lpBitmap + 1);
lpBits += nColorTableSize * sizeof(RGBQUAD);
StretchDIBits (hdcDst, 0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight,
lpBits, (LPBITMAPINFO)lpBitmapInfo, DIB_RGB_COLORS,
SRCCOPY);
SelectObject (hdcDst, hbmOld);
DeleteDC (hdcDst);
}
ReleaseDC (NULL, hdcScreen);
GlobalFree ((HGLOBAL)lpBitmapInfo);
FreeResource (hglb);
return hbm;
}
/***********************************************************************
* CreateToolbar [COMCTL32.7]
*
* Creates a toolbar control.
*
* PARAMS
* hwnd
* style
* wID
* nBitmaps
* hBMInst
* wBMID
* lpButtons
* iNumButtons
*
* RETURNS
* Success: handle to the tool bar control
* Failure: 0
*
* NOTES
* Do not use this functions anymore. Use CreateToolbarEx instead.
*/
HWND WINAPI
CreateToolbar (HWND hwnd, DWORD style, UINT wID, INT nBitmaps,
HINSTANCE hBMInst, UINT wBMID,
LPCTBBUTTON lpButtons,INT iNumButtons)
{
return CreateToolbarEx (hwnd, style | CCS_NODIVIDER, wID, nBitmaps,
hBMInst, wBMID, lpButtons,
iNumButtons, 0, 0, 0, 0, CCSIZEOF_STRUCT(TBBUTTON, dwData));
}
/***********************************************************************
* DllGetVersion [COMCTL32.@]
*
* Retrieves version information of the 'COMCTL32.DLL'
*
* PARAMS
* pdvi [O] pointer to version information structure.
*
* RETURNS
* Success: S_OK
* Failure: E_INVALIDARG
*
* NOTES
* Returns version of a comctl32.dll from IE4.01 SP1.
*/
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
{
if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
WARN("wrong DLLVERSIONINFO size from app\n");
return E_INVALIDARG;
}
pdvi->dwMajorVersion = COMCTL32_VERSION;
pdvi->dwMinorVersion = COMCTL32_VERSION_MINOR;
pdvi->dwBuildNumber = 2919;
pdvi->dwPlatformID = 6304;
TRACE("%u.%u.%u.%u\n",
pdvi->dwMajorVersion, pdvi->dwMinorVersion,
pdvi->dwBuildNumber, pdvi->dwPlatformID);
return S_OK;
}
/***********************************************************************
* DllInstall (COMCTL32.@)
*
* Installs the ComCtl32 DLL.
*
* RETURNS
* Success: S_OK
* Failure: A HRESULT error
*/
HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
{
FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
debugstr_w(cmdline));
return S_OK;
}
/***********************************************************************
* _TrackMouseEvent [COMCTL32.@]
*
* Requests notification of mouse events
*
* During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
* to the hwnd specified in the ptme structure. After the event message
* is posted to the hwnd, the entry in the queue is removed.
*
* If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
* ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
* immediately and the TME_LEAVE flag being ignored.
*
* PARAMS
* ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
*
* RETURNS
* Success: non-zero
* Failure: zero
*
* IMPLEMENTATION moved to USER32.TrackMouseEvent
*
*/
BOOL WINAPI
_TrackMouseEvent (TRACKMOUSEEVENT *ptme)
{
return TrackMouseEvent (ptme);
}
/*************************************************************************
* GetMUILanguage [COMCTL32.@]
*
* Returns the user interface language in use by the current process.
*
* RETURNS
* Language ID in use by the current process.
*/
LANGID WINAPI GetMUILanguage (VOID)
{
return COMCTL32_uiLang;
}
/*************************************************************************
* InitMUILanguage [COMCTL32.@]
*
* Sets the user interface language to be used by the current process.
*
* RETURNS
* Nothing.
*/
VOID WINAPI InitMUILanguage (LANGID uiLang)
{
COMCTL32_uiLang = uiLang;
}
/***********************************************************************
* SetWindowSubclass [COMCTL32.410]
*
* Starts a window subclass
*
* PARAMS
* hWnd [in] handle to window subclass.
* pfnSubclass [in] Pointer to new window procedure.
* uIDSubclass [in] Unique identifier of sublass together with pfnSubclass.
* dwRef [in] Reference data to pass to window procedure.
*
* RETURNS
* Success: non-zero
* Failure: zero
*
* BUGS
* If an application manually subclasses a window after subclassing it with
* this API and then with this API again, then none of the previous
* subclasses get called or the origional window procedure.
*/
BOOL WINAPI SetWindowSubclass (HWND hWnd, SUBCLASSPROC pfnSubclass,
UINT_PTR uIDSubclass, DWORD_PTR dwRef)
{
LPSUBCLASS_INFO stack;
LPSUBCLASSPROCS proc;
TRACE ("(%p, %p, %x, %lx)\n", hWnd, pfnSubclass, uIDSubclass, dwRef);
/* Since the window procedure that we set here has two additional arguments,
* we can't simply set it as the new window procedure of the window. So we
* set our own window procedure and then calculate the other two arguments
* from there. */
/* See if we have been called for this window */
stack = (LPSUBCLASS_INFO)GetPropW (hWnd, COMCTL32_wSubclass);
if (!stack) {
/* allocate stack */
stack = Alloc (sizeof(SUBCLASS_INFO));
if (!stack) {
ERR ("Failed to allocate our Subclassing stack\n");
return FALSE;
}
SetPropW (hWnd, COMCTL32_wSubclass, (HANDLE)stack);
/* set window procedure to our own and save the current one */
if (IsWindowUnicode (hWnd))
stack->origproc = (WNDPROC)SetWindowLongPtrW (hWnd, GWLP_WNDPROC,
(DWORD_PTR)COMCTL32_SubclassProc);
else
stack->origproc = (WNDPROC)SetWindowLongPtrA (hWnd, GWLP_WNDPROC,
(DWORD_PTR)COMCTL32_SubclassProc);
}
else {
/* Check to see if we have called this function with the same uIDSubClass
* and pfnSubclass */
proc = stack->SubclassProcs;
while (proc) {
if ((proc->id == uIDSubclass) &&
(proc->subproc == pfnSubclass)) {
proc->ref = dwRef;
return TRUE;
}
proc = proc->next;
}
}
proc = Alloc(sizeof(SUBCLASSPROCS));
if (!proc) {
ERR ("Failed to allocate subclass entry in stack\n");
if (IsWindowUnicode (hWnd))
SetWindowLongPtrW (hWnd, GWLP_WNDPROC, (DWORD_PTR)stack->origproc);
else
SetWindowLongPtrA (hWnd, GWLP_WNDPROC, (DWORD_PTR)stack->origproc);
Free (stack);
RemovePropW( hWnd, COMCTL32_wSubclass );
return FALSE;
}
proc->subproc = pfnSubclass;
proc->ref = dwRef;
proc->id = uIDSubclass;
proc->next = stack->SubclassProcs;
stack->SubclassProcs = proc;
return TRUE;
}
/***********************************************************************
* GetWindowSubclass [COMCTL32.411]
*
* Gets the Reference data from a subclass.
*
* PARAMS
* hWnd [in] Handle to window which were subclassing
* pfnSubclass [in] Pointer to the subclass procedure
* uID [in] Unique indentifier of the subclassing procedure
* pdwRef [out] Pointer to the reference data
*
* RETURNS
* Success: Non-zero
* Failure: 0
*/
BOOL WINAPI GetWindowSubclass (HWND hWnd, SUBCLASSPROC pfnSubclass,
UINT_PTR uID, DWORD_PTR *pdwRef)
{
LPSUBCLASS_INFO stack;
LPSUBCLASSPROCS proc;
TRACE ("(%p, %p, %x, %p)\n", hWnd, pfnSubclass, uID, pdwRef);
/* See if we have been called for this window */
stack = (LPSUBCLASS_INFO)GetPropW (hWnd, COMCTL32_wSubclass);
if (!stack)
return FALSE;
proc = stack->SubclassProcs;
while (proc) {
if ((proc->id == uID) &&
(proc->subproc == pfnSubclass)) {
*pdwRef = proc->ref;
return TRUE;
}
proc = proc->next;
}
return FALSE;
}
/***********************************************************************
* RemoveWindowSubclass [COMCTL32.412]
*
* Removes a window subclass.
*
* PARAMS
* hWnd [in] Handle to the window were subclassing
* pfnSubclass [in] Pointer to the subclass procedure
* uID [in] Unique identifier of this subclass
*
* RETURNS
* Success: non-zero
* Failure: zero
*/
BOOL WINAPI RemoveWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uID)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -