Exemple #1
0
bool
CRootNode::SetupNode()
{

    // Load the bitmap we'll be using as the root image
    HBITMAP hRootImage;
    hRootImage = LoadBitmapW(g_hThisInstance,
                             MAKEINTRESOURCEW(IDB_ROOT_IMAGE));
    if (hRootImage == NULL) return FALSE;

    // Add this bitmap to the device image list. This is a bit hacky, but it's safe
    m_ClassImage = ImageList_Add(m_ImageListData->ImageList,
                                 hRootImage,
                                 NULL);
    DeleteObject(hRootImage);


    // Get the root instance 
    CONFIGRET cr;
    cr = CM_Locate_DevNodeW(&m_DevInst,
                            NULL,
                            CM_LOCATE_DEVNODE_NORMAL);
    if (cr != CR_SUCCESS)
    {
        return false;
    }

    // The root name is the computer name 
    DWORD Size = DISPLAY_NAME_LEN;
    GetComputerNameW(m_DisplayName, &Size);

    return true;
}
Exemple #2
0
void Font_DrawText(HDC hDC, LPWSTR lpwszText, int x, int y)
{
    HDC        hFontDC;
    HBITMAP    hFontBitmap;
    HBITMAP    hOldBitmap;
    int        i;

    hFontDC = CreateCompatibleDC(hDC);
    hFontBitmap = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_FONT));
    hOldBitmap = SelectObject(hFontDC, hFontBitmap);

    for (i = 0; lpwszText[i]; i++) {
        if ((lpwszText[i] >= '0') && (lpwszText[i] <= '9')) {
            BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpwszText[i] - '0') * 8, 0, SRCCOPY);
        }
        else if (lpwszText[i] == 'K')
        {
            BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
        }
        else if (lpwszText[i] == '%')
        {
            BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
        }
    }
    SelectObject(hFontDC, hOldBitmap);
    DeleteObject(hFontBitmap);
    DeleteDC(hFontDC);
}
Exemple #3
0
static void InitBoard( BOARD *p_board )
{
    HMENU hMenu;

    p_board->hMinesBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_MINES));
    p_board->hFacesBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_FACES));
    p_board->hLedsBMP = LoadBitmapW( p_board->hInst, MAKEINTRESOURCEW(IDI_LEDS));

    LoadBoard( p_board );

    hMenu = GetMenu( p_board->hWnd );
    CheckMenuItem( hMenu, IDM_BEGINNER + (unsigned) p_board->difficulty,
            MF_CHECKED );
    if( p_board->IsMarkQ )
        CheckMenuItem( hMenu, IDM_MARKQ, MF_CHECKED );
    else
        CheckMenuItem( hMenu, IDM_MARKQ, MF_UNCHECKED );
    CheckLevel( p_board );
}
static void PrepareResultsList(HWND hwnd){
	LVCOLUMNW	lvc;
	HBITMAP		hBmp;
	HMODULE		hIcons;

	hIcons = LoadLibraryExW(g_NotePaths.IconsPath, NULL, LOAD_LIBRARY_AS_DATAFILE);
	if(hIcons){
		//prepare and set list view image lists
		hBmp = LoadBitmapW(hIcons, MAKEINTRESOURCEW(IDB_CTRL_SMALL));
		m_hImlSearch = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 1);
		ImageList_AddMasked(m_hImlSearch, hBmp, CLR_MASK);
		DeleteBitmap(hBmp);
		DeleteObject((void *)CLR_MASK);
		//prepare image list for check image
		hBmp = LoadBitmapW(hIcons, MAKEINTRESOURCEW(IDB_CHECKS));
		m_hImlDefCheck = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0);
		ImageList_AddMasked(m_hImlDefCheck, hBmp, CLR_MASK);
		DeleteBitmap(hBmp);
		DeleteObject((void *)CLR_MASK);
		FreeLibrary(hIcons);
	}
	ListView_SetImageList(m_hListResults, m_hImlSearch, LVSIL_SMALL);
	SendMessageW(m_hListResults, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
	ZeroMemory(&lvc, sizeof(lvc));
	lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
	for(int i = 0; i < NELEMS(m_cols); i++){
		if(i > 0){
			lvc.cx = 240;
		}
		else{
			lvc.cx = 180;
		}
		lvc.iSubItem = i;
		lvc.pszText = m_cols[i];
		SendMessageW(m_hListResults, LVM_INSERTCOLUMNW, i, (LPARAM)&lvc);
	}

	//add checks
	CTreeView_Subclass(GetDlgItem(hwnd, IDC_TVW_SEARCH_DATES));
	TreeView_SetImageList(GetDlgItem(hwnd, IDC_TVW_SEARCH_DATES), m_hImlDefCheck, TVSIL_NORMAL);
	PrepareChecksList(GetDlgItem(hwnd, IDC_TVW_SEARCH_DATES));
}
Exemple #5
0
NTSTATUS
WINAPI
User32CallOBMFromKernel(PVOID Arguments, ULONG ArgumentLength)
{
  BITMAP bmp;
  PSETOBM_CALLBACK_ARGUMENTS Common = Arguments;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_CLOSE].cx = bmp.bmWidth;
  Common->oembmi[OBI_CLOSE].cy = bmp.bmHeight;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_MNARROW)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_MNARROW].cx = bmp.bmWidth;
  Common->oembmi[OBI_MNARROW].cy = bmp.bmHeight;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_DNARROW)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_DNARROW].cx = bmp.bmWidth;
  Common->oembmi[OBI_DNARROW].cy = bmp.bmHeight;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_DNARROWI)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_DNARROWI].cx = bmp.bmWidth;
  Common->oembmi[OBI_DNARROWI].cy = bmp.bmHeight;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_UPARROW)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_UPARROW].cx = bmp.bmWidth;
  Common->oembmi[OBI_UPARROW].cy = bmp.bmHeight;

  GetObjectW(LoadBitmapW(0, MAKEINTRESOURCEW(OBM_UPARROWI)), sizeof(bmp), &bmp);
  Common->oembmi[OBI_UPARROWI].cx = bmp.bmWidth;
  Common->oembmi[OBI_UPARROWI].cy = bmp.bmHeight;

  return ZwCallbackReturn(Arguments, ArgumentLength, STATUS_SUCCESS);
}
Exemple #6
0
BOOL CMainWindow::OnCreate(__in HINSTANCE hInstance)
{
	// window caption
	SetWindowTextW(m_hDialog, pStrings->Get(IDS_XPI).c_str());

	// XPIGUI
	m_pXPIGUI = new XPIGUI;

	ZeroMemory(m_pXPIGUI, sizeof(XPIGUI));

	// XPIGUI - instance
	m_pXPIGUI->hInstance = hInstance;

	// XPIGUI - application icon
	m_pXPIGUI->hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI));
	if (m_pXPIGUI->hIcon != NULL)
		SendMessageW(m_hDialog, WM_SETICON, ICON_BIG, (LPARAM)m_pXPIGUI->hIcon);
#ifdef _DEBUG
	else
		pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load XPI icon, continuing anyway. [LE=0x%08X]", GetLastError());
#endif

	// XPIGUI - small application icon
	m_pXPIGUI->hIconSmall = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI_SMALL));
	if (m_pXPIGUI->hIconSmall != NULL)
		SendMessageW(m_hDialog, WM_SETICON, ICON_SMALL, (LPARAM)m_pXPIGUI->hIconSmall);
#ifdef _DEBUG
	else
		pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load small XPI icon, continuing anyway. [LE=0x%08X]", GetLastError());
#endif

	// XPIGUI - load Consolas from resource
	m_pXPIGUI->hMemFont = AddFontFromResource(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDR_CONSOLAS));
	if (m_pXPIGUI->hMemFont == NULL)
	{
	}

	// XPIGUI - Consolas font handle
	m_pXPIGUI->hFont = CreateFontW(14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas");
	if (m_pXPIGUI->hFont == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create log font, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// XPIGUI - direction image list
	do
	{
		m_pXPIGUI->hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		ImageList_SetBkColor(m_pXPIGUI->hImageList, CLR_NONE);
		if (m_pXPIGUI->hImageList != NULL)
		{
			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_DIRECTIONS));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create packet direction icons image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - injection icons
	m_pXPIGUI->hInjectOut = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_OUT), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hInjectOut == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load inject OUT icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	m_pXPIGUI->hInjectIn = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_IN), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hInjectIn == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load inject IN icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// XPIGUI - pause/resume icons
	m_pXPIGUI->hPauseIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_PAUSE), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hPauseIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load pause icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	Static_SetIcon(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), m_pXPIGUI->hPauseIcon);
	m_pXPIGUI->hResumeIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_RESUME), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hResumeIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load resume icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	RECT rcClient;
	GetClientRect(m_hDialog, &rcClient);
	SetWindowPos(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), NULL, rcClient.right - rcClient.left - UI_PAUSE_WIDTH - UI_PAUSE_PADDING, UI_PAUSE_PADDING, UI_PAUSE_WIDTH, UI_PAUSE_HEIGHT, 0);

	// XPIGUI - clear packets icon
	m_pXPIGUI->hClearIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_CLEAR), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hClearIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load clear icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	Static_SetIcon(GetDlgItem(m_hDialog, IDC_CLEAR), m_pXPIGUI->hClearIcon);
	SetWindowPos(GetDlgItem(m_hDialog, IDC_CLEAR), NULL, rcClient.right - rcClient.left - UI_CLEAR_WIDTH - (UI_CLEAR_PADDING * 2) - UI_PAUSE_WIDTH, UI_CLEAR_PADDING, UI_CLEAR_WIDTH, UI_CLEAR_HEIGHT, 0);

	// XPIGUI - settings image list
	do
	{
		m_pXPIGUI->hSettingsImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		ImageList_SetBkColor(m_pXPIGUI->hSettingsImageList, CLR_NONE);
		if (m_pXPIGUI->hSettingsImageList != NULL)
		{
			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_PACKET_STATES));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hSettingsImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create settings image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - color icons
	for (INT i = 0; i < _countof(m_pXPIGUI->hColorIcon); i++)
	{
		HICON hTempIcon = LoadIcon(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(g_XPIColors[i].wIcon));
		m_pXPIGUI->hColorIcon[i] = MenuBitmapFromIcon(m_hDialog, hTempIcon, 16, 16);
		if (m_pXPIGUI->hColorIcon[i] == NULL)
		{
#ifdef _DEBUG
			pLog->Write(LOG_WF_ERROR, L"Couldn't load color icon #%d, aborting. [LE=0x%08X]", i, GetLastError());
#endif
			NotifyErrorUI();
			return FALSE;
		}
		DestroyIcon(hTempIcon);
	}

	// XPIGUI - formatted image list
	do
	{
		m_pXPIGUI->hFormattedImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		if (m_pXPIGUI->hFormattedImageList != NULL)
		{
			ImageList_SetBkColor(m_pXPIGUI->hFormattedImageList, CLR_NONE);

			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_FORMATTED_LIST));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hFormattedImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create formatted image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - stop icon
	m_pXPIGUI->hStop = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_STOP), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hStop == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load stop icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// shell notify icon
	ZeroMemory(&m_NotifyIconData, sizeof(m_NotifyIconData));
	m_NotifyIconData.cbSize = sizeof(m_NotifyIconData);
	m_NotifyIconData.hWnd = m_hDialog;
	m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	m_NotifyIconData.hIcon = m_pXPIGUI->hIconSmall;
	m_NotifyIconData.uCallbackMessage = WM_SHELLNOTIFY;
	if (FAILED(StringCchCopyW(m_NotifyIconData.szTip, _countof(m_NotifyIconData.szTip), pStrings->Get(IDS_XPI).c_str())))
		m_NotifyIconData.uFlags &= ~NIF_TIP;
	Shell_NotifyIconW(NIM_ADD, &m_NotifyIconData);

	// tooltips window (for icons)
	m_hIconTips = CreateWindowEx(0, TOOLTIPS_CLASS, L"", TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hDialog, 0, m_pXPIGUI->hInstance, NULL);
	SetWindowPos(m_hIconTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

	TOOLINFO ti;
	ti.cbSize = sizeof(ti);
	ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
	ti.hwnd = m_hDialog;

	std::wstring wstrTemp;

	wstrTemp = pStrings->Get(IDS_CLEAR_ALL_PACKETS);
	ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_CLEAR);
	ti.lpszText = (LPWSTR)wstrTemp.c_str();
	SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti);

	wstrTemp = pStrings->Get(IDS_PAUSE_LOGGING);
	ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_PAUSELOGGING);
	ti.lpszText = (LPWSTR)wstrTemp.c_str();
	SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti);

	// tabs creation
	TAB_INFO  Tabs[] =
	{
		{ pStrings->Get(IDS_TAB_PLAIN), MAKEINTRESOURCEW(IDD_PLAINVIEW), CPlainView::DialogProc },
		{ pStrings->Get(IDS_TAB_FORMATTED), MAKEINTRESOURCEW(IDD_FORMATTEDVIEW), CFormattedView::DialogProc },
		{ pStrings->Get(IDS_TAB_SETTINGS), MAKEINTRESOURCEW(IDD_SETTINGS), CMainSettings::DialogProc }
	};

	INT iCount = 0;

	foreach(const TAB_INFO& i, Tabs)
	{
		HWND hWnd = CreateDialogParamW(m_pXPIGUI->hInstance, i.lpwszTemplate, m_hDialog, i.DlgProc, (LPARAM)m_pXPIGUI);
		if (hWnd != NULL)
		{
			TCITEMW tci;
			tci.mask = TCIF_TEXT | TCIF_PARAM;
			tci.pszText = (LPWSTR)i.wstrCaption.c_str();
			tci.lParam = (LPARAM)m_pXPIGUI;

			if (TabCtrl_InsertItem(GetDlgItem(m_hDialog, IDC_TAB), iCount++, &tci) != -1)
			{
				ShowWindow(hWnd, m_vhTabs.empty() ? SW_SHOW : SW_HIDE);
				m_vhTabs.push_back(hWnd);
				continue;
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create tab ID %s, aborting.", i.wstrCaption);
#endif
		NotifyErrorUI();
		return FALSE;
	}
Exemple #7
0
/***********************************************************************
 *           ButtonWndProc_common
 */
LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
                                  WPARAM wParam, LPARAM lParam, BOOL unicode )
{
    RECT rect;
    POINT pt;
    LONG style = GetWindowLongPtrW( hWnd, GWL_STYLE );
    UINT btn_type = get_button_type( style );
    LONG state;
    HANDLE oldHbitmap;
#ifdef __REACTOS__
    PWND pWnd;

    pWnd = ValidateHwnd(hWnd);
    if (pWnd)
    {
       if (!pWnd->fnid)
       {
          NtUserSetWindowFNID(hWnd, FNID_BUTTON);
       }
       else
       {
          if (pWnd->fnid != FNID_BUTTON)
          {
             ERR("Wrong window class for Button! fnId 0x%x\n",pWnd->fnid);
             return 0;
          }
       }
    }    
#endif    

    pt.x = (short)LOWORD(lParam);
    pt.y = (short)HIWORD(lParam);

    switch (uMsg)
    {
    case WM_GETDLGCODE:
        switch(btn_type)
        {
        case BS_USERBUTTON:
        case BS_PUSHBUTTON:      return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
        case BS_DEFPUSHBUTTON:   return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
        case BS_RADIOBUTTON:
        case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
        case BS_GROUPBOX:        return DLGC_STATIC;
        default:                 return DLGC_BUTTON;
        }

    case WM_ENABLE:
        paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        break;

    case WM_CREATE:
        if (!hbitmapCheckBoxes)
        {
            BITMAP bmp;
            hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES));
            GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp );
            checkBoxWidth  = bmp.bmWidth / 4;
            checkBoxHeight = bmp.bmHeight / 3;
        }
        if (btn_type >= MAX_BTN_TYPE)
            return -1; /* abort */

        /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
        if (btn_type == BS_USERBUTTON )
        {
#ifdef __REACTOS__
            style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
            SetWindowLongPtrW( hWnd, GWL_STYLE, style );
#else
            style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
            WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
#endif
        }
        set_button_state( hWnd, BST_UNCHECKED );
        button_update_uistate( hWnd, unicode );
        return 0;

#ifdef __REACTOS__
    case WM_NCDESTROY:
        NtUserSetWindowFNID(hWnd, FNID_DESTROY);
    case WM_DESTROY:
        break;
#endif

    case WM_ERASEBKGND:
        if (btn_type == BS_OWNERDRAW)
        {
            HDC hdc = (HDC)wParam;
            RECT rc;
            HBRUSH hBrush;
            HWND parent = GetParent(hWnd);
            if (!parent) parent = hWnd;
            hBrush = GetControlColor( parent, hWnd, hdc, WM_CTLCOLORBTN);
            GetClientRect(hWnd, &rc);
            FillRect(hdc, &rc, hBrush);
        }
        return 1;

    case WM_PRINTCLIENT:
    case WM_PAINT:
        if (btnPaintFunc[btn_type])
        {
            PAINTSTRUCT ps;
            HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
            int nOldMode = SetBkMode( hdc, OPAQUE );
            (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
            SetBkMode(hdc, nOldMode); /*  reset painting mode */
            if( !wParam ) EndPaint( hWnd, &ps );
        }
        break;

    case WM_KEYDOWN:
	if (wParam == VK_SPACE)
	{
	    SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
            set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
            SetCapture( hWnd );
	}
	break;

    case WM_LBUTTONDBLCLK:
        if(style & BS_NOTIFY ||
           btn_type == BS_RADIOBUTTON ||
           btn_type == BS_USERBUTTON ||
           btn_type == BS_OWNERDRAW)
        {
            BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
            break;
        }
        /* fall through */
    case WM_LBUTTONDOWN:
        SetCapture( hWnd );
        SetFocus( hWnd );
        set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
        SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
        break;

    case WM_KEYUP:
	if (wParam != VK_SPACE)
	    break;
	/* fall through */
    case WM_LBUTTONUP:
        state = get_button_state( hWnd );
        if (!(state & BUTTON_BTNPRESSED)) break;
        state &= BUTTON_NSTATES;
        set_button_state( hWnd, state );
        if (!(state & BST_PUSHED))
        {
            ReleaseCapture();
            break;
        }
        SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        ReleaseCapture();
        GetClientRect( hWnd, &rect );
	if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
        {
            state = get_button_state( hWnd );
            switch(btn_type)
            {
            case BS_AUTOCHECKBOX:
                SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 );
                break;
            case BS_AUTORADIOBUTTON:
                SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
                break;
            case BS_AUTO3STATE:
                SendMessageW( hWnd, BM_SETCHECK,
                                (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 );
                break;
            }
            BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
        }
        break;

    case WM_CAPTURECHANGED:
        TRACE("WM_CAPTURECHANGED %p\n", hWnd);
        state = get_button_state( hWnd );
        if (state & BUTTON_BTNPRESSED)
        {
            state &= BUTTON_NSTATES;
            set_button_state( hWnd, state );
            if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        }
        break;

    case WM_MOUSEMOVE:
        if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
        {
            GetClientRect( hWnd, &rect );
            SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
        }
        break;

    case WM_SETTEXT:
    {
        /* Clear an old text here as Windows does */
//
// wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
// Patch: http://source.winehq.org/patches/data/70889
// By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
//
        if (style & WS_VISIBLE)
        {
            HDC hdc = GetDC(hWnd);
            HBRUSH hbrush;
            RECT client, rc;
            HWND parent = GetParent(hWnd);
            UINT ctlMessage=(btn_type == BS_PUSHBUTTON ||
                      btn_type == BS_DEFPUSHBUTTON ||
                      btn_type == BS_PUSHLIKE ||
                      btn_type == BS_USERBUTTON ||
                      btn_type == BS_OWNERDRAW) ?
                      WM_CTLCOLORBTN : WM_CTLCOLORSTATIC;

            if (!parent) parent = hWnd;

            hbrush = GetControlColor( parent, hWnd, hdc, ctlMessage);

            GetClientRect(hWnd, &client);
            rc = client;
            BUTTON_CalcLabelRect(hWnd, hdc, &rc);
            /* Clip by client rect bounds */
            if (rc.right > client.right) rc.right = client.right;
            if (rc.bottom > client.bottom) rc.bottom = client.bottom;
            FillRect(hdc, &rc, hbrush);
            ReleaseDC(hWnd, hdc);
        }
////
        if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
        else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
        if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
            InvalidateRect( hWnd, NULL, TRUE );
        else
            paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        return 1; /* success. FIXME: check text length */
    }

    case WM_SETFONT:
        set_button_font( hWnd, (HFONT)wParam );
        if (lParam) InvalidateRect(hWnd, NULL, TRUE);
        break;

    case WM_GETFONT:
        return (LRESULT)get_button_font( hWnd );

    case WM_SETFOCUS:
        TRACE("WM_SETFOCUS %p\n",hWnd);
        set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS );
        paint_button( hWnd, btn_type, ODA_FOCUS );
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
        break;

    case WM_KILLFOCUS:
        TRACE("WM_KILLFOCUS %p\n",hWnd);
        state = get_button_state( hWnd );
        set_button_state( hWnd, state & ~BST_FOCUS );
	paint_button( hWnd, btn_type, ODA_FOCUS );

        if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
            ReleaseCapture();
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);

        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case WM_SYSCOLORCHANGE:
        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case BM_SETSTYLE:
        if ((wParam & BS_TYPEMASK) >= MAX_BTN_TYPE) break;
        btn_type = wParam & BS_TYPEMASK;
        style = (style & ~BS_TYPEMASK) | btn_type;
        SetWindowLongPtrW( hWnd, GWL_STYLE, style );
        //WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );

        /* Only redraw if lParam flag is set.*/
        if (lParam)
            InvalidateRect( hWnd, NULL, TRUE );

        break;

    case BM_CLICK:
        //// ReactOS
        state = get_button_state( hWnd );
        if (state & BUTTON_BMCLICK)
           break;
        set_button_state( hWnd, state | BUTTON_BMCLICK ); // Tracked in STATE_GWL_OFFSET.
        ////
	SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
	SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
        ////
        state = get_button_state( hWnd );
        if (!(state & BUTTON_BMCLICK)) break;
        state &= ~BUTTON_BMCLICK;
        set_button_state( hWnd, state );
        ////
	break;

    case BM_SETIMAGE:
        /* Check that image format matches button style */
        switch (style & (BS_BITMAP|BS_ICON))
        {
        case BS_BITMAP:
            if (wParam != IMAGE_BITMAP) return 0;
            break;
        case BS_ICON:
            if (wParam != IMAGE_ICON) return 0;
            break;
        default:
            return 0;
        }
        oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam );
	InvalidateRect( hWnd, NULL, FALSE );
	return (LRESULT)oldHbitmap;

    case BM_GETIMAGE:
        return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );

    case BM_GETCHECK:
        return get_button_state( hWnd ) & 3;

    case BM_SETCHECK:
        if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
        state = get_button_state( hWnd );
        if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
        {
#ifdef __REACTOS__
            if (wParam) style |= WS_TABSTOP;
            else style &= ~WS_TABSTOP;
            SetWindowLongPtrW( hWnd, GWL_STYLE, style );
#else
            if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 );
            else WIN_SetStyle( hWnd, 0, WS_TABSTOP );
#endif
        }
        if ((state & 3) != wParam)
        {
            set_button_state( hWnd, (state & ~3) | wParam );
            paint_button( hWnd, btn_type, ODA_SELECT );
        }
        if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
            BUTTON_CheckAutoRadioButton( hWnd );
        break;

    case BM_GETSTATE:
        return get_button_state( hWnd );

    case BM_SETSTATE:
        state = get_button_state( hWnd );
        if (wParam)
            set_button_state( hWnd, state | BST_PUSHED );
        else
            set_button_state( hWnd, state & ~BST_PUSHED );

        paint_button( hWnd, btn_type, ODA_SELECT );
        break;

    case WM_UPDATEUISTATE:
        if (unicode)
            DefWindowProcW(hWnd, uMsg, wParam, lParam);
        else
            DefWindowProcA(hWnd, uMsg, wParam, lParam);

        if (button_update_uistate(hWnd, unicode))
            paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        break;

    case WM_NCHITTEST:
        if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
        /* fall through */
    default:
        return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
                         DefWindowProcA(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}
Exemple #8
0
/***********************************************************************
 *           ButtonWndProc_common
 */
LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
{
    RECT rect;
    POINT pt;
    LONG style = GetWindowLongW( hWnd, GWL_STYLE );
    UINT btn_type = get_button_type( style );
    LONG state;
    HANDLE oldHbitmap;

    if (!IsWindow( hWnd )) return 0;

    pt.x = (short)LOWORD(lParam);
    pt.y = (short)HIWORD(lParam);

    switch (uMsg)
    {
    case WM_GETDLGCODE:
        switch(btn_type)
        {
        case BS_USERBUTTON:
        case BS_PUSHBUTTON:      return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
        case BS_DEFPUSHBUTTON:   return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
        case BS_RADIOBUTTON:
        case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
        case BS_GROUPBOX:        return DLGC_STATIC;
        default:                 return DLGC_BUTTON;
        }

    case WM_ENABLE:
        paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        break;

    case WM_CREATE:
        if (!hbitmapCheckBoxes)
        {
            BITMAP bmp;
            hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES));
            GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp );
            checkBoxWidth  = bmp.bmWidth / 4;
            checkBoxHeight = bmp.bmHeight / 3;
        }
        if (btn_type >= MAX_BTN_TYPE)
            return -1; /* abort */

        /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
        if (btn_type == BS_USERBUTTON )
        {
            style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
            WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
        }
        set_button_state( hWnd, BST_UNCHECKED );
        return 0;

    case WM_ERASEBKGND:
        if (btn_type == BS_OWNERDRAW)
        {
            HDC hdc = (HDC)wParam;
            RECT rc;
            HBRUSH hBrush;
            HWND parent = GetParent(hWnd);
            if (!parent) parent = hWnd;
            hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
            if (!hBrush) /* did the app forget to call defwindowproc ? */
                hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
                                                (WPARAM)hdc, (LPARAM)hWnd);
            GetClientRect(hWnd, &rc);
            FillRect(hdc, &rc, hBrush);
        }
        return 1;

    case WM_PRINTCLIENT:
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
        if (btnPaintFunc[btn_type])
        {
            int nOldMode = SetBkMode( hdc, OPAQUE );
            (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
            SetBkMode(hdc, nOldMode); /*  reset painting mode */
        }
        if ( !wParam ) EndPaint( hWnd, &ps );
        break;
    }

    case WM_KEYDOWN:
	if (wParam == VK_SPACE)
	{
	    SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
            set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
            SetCapture( hWnd );
	}
	break;

    case WM_LBUTTONDBLCLK:
        if(style & BS_NOTIFY ||
           btn_type == BS_RADIOBUTTON ||
           btn_type == BS_USERBUTTON ||
           btn_type == BS_OWNERDRAW)
        {
            BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
            break;
        }
        /* fall through */
    case WM_LBUTTONDOWN:
        SetCapture( hWnd );
        SetFocus( hWnd );
        set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
        SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
        break;

    case WM_KEYUP:
	if (wParam != VK_SPACE)
	    break;
	/* fall through */
    case WM_LBUTTONUP:
        state = get_button_state( hWnd );
        if (!(state & BUTTON_BTNPRESSED)) break;
        state &= BUTTON_NSTATES;
        set_button_state( hWnd, state );
        if (!(state & BST_PUSHED))
        {
            ReleaseCapture();
            break;
        }
        SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        GetClientRect( hWnd, &rect );
	if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
        {
            state = get_button_state( hWnd );
            switch(btn_type)
            {
            case BS_AUTOCHECKBOX:
                SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 );
                break;
            case BS_AUTORADIOBUTTON:
                SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
                break;
            case BS_AUTO3STATE:
                SendMessageW( hWnd, BM_SETCHECK,
                                (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 );
                break;
            }
            ReleaseCapture();
            BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
        }
        else
        {
            ReleaseCapture();
        }
        break;

    case WM_CAPTURECHANGED:
        TRACE("WM_CAPTURECHANGED %p\n", hWnd);
        state = get_button_state( hWnd );
        if (state & BUTTON_BTNPRESSED)
        {
            state &= BUTTON_NSTATES;
            set_button_state( hWnd, state );
            if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        }
        break;

    case WM_MOUSEMOVE:
        if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
        {
            GetClientRect( hWnd, &rect );
            SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
        }
        break;

    case WM_SETTEXT:
    {
        /* Clear an old text here as Windows does */
        HDC hdc = GetDC(hWnd);
        HBRUSH hbrush;
        RECT client, rc;
        HWND parent = GetParent(hWnd);

        if (!parent) parent = hWnd;
        hbrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
				      (WPARAM)hdc, (LPARAM)hWnd);
        if (!hbrush) /* did the app forget to call DefWindowProc ? */
            hbrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
					    (WPARAM)hdc, (LPARAM)hWnd);

        GetClientRect(hWnd, &client);
        rc = client;
        BUTTON_CalcLabelRect(hWnd, hdc, &rc);
        /* Clip by client rect bounds */
        if (rc.right > client.right) rc.right = client.right;
        if (rc.bottom > client.bottom) rc.bottom = client.bottom;
        FillRect(hdc, &rc, hbrush);
        ReleaseDC(hWnd, hdc);

        if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
        else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
        if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
            InvalidateRect( hWnd, NULL, TRUE );
        else
            paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        return 1; /* success. FIXME: check text length */
    }

    case WM_SETFONT:
        set_button_font( hWnd, (HFONT)wParam );
        if (lParam) InvalidateRect(hWnd, NULL, TRUE);
        break;

    case WM_GETFONT:
        return (LRESULT)get_button_font( hWnd );

    case WM_SETFOCUS:
        TRACE("WM_SETFOCUS %p\n",hWnd);
        set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS );
        paint_button( hWnd, btn_type, ODA_FOCUS );
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
        break;

    case WM_KILLFOCUS:
        TRACE("WM_KILLFOCUS %p\n",hWnd);
        state = get_button_state( hWnd );
        set_button_state( hWnd, state & ~BST_FOCUS );
	paint_button( hWnd, btn_type, ODA_FOCUS );

        if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
            ReleaseCapture();
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);

        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case WM_SYSCOLORCHANGE:
        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case BM_SETSTYLE:
        btn_type = wParam & BS_TYPEMASK;
        style = (style & ~BS_TYPEMASK) | btn_type;
        WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );

        /* Only redraw if lParam flag is set.*/
        if (lParam)
            InvalidateRect( hWnd, NULL, TRUE );

        break;

    case BM_CLICK:
	SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
	SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
	break;

    case BM_SETIMAGE:
        /* Check that image format matches button style */
        switch (style & (BS_BITMAP|BS_ICON))
        {
        case BS_BITMAP:
            if (wParam != IMAGE_BITMAP) return 0;
            break;
        case BS_ICON:
            if (wParam != IMAGE_ICON) return 0;
            break;
        default:
            return 0;
        }
        oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam );
	InvalidateRect( hWnd, NULL, FALSE );
	return (LRESULT)oldHbitmap;

    case BM_GETIMAGE:
        return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );

    case BM_GETCHECK:
        return get_button_state( hWnd ) & 3;

    case BM_SETCHECK:
        if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
        state = get_button_state( hWnd );
        if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
        {
            if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 );
            else WIN_SetStyle( hWnd, 0, WS_TABSTOP );
        }
        if ((state & 3) != wParam)
        {
            set_button_state( hWnd, (state & ~3) | wParam );
            paint_button( hWnd, btn_type, ODA_SELECT );
        }
        if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
            BUTTON_CheckAutoRadioButton( hWnd );
        break;

    case BM_GETSTATE:
        return get_button_state( hWnd );

    case BM_SETSTATE:
        state = get_button_state( hWnd );
        if (wParam)
            set_button_state( hWnd, state | BST_PUSHED );
        else
            set_button_state( hWnd, state & ~BST_PUSHED );

        paint_button( hWnd, btn_type, ODA_SELECT );
        break;

    case WM_NCHITTEST:
        if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
        /* fall through */
    default:
        return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
                         DefWindowProcA(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}