-
Didn't mean to leave you hanging. I went out of town for a few days.
What is the deal with that if statement. Why are you typecasting the lparam to a HWND. It appears that your problem is with the if statement. I am assuming based on your code that EDIT_FILE is the resource name for the edit control on the dialog (rigt click the edit box control, and select properties to get the name).
That being the case. GetDlgCtrlID will return the resource id (int) when you pass the hwnd of the object. What your code is telling me is that (HWND)lPAram is the hwnd to the editbox. If you already had the hwnd to the edit box you would not have this problem.
It appears to me, that All you have from the edit box is the resource ID not the hwnd. That is what you are trying to get. That being the case:
1) Remove the if statement. You don't need it.
2) I am making an assumption that hwnd is the handle to the dialog window, and EDIT_FILEs is the resource ID name for the edit box.
That being the case, the code should work. Let me know if it doesn't. Good luck!
-
GDI's are your computers resources. Graphical Device Interface(?) I think.
Open the Resource meter in Win98 and the bottom line is GDI resources.
If your computer runs out of them it will just fail to update the screen. Or crash. Think of it as memory. (as it is) You will not notice them being lost as they are usually small in size (beware if they are in a paint function).
Break it down into parts.
catch the returns from all the macros and ensure they are correct (at least not NULL) and that the code is not being bypassed (not entering if).
If you always want the edit to appear this way do this in your dialog init/create function or in response to a WM_CREATE msg (you may not be generating a WM_CTLCOLOURSTATIC msg).
hDlg is the HWND passed into the callback.
ID_EDIT is the ID you specified when you created the edit in the resource editor.
case WM_CREATE:
hEdit=GetDlgItem(hDlg,ID_EDIT);
hdc=GetDC(hEdit));
SetBkColour(hdc,RGB(255,255,255));
SetTextColour(hdc,RGB(0,0,0));
ReleaseDC(hEdit,hdc);
break;
OR on the fly if the control will change
UINT idControl;
case WM_COMMAND:
idControl=GET_WM_COMMAND_ID(wParam,lParam) ;
switch(idControl);
case ID_EDIT:
hEdit=GetDlgItem(hDlg,ID_EDIT);
hdc=GetDC(hEdit));
SetBkColour(hdc,RGB(255,255,255));
SetTextColour(hdc,RGB(0,0,0));
ReleaseDC(hEdit,hdc);
break;
I would not do both as this might create an infinte loop.
-
I just wanted to test that the last stuff would work.
It won't.
The SetBkColor returns the color ref, the HWND and HDC are OK.
The SetTextColor fails and returns 0. GetLastError() says it was an error sucsess.
I would say you can not change the text color or the background (not by this method anyway).
I re-read you post as to why.
To disable all user input to the edit just use
UINT idControl;
case WM_COMMAND:
idControl=GET_WM_COMMAND_ID(wParam,lParam) ;
switch(idControl);
case ID_EDIT:
break;
If this still causes problems find the ClientRect() of the edit and ignore all mouse messages to this rectangle.
WM_LBUTTONDOWN ect
Use MAKEPOINTS and PtInRect() to find if the mouse was clicked in the edit.
May need ClientToScreen() to ensure that all the points are refrenced to the top left of the screen (not top left dialog).
-
As a programmer once said on this board a while back, don't ask his name cause I don't remember it hehe, "You shouldn't simply just try to find a work around. You should be trying to figure out why it doesn't work and how to make it work." And I agree fully with that. I'm trying to find out how come it wont work with disabled editboxes. Another programmer had given me a way to change the background colour by catching the WM_CTLCOLORSTATIC message and then returning a value (don't remember exact code, but I have it closer to the top of this post). However, that doesn't help me if I want to change the text color.
Now I thank you very much for all your aid thus far, but if you would rather not help me anymore or are out of ideas then thats fine with me. However, I am not going to use the work around and I am still going to look for a way to make it work. I believe a friend at school may know, I'll ask him today. But if you guys get anymore suggestions to try then just post it here and I will be greatful! :)
-
Why don't you just use a static control? As long as give give it a unique ID (not IDC_STATIC) you can write text into it and change the text and background colour properly by capturing the
WM_CTLCOLORSTATIC message (you don't appear to be able to change the text colour of a disabled edit control by capturing this message). If you adjust the properties of a static control you can make it appear just like an edit control.
Another option would be to use SetSysColors() to change the COLOR_GRAYTEXT system colour but this would affect all other disabled text.
-
I tried the WM_COLOURSTATIC msg and still no change in the edit control. Also tried normal editboxes.
I think that the edit is handling its own paint and as you change it windows redraws it to the original. Need OWNERDRAW.
I would take Zen's advice and create a static with the SUNKEN or BORDER styles to make it look like an EDIT. You have more control over the apperarance of these. All the same code should work with the static.
You could use a FRAME, get a DC, create a compatible DC & BMP, create pens and brush, draw on them, and then use InvalidateRect() or UpdateWindow() to send a WM_PAINT msg to show them. In your paint function draw to the PAINTSTRUC DC on screen with BitBlt().
-
The following code:
case WM_CTLCOLORSTATIC:
if( GetDlgCtrlID((HWND)lParam) == EDIT_FILES ) {
return((LRESULT)GetStockObject(WHITE_BRUSH));
}
return(TRUE);
works for me. You have be using this code in the dialog's message proc function and not the program's main one. The main one in my program is only used for little things such as terminating the overall program when needed, etc. However, the above code wont change the text color which is what I need to do now.