Click here to Skip to main content
15,906,569 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to visible the background buttons when I change the back ground color Pin
Owner drawn15-Jan-06 18:27
Owner drawn15-Jan-06 18:27 
GeneralRe: How to visible the background buttons when I change the back ground color Pin
S_a_n15-Jan-06 18:44
S_a_n15-Jan-06 18:44 
GeneralDon't use FillRect() there Pin
Owner drawn15-Jan-06 18:47
Owner drawn15-Jan-06 18:47 
GeneralRe: Don't use FillRect() Pin
S_a_n15-Jan-06 18:51
S_a_n15-Jan-06 18:51 
GeneralRe: Don't use FillRect() Pin
Owner drawn15-Jan-06 18:55
Owner drawn15-Jan-06 18:55 
GeneralRe: Don't use FillRect() Pin
S_a_n15-Jan-06 19:42
S_a_n15-Jan-06 19:42 
GeneralRe: Don't use FillRect() Pin
Owner drawn15-Jan-06 19:50
Owner drawn15-Jan-06 19:50 
GeneralRe: Don't use FillRect() Pin
S_a_n15-Jan-06 20:03
S_a_n15-Jan-06 20:03 
The same way Iam doing..Could you plz check this code,but intially it is with desktop color...But i need intially the background shud be in LTGRAY_BRUSH and one button on it..
When i click the button some transparent layer has to come over the window and the color has to cover the button also..



#include "stdafx.h"
#include "transparent.h"
#include <commctrl.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // The current instance
HWND hwndCB,hWndB; // The command bar handle
bool check_flag=false;
void changecolor(HWND hWnd);

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TRANSPARENT);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// It is important to call this function so that the application
// will get 'well formed' small icons associated with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TRANSPARENT));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;

return RegisterClass(&wc);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name

hInst = hInstance; // Store instance handle in our global variable
// Initialize global strings
LoadString(hInstance, IDC_TRANSPARENT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance, szWindowClass);

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

hWndB = CreateWindow(L"button",L"",WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,200,300,100,30,hWnd,NULL,hInstance,NULL);

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if (hwndCB)
CommandBar_Show(hwndCB, TRUE);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int wmId, wmEvent;
PAINTSTRUCT ps;
TCHAR szHello[MAX_LOADSTRING];
LPDRAWITEMSTRUCT lpDIS;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_FILE_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
hwndCB = CommandBar_Create(hInst, hWnd, 1);
CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
CommandBar_AddAdornments(hwndCB, 0, 0);
break;
case WM_DRAWITEM:
lpDIS = (LPDRAWITEMSTRUCT) lParam;
DrawFrameControl(lpDIS->hDC,&lpDIS->rcItem,DFC_BUTTON,DFCS_BUTTONPUSH);
if(lpDIS->itemAction == ODA_DRAWENTIRE)
{
DrawText(lpDIS->hDC,L"Uma",3,&lpDIS->rcItem,DT_CENTER | DT_VCENTER);
}
if(lpDIS->itemAction & ODA_SELECT)
{

DrawText(lpDIS->hDC,L"Selected",3,&lpDIS->rcItem,DT_CENTER | DT_VCENTER);
check_flag=true;
RECT rt;
GetWindowRect(hWnd,&rt);
InvalidateRect(hWnd,&rt,TRUE);

}
break;
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
//DrawText(hdc, szHello, _tcslen(szHello), &rt,
// DT_SINGLELINE | DT_VCENTER | DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
CommandBar_Destroy(hwndCB);
PostQuitMessage(0);
break;
case WM_ERASEBKGND:
//HDC hdc;
//hdc = BeginPaint(hWnd,&ps);
if(check_flag)
{
changecolor(hWnd);
}

//MessageBox(hWnd,L"Erasing",L"OK",MB_OK);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for the About box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;

switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;

// if the About box is larger than the physical screen
if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
return TRUE;

case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}


void changecolor(HWND hWnd)
{
RECT wndRect;
UINT uiWidth,uiHeight;
HDC hdc=GetDC(hWnd);
GetWindowRect(hWnd,&wndRect);

uiWidth = wndRect.right - wndRect.left;
uiHeight = wndRect.bottom - wndRect.top;
wndRect.top = 0;
wndRect.left = 0;
wndRect.bottom = wndRect.top + uiHeight;
wndRect.right = wndRect.left + uiWidth;

HBRUSH hBrush = CreateSolidBrush(RGB(120,120,120));//RGB(120 , 230 , 120));

FillRect(hdc, &wndRect, hBrush);

DeleteObject(hBrush);
ReleaseDC(hWnd,hdc);
EnableWindow(hWndB,false);
}
GeneralRe: How to visible the background buttons when I change the back ground color Pin
Stephen Hewitt15-Jan-06 18:57
Stephen Hewitt15-Jan-06 18:57 
QuestionThere isn't any error when access private member variable directly in copy constructor... Pin
followait15-Jan-06 17:51
followait15-Jan-06 17:51 
AnswerRe: There isn't any error when access private member variable directly in copy constructor... Pin
Saurabh.Garg15-Jan-06 18:03
Saurabh.Garg15-Jan-06 18:03 
AnswerRe: There isn't any error when access private member variable directly in copy constructor... Pin
Sebastian Schneider15-Jan-06 22:48
Sebastian Schneider15-Jan-06 22:48 
GeneralRe: There isn't any error when access private member variable directly in copy constructor... Pin
Owner drawn16-Jan-06 17:04
Owner drawn16-Jan-06 17:04 
Answermany thanks Pin
followait16-Jan-06 15:11
followait16-Jan-06 15:11 
Questionrelated to Socket Pin
baldha rakesh15-Jan-06 17:21
baldha rakesh15-Jan-06 17:21 
AnswerRe: related to Socket Pin
kevincwong15-Jan-06 18:20
kevincwong15-Jan-06 18:20 
AnswerRe: related to Socket Pin
sunit515-Jan-06 19:28
sunit515-Jan-06 19:28 
AnswerRe: related to Socket Pin
Prakash Nadar15-Jan-06 19:30
Prakash Nadar15-Jan-06 19:30 
AnswerRe: related to Socket Pin
vikas amin16-Jan-06 0:47
vikas amin16-Jan-06 0:47 
Questioncall FindFirstPrinterChangeNotification() Get Error 997? Pin
szcococut15-Jan-06 16:30
szcococut15-Jan-06 16:30 
AnswerRe: call FindFirstPrinterChangeNotification() Get Error 997? Pin
Prakash Nadar15-Jan-06 19:32
Prakash Nadar15-Jan-06 19:32 
GeneralRe: call FindFirstPrinterChangeNotification() Get Error 997? Pin
szcococut15-Jan-06 20:11
szcococut15-Jan-06 20:11 
QuestionInvisible/Visible Button Pin
DanYELL15-Jan-06 13:05
DanYELL15-Jan-06 13:05 
AnswerRe: Invisible/Visible Button Pin
Maximilien15-Jan-06 13:54
Maximilien15-Jan-06 13:54 
QuestionResizing dialog-based app and its controls Pin
Jamaica15-Jan-06 11:15
Jamaica15-Jan-06 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.