C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-17-2008, 08:38 AM   #1
Registered User
 
Join Date: Sep 2007
Posts: 18
Question WinAPI: Editbox + WM_CTLCOLORSTATIC sets bigger border?

Quote:
Hi

I have a little problem with my program.
I am creating an EDIT-box with this line:
Code:
HWND hA = CreateWindowEx(0, "EDIT", "", WS_CHILD|WS_TABSTOP|WS_VISIBLE|WS_BORDER, 5, 22, 165, 20, hwnd, (HMENU)IDC_US, GetModuleHandle(NULL), NULL);
After the user presses “ok” I send:
Code:
SendMessage(hA, EM_SETREADONLY, (WPARAM) TRUE, 0);
to make the box “readonly”.

Then the box color chance to gray, but I want it to be white.
To do so I use this in my WindowProcedure:

Code:
case WM_CTLCOLORSTATIC: {
         switch(GetDlgCtrlID((HWND) lParam)) {
                  case IDC_US:
                           #define WHITE 0x0FFFFFFF
                           CreateSolidBrush(WHITE);
                           break;
                  default: return DefWindowProc (hwnd, message, wParam, lParam);
         }
}
It works fine, but the problem is that the border around the box goes bigger?
Why? Can I block or chance it?

____Pic: LINK

Sorry for my bad eng =)

EDIT:
I think I have found a way to do it now, de first time I did it wrong ^^
I hope someone can confirm that I am doing it right now:

I set this to be global:
Code:
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(255,255,255));
My case lock like this:
Code:
case WM_CTLCOLORSTATIC: {
     switch(GetDlgCtrlID((HWND) lParam)) {
          case IDC_US: {
               HDC hdcStatic = (HDC)wParam;
               SetTextColor(hdcStatic, RGB(0, 0, 0));
               SetBkMode(hdcStatic, TRANSPARENT);
               return (LONG)g_hbrBackground;
               break;
          }
     default: return DefWindowProc (hwnd, message, wParam, lParam);
     }
}
And on destroy:
Code:
DeleteObject(g_hbrBackground);

Last edited by Dampy; 05-17-2008 at 02:34 PM. Reason: Find a way
Dampy is offline   Reply With Quote
Old 05-17-2008, 09:25 AM   #2
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
Moving to Windows forum.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 05-18-2008, 07:10 AM   #3
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,844
>> someone can confirm that I am doing it right now
Looks correct.

gg
Codeplug is offline   Reply With Quote
Reply

Tags
createsolidbrush, edit box, wm_ctlcolorstatic

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem aligning floating point numbers esbo C Programming 4 01-05-2009 08:09 PM
creating new sets axon C++ Programming 7 12-03-2003 06:37 PM


All times are GMT -6. The time now is 02:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22