Results 1 to 18 of 18

Thread: CreateSolidBrush & GetStockObject

  1. #1

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    CreateSolidBrush & GetStockObject

    I am trying to set the background of an edit control... i know u have to handle the WM_CTLCOLOREDIT which is fine and i can set the back and fore color like this

    Code:
    		case WM_CTLCOLOREDIT:
    			if(IDC_TEXT == GetDlgCtrlID((HWND)lParam))
    			{			
    				SetBkMode((HDC)wParam, TRANSPARENT);
    				SetTextColor((HDC)wParam, RGB(59, 195, 25));
    				return (LRESULT)GetStockObject(BLACK_BRUSH);
    			}
    		break;
    this works fine, but i would like to create create my own brush using CreateSolidBrush and setting the RGB color value.. i'm attempting to call the code like this

    Code:
    		case WM_CTLCOLOREDIT:
    			if(IDC_TEXT == GetDlgCtrlID((HWND)lParam))
    			{
    				hbrush = CreateSolidBrush(RGB(0, 0, 0));
    				
    				SetBkMode((HDC)wParam, TRANSPARENT);
    				SetTextColor((HDC)wParam, RGB(59, 195, 25));
    				return (LRESULT)GetStockObject(hbrush);
    			}
    		break;
    i get an error when i try and compile... the error is

    "error C2664: 'GetStockObject' : cannot convert parameter 1 from 'struct HBRUSH__ *' to 'int'"

    how to i fix this ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hbrush has to be a HBRUSH
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    umm why, u only use that to define hbrush... I've already defined hbrush as

    HBRUSH hbrush;

    its just not in the code, its defined as global..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  4. #4
    jim mcnamara
    Guest
    GetStockObject takes long integers for an argument not structs.

    HBRUSH is a struct. I think that's what Kedaman is saying.

  5. #5

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok, so how do i fix this ??? and i also have another problem... for some reason when i set the back and forecolor and type some text and then attempt to delete it by hitting backspace, it doesn't delete until the i minimize the window and restore it... i tried catching the en_change message and sending an updatewindow but it didn't work.... how do i fix this also ?? the reason i need to create my own brush is because i open the color dialog box for the user to select the back and forecolor of the edit control...
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well at least the type convertion you can do:

    return (LRESULT)GetStockObject(*(int*)(void*)&BLACK_BRUSH);
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    believe or not i had already tried that with no luck... it compiles just fine but doesn't work
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  8. #8

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok i figured out how to create my own brush and use it for the background of my edit control now i have another problem.. the problem is refreshing the edit control... the new color doesn't display until i minimize the edit control and restore it... wierd

    i've tried updatewindow with no luck
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    does the rest of your window update at all? maybe you want to show us the callback proc
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok i fixed the update of the background by calling invalidate rect so now that works... now i need to make sure that the window gets updated properly when text gets added and deleted from tthe edit control
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  11. #11

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok nevermind i got it i just simply handle the en_change event and invalidaterect works perfect thanx for your time tho..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  12. #12

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok new problem!! LOL instead of handling the EN_CHANGE, i now handle the EN_UPDATE... works perfect when deleting text... the problem i now have is with scrolling... how do i detect when a user scrolls ?? and i don't mean EN_VSCROLL or EN_HSCROLL those messages only fire when a scrollbar button is clicked and not the actual scrollbar or when its scolling... any suggestions ?? perhaps not handling EN_UPDATE or possibly some other message.. would WM_PAINT work in this situation ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  13. #13

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    nevermind.... i've figured it out... in case anybody reads this and is wondering what to do here it is.. u don't have to handle any paint messages....

    simply do the code like this

    Code:
    		case WM_CTLCOLOREDIT:
    			if(HWND_TEXT == GetDlgCtrlID((HWND)lParam))
    			{
    				HRBUSH hbrush = CreateSolidBrush(RGB(0,0,0)); //create a solid black brush
    				SetBkColor((HDC)wParam, RGB(0,0,0)); //Set Background to Black
    				SetTextColor((HDC)wParam, RGB(255,255,255));//Set TextColor To White
    				return (DWORD)hbrush; // brush must be returned to update
    			}
    		break;

    just note that if u want to change the background, u must change the hbrush RGB as well as the RGB in the SetBkColor..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  14. #14
    jim mcnamara
    Guest
    This is great - post once, watch you ask/solve several questions.

  15. #15

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    LOL!! yea i was pretty much talking to myself those last few posts!! AHAHAH it helps to talk it out sometimes!! LOL
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe, wonderfull to read these
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  17. #17
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: CreateSolidBrush & GetStockObject

    how to use by vb6

  18. #18
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: CreateSolidBrush & GetStockObject

    Quote Originally Posted by xiaoyao View Post
    how to use by vb6
    This thread is 20 years.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width