c++ - Background color problem
- Gary (134/134) Mar 10 2003 I'm having a problem with the background color of STATIC, GROUPBOX,
- Jan Knepper (6/140) Mar 10 2003 I think you have to add
I'm having a problem with the background color of STATIC, GROUPBOX, CHECKBOX, and RADIOBUTTON controls using the DMC v8.32. Possibly other controls as well, but these are the only ones I've tried. When I compile the program with the Borland C/C++ 5.5 commandline compiler, all controls show the same background as the main window, as set in the WNDCLASSEX structure. Using the LCCWin32 C compiler, I have the same results. But with the DMC compiler, these controls always have a white background, no matter what I do. I also had the same problen with the OpenWatcom 1.0 compiler, but that problem was solved by adding a "system win95" directive to the linker command line. Is there a similar option for DMC? I'm using "dmc -mn win.cpp gdi32.lib" to compile the program and a win.def file containing "EXETYPE NT" and "SUBSYSTEM WINDOWS". I must be missing something. Also, I can't keep the console window from showing. The test program follows: #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { HWND hwnd; MSG Msg; HICON hIcon; HCURSOR hCursor; TCHAR chClassName[]=TEXT("SIMPLEWND"); WNDCLASSEX wcx; g_hInst=hInstance; hIcon=(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED); hCursor=(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED); wcx.cbSize = sizeof(WNDCLASSEX); wcx.style = CS_HREDRAW|CS_VREDRAW; wcx.lpfnWndProc = (WNDPROC)WndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hInstance; wcx.hIcon = hIcon; wcx.hCursor = hCursor; wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcx.lpszMenuName = NULL; wcx.lpszClassName = chClassName; wcx.hIconSm = NULL; if (!RegisterClassEx(&wcx)) { MessageBox( NULL, TEXT("Failed to register wnd class"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } hwnd=CreateWindowEx(0, chClassName, TEXT("Static Controls"), WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2, NULL, NULL, hInstance, NULL); if (!hwnd) { MessageBox( NULL, TEXT("Failed to create wnd"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam) { static HWND hCntrl; switch (Message) { case WM_CREATE: CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_WHITERECT, 10, 10, 160, 30, hwnd, NULL, g_hInst, NULL); CreateWindowEx(0, TEXT("STATIC"), TEXT("TEXT STATIC CONTROL"), WS_CHILD|WS_VISIBLE|SS_SIMPLE, 10, 50, 160, 30, hwnd, NULL, g_hInst, NULL); hCntrl=CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_ICON, 10, 80, 40, 40, hwnd, NULL, g_hInst, NULL); SendMessage(hCntrl,STM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0,0,LR_SHARED)); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd,Message,wParam,lParam); } } Any ideas? Gary.
Mar 10 2003
I think you have to add EXETYPE NT SUBSYSTEM WINDOWS,4.0 to the .def file. Jan Gary wrote:I'm having a problem with the background color of STATIC, GROUPBOX, CHECKBOX, and RADIOBUTTON controls using the DMC v8.32. Possibly other controls as well, but these are the only ones I've tried. When I compile the program with the Borland C/C++ 5.5 commandline compiler, all controls show the same background as the main window, as set in the WNDCLASSEX structure. Using the LCCWin32 C compiler, I have the same results. But with the DMC compiler, these controls always have a white background, no matter what I do. I also had the same problen with the OpenWatcom 1.0 compiler, but that problem was solved by adding a "system win95" directive to the linker command line. Is there a similar option for DMC? I'm using "dmc -mn win.cpp gdi32.lib" to compile the program and a win.def file containing "EXETYPE NT" and "SUBSYSTEM WINDOWS". I must be missing something. Also, I can't keep the console window from showing. The test program follows: #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { HWND hwnd; MSG Msg; HICON hIcon; HCURSOR hCursor; TCHAR chClassName[]=TEXT("SIMPLEWND"); WNDCLASSEX wcx; g_hInst=hInstance; hIcon=(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED); hCursor=(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED); wcx.cbSize = sizeof(WNDCLASSEX); wcx.style = CS_HREDRAW|CS_VREDRAW; wcx.lpfnWndProc = (WNDPROC)WndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hInstance; wcx.hIcon = hIcon; wcx.hCursor = hCursor; wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcx.lpszMenuName = NULL; wcx.lpszClassName = chClassName; wcx.hIconSm = NULL; if (!RegisterClassEx(&wcx)) { MessageBox( NULL, TEXT("Failed to register wnd class"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } hwnd=CreateWindowEx(0, chClassName, TEXT("Static Controls"), WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2, NULL, NULL, hInstance, NULL); if (!hwnd) { MessageBox( NULL, TEXT("Failed to create wnd"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam) { static HWND hCntrl; switch (Message) { case WM_CREATE: CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_WHITERECT, 10, 10, 160, 30, hwnd, NULL, g_hInst, NULL); CreateWindowEx(0, TEXT("STATIC"), TEXT("TEXT STATIC CONTROL"), WS_CHILD|WS_VISIBLE|SS_SIMPLE, 10, 50, 160, 30, hwnd, NULL, g_hInst, NULL); hCntrl=CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_ICON, 10, 80, 40, 40, hwnd, NULL, g_hInst, NULL); SendMessage(hCntrl,STM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0,0,LR_SHARED)); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd,Message,wParam,lParam); } } Any ideas? Gary.
Mar 10 2003
I've tried that, but it doesn't work either. Gary "Jan Knepper" <jan smartsoft.us> wrote in message news:3E6D6FAF.A9D2D2DB smartsoft.us...I think you have to add EXETYPE NT SUBSYSTEM WINDOWS,4.0 to the .def file. Jan Gary wrote:theI'm having a problem with the background color of STATIC, GROUPBOX, CHECKBOX, and RADIOBUTTON controls using the DMC v8.32. Possibly other controls as well, but these are the only ones I've tried. When I compileshowprogram with the Borland C/C++ 5.5 commandline compiler, all controlsstructure.the same background as the main window, as set in the WNDCLASSEXIUsing the LCCWin32 C compiler, I have the same results. But with the DMC compiler, these controls always have a white background, no matter whatthatdo. I also had the same problen with the OpenWatcom 1.0 compiler, butwin.cppproblem was solved by adding a "system win95" directive to the linker command line. Is there a similar option for DMC? I'm using "dmc -mnNT"gdi32.lib" to compile the program and a win.def file containing "EXETYPEtheand "SUBSYSTEM WINDOWS". I must be missing something. Also, I can't keeplParam)console window from showing. The test program follows: #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { HWND hwnd; MSG Msg; HICON hIcon; HCURSOR hCursor; TCHAR chClassName[]=TEXT("SIMPLEWND"); WNDCLASSEX wcx; g_hInst=hInstance; hIcon=(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED); hCursor=(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED); wcx.cbSize = sizeof(WNDCLASSEX); wcx.style = CS_HREDRAW|CS_VREDRAW; wcx.lpfnWndProc = (WNDPROC)WndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hInstance; wcx.hIcon = hIcon; wcx.hCursor = hCursor; wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcx.lpszMenuName = NULL; wcx.lpszClassName = chClassName; wcx.hIconSm = NULL; if (!RegisterClassEx(&wcx)) { MessageBox( NULL, TEXT("Failed to register wnd class"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } hwnd=CreateWindowEx(0, chClassName, TEXT("Static Controls"), WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2, NULL, NULL, hInstance, NULL); if (!hwnd) { MessageBox( NULL, TEXT("Failed to create wnd"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM{ static HWND hCntrl; switch (Message) { case WM_CREATE: CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_WHITERECT, 10, 10, 160, 30, hwnd, NULL, g_hInst, NULL); CreateWindowEx(0, TEXT("STATIC"), TEXT("TEXT STATIC CONTROL"), WS_CHILD|WS_VISIBLE|SS_SIMPLE, 10, 50, 160, 30, hwnd, NULL, g_hInst, NULL); hCntrl=CreateWindowEx(0, TEXT("STATIC"), NULL, WS_CHILD|WS_VISIBLE|SS_ICON, 10, 80, 40, 40, hwnd, NULL, g_hInst, NULL); SendMessage(hCntrl,STM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0,0,LR_SHARED)); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd,Message,wParam,lParam); } } Any ideas? Gary.
Mar 11 2003
It's working now... not sure why, but I rebooted and now it works??? Gary "Jan Knepper" <jan smartsoft.us> wrote in message news:3E6D6FAF.A9D2D2DB smartsoft.us...I think you have to add EXETYPE NT SUBSYSTEM WINDOWS,4.0 to the .def file. Jan
Mar 11 2003