mase
September 7th, 2007, 04:51 PM
I'm new to win32 API, so this is my first try to do some dialog box not using MFC. For example, I have dialogBox labeling "ADD" button, after I click on the ADD, that label will switch the text label to equal sign with color highlight on the button for the user to press on it.
If I'm going to implement it, what function should I use to change the text label and color on the ADD button?
thanks for advance
kirants
September 8th, 2007, 02:04 PM
1. You can use SetWindowText or SetDlgItemText to change the text of the button
2. To change color, you need to set BS_OWNERDRAW style for the button and handle WM_DRAWITEM in the parent window and do something like a FillRect using the DC passed in in the DRAWITEMSTRUCT
mase
September 9th, 2007, 12:00 AM
thank for replying back my post. I will try your suggestion.
mase
September 10th, 2007, 03:17 PM
Please disregard my first post so you won't get confused according to what I try to do with my code below, so here is my little code:
#include <windows.h>
#include "resource.h"
int launch_app = 0;
int button_pressed2 = 0;
int button_pressed3 = 0;
int button_pressed4 = 0;
const COLORREF buttonColor = RGB(20,135,23);
HBRUSH g_hbrBackground = NULL;
BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand);//, WORD wNotify, HWND hControl);
/////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)AboutDlgProc, 0);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
EndDialog(hWnd, 0);
return TRUE;
case WM_COMMAND:
return MainDialog_OnCommand(hWnd, LOWORD(wParam));
}
return false;
}
//////////////////////////////////////////////////////////////////////////////
BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand)//, WORD wNotify, HWND hControl)
{
switch(wCommand)
{
case IDC_BUTTON1:
if(launch_app== 0)
{
//testing testing
MessageBox(0, TEXT("application running"), TEXT("open application"), MB_OK);
launch_app = 1;
SetDlgItemText(hWnd, IDC_BUTTON1, TEXT("close application"));
} else {
//testing testing
MessageBox(0, TEXT("application is closing"), TEXT("close application"), MB_OK);
launch_app= 0;
EndDialog(hWnd, 0);//closing out the main dialog box
}
break;
case IDC_BUTTON2:
if(launch_app == 1)
{
//testing testing
MessageBox(0, TEXT("button 2 pressed"), TEXT("Button 2"), MB_OK);
button_pressed2 = 1;
}
break;
case IDC_BUTTON3:
if(launch_app == 1)
{
//testing testing
MessageBox(0, TEXT("button 3 pressed"), TEXT("Button 3"), MB_OK);
}
break;
case IDC_BUTTON4:
if(launch_app == 1)
{
//testing testing
MessageBox(0, TEXT("button 4 pressed"), TEXT("Button 4"), MB_OK);
}
break;
}
return TRUE;
}
}
Basically, all I want to accomplish is to change the color of the three buttons(button2,button3,button4) whenever the user clicks on the button to launch application, so as soon as the user clicks on the button to launch App, all the three buttons will switch to different color. I tried to follow kirants's suggestion on changing the color, but I was not able to follow it, so I post my code above for more feedback and suggestions.
kirants
September 10th, 2007, 08:20 PM
Set BS_OWNERDRAW style for the 3 buttons
In AboutDlgProc, handle WM_DRAWITEM and in there, draw the button
[hint]use FillSolidRect() to draw a solid coor rectangle using the dc passed in DRAWITEMSTRUCT. This will draw the colored background. Followed by this, you draw the text using say DrawText(). Use GetWindowText to get the button text.
mase
September 12th, 2007, 11:50 AM
thank Kirants for responding. Let see if I can follow your steps.