Controlling Philips Hue using OpenHAB in Raspberry Pi - philips-hue

I want to control the Philips Hue Lux color lamps with OpenHAB. So I wonder what are the steps I should do and if I am missing something.
In pi#raspberrypi:/opt/openhab/configurations/rules $ sudo vi demo.rules
rule "Select scene"
when
Item scene received command
then
switch(receivedCommand) {
/*alles uit */
case 0 : {
sendCommand(Toggle_7, OFF);
sendCommand(Toggle_3, OFF);
sendCommand(Toggle_1, OFF);
sendCommand(Toggle_10, OFF);
sendCommand(Toggle_11, OFF);
sendCommand(Toggle_5, OFF);
sendCommand(Toggle_9, OFF);
}
/*sfeer */
case 1 : {
sendCommand(LWD_3, 90);
sendCommand(Color_7, "45.584415,86.033516,70.19608");
sendCommand(Color_1, "45.584415,86.033516,70.19608");
sendCommand(Color_10, "45.584415,86.033516,70.19608");
sendCommand(Color_11, "45.584415,86.033516,70.19608");
sendCommand(Color_5, "45.584415,86.033516,70.19608");
sendCommand(LWD_9,10);
}
/*Alles aan */
case 2 : {
sendCommand(Toggle_7, ON);
sendCommand(Toggle_3, ON);
sendCommand(Toggle_1, ON);
sendCommand(Toggle_10, ON);
sendCommand(Toggle_11, ON);
sendCommand(Toggle_5, ON);
sendCommand(LWD_9,100);
}
/*eten */
case 3 : {
sendCommand(Toggle_3, OFF);
sendCommand(Color_7, "42.391304,73.6,100.0");
sendCommand(Color_1, "42.391304,73.6,100.0");
sendCommand(Color_10, "42.391304,73.6,100.0");
sendCommand(Color_11, "60,42,100");
sendCommand(Color_5, "60,42,100");
sendCommand(LWD_9,10);
}
case 4 : {
/*nacht */
sendCommand(LWD_9, 50);
sendCommand(Color_7, "46.25,37.64706,100.0");
sendCommand(Color_10, "46.25,37.64706,100.0");
sendCommand(Toggle_1, OFF);
sendCommand(Toggle_3, OFF);
sendCommand(Toggle_11, OFF);
sendCommand(Toggle_5, OFF);
}
case 5 : {
/* Sunset */
sendCommand(Color_7, "42.391304,73.6,100.0");
sendCommand(Color_1, "42.391304,73.6,100.0");
sendCommand(Color_10, "42.391304,73.6,100.0");
sendCommand(Color_11, "42.391304,73.6,100.0");
sendCommand(Color_5, "42.391304,73.6,100.0");
sendCommand(Toggle_3, OFF);
sendCommand(LWD_9,10);
}
case 6 : {
/* Aqua */
sendCommand(Color_7, "230.82353,100.0,100.0");
sendCommand(Color_1, "230.82353,100.0,100.0");
sendCommand(Color_10, "230.82353,100.0,100.0");
sendCommand(Color_11, "230.82353,100.0,100.0");
sendCommand(Color_5, "230.82353,100.0,100.0");
sendCommand(Toggle_3, OFF);
sendCommand(LWD_9,10);
}
case 7 : {
/* Duo */
sendCommand(Color_7, "272,100.0,100.0");
sendCommand(Color_5, "272,100.0,100.0");
sendCommand(Color_1, "330,100.0,100.0");
sendCommand(Color_10, "330,100.0,100.0");
sendCommand(Color_11, "330,100.0,100.0");
sendCommand(Toggle_3, OFF);
sendCommand(LWD_9,10);
}
case 8 : {
/* Duo ambilight play */
sendCommand(Color_7, "272,100.0,30.0");
sendCommand(Color_5, "272,100.0,30.0");
sendCommand(Color_1, "330,100.0,30.0");
sendCommand(Color_10, "330,100.0,30.0");
sendCommand(Color_11, "330,100.0,30.0");
}
case 9 : {
/* Duo ambilight pauze*/
sendCommand(Color_7, "272,100.0,100.0");
sendCommand(Color_5, "272,100.0,100.0");
sendCommand(Color_1, "330,100.0,100.0");
sendCommand(Color_10, "330,100.0,100.0");
sendCommand(Color_11, "330,100.0,100.0");
}
}
end
in pi#raspberrypi:/opt/openhab/configurations/items $ vi demo.items
I have
:
/* Hue */
Switch Toggle_1 "left bulb" (Switching) {hue="1"}
Switch Toggle_2 "center bulb" (Switching) {hue="2"}
Switch Toggle_3 "right bulb" (Switching) {hue="3"}
Color Color_1 "left bulb" (Colorize) {hue="1"}
Color Color_2 "center bulb" (Colorize) {hue="2"}
Color Color_3 "right bulb" (Colorize) {hue="3"}
Dimmer Dimm_1 "left bulb" (WhiteDimmer) {hue="1;brightness;30"}
Dimmer Dimm_2 "center bulb" (WhiteDimmer) {hue="2;brightness;30"}
Dimmer Dimm_3 "right bulb" (WhiteDimmer) {hue="3;brightness;30"}
Dimmer CT_Dimm_1 "left bulb" (CTDimmer) {hue="1;colorTemperature;30"}
Dimmer CT_Dimm_2 "center bulb" (CTDimmer) {hue="2;colorTemperature;30"}
Dimmer CT_Dimm_3 "right bulb" (CTDimmer) {hue="3;colorTemperature;30"}
in pi#raspberrypi:/opt/openhab/configurations $ vi openhab.cfg:
I have:
############################### Philips Hue Binding ###################################
#
# IP address of Hue Bridge (optional, default is auto-discovery)
hue:ip=192.168.1.117
hue:secret=openHABRuntime
hue:refresh=10000
I ran it using sudo ./start.sh and then paired the Hue hub with OpenHAB. I am not what is missing because still I can't control the Hue with OpenHAB.
My main struggle is connecting the web UI to the code in openHAB. Any pointer is really appreciated! Also I have stitched the code above from various tutorials so it possibly would make no sense at all!

Changing how the UI's look is done with the *.sitemap files.
This files define how and which items are shown in the UI:
https://github.com/openhab/openhab/wiki/Explanation-of-Sitemaps
As for the rest of the example:
- Are you sure about the ip and secret of the Hue bridge?
- How many light bulbs are connected to the bridge? Because in the *.items file hue=1 means the first bulb connected to your bridge.

It is random yes but you also have to pair the bridge. Have you got it do at least one bulb can turn on and off?
Just checking but your switch and scene items are not called switch and scene are they?
The binding is picky and you might have to declare the variable type for each:
var DecimalType hue = new DecimalType(240) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
var PercentType sat = new PercentType(100) // 0-100
var PercentType bright = new PercentType(100) // 0-100
var HSBType light = new HSBType(hue,sat,bright)
sendCommand(Light_GF_Lounge_C, light)
Though to be frank, the binding is a bit of a pain and you would be better off using the API directly and then setting scenes you have set in an app or something.
Or directly
rule "Set lights"
when
Item Switch_Lounge received update ON
then
var String hueApiCall = "curl##-X##PUT##-d##{\"on\": %s, \"hue\":%d , \"sat\": %d, \"bri\": %d, \"transitiontime\": %d}##http://192.168.1.147/api/YOURPAIREDHUEUSERID/groups/%d/action"
executeCommandLine(String::format(hueApiCall, true, 13088, 212, 100, 10, 2 ))
end
Each of the values in the executeCommandLine match the % placeholders in order, in this example on: true, hue: 13088, sat: 212, bri, 100, transition time: 10, group 2
Using that syntax you can set scenes, alerts, all sorts.

Related

how to change my background image by day_of_week

what code for change background image in android studio java by current day name,
for example if today is monday then background image is A image,if tuesday then b image...thx
You can check day's of the week and change image . Please try as follows
private static void getDaysOfTheWeek() {
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
cal.setTime(new Date());
switch(cal.get(Calendar.DAY_OF_WEEK)){
case Calendar.MONDAY:
System.out.println("image 1");
break;
case Calendar.TUESDAY:
System.out.println("image 2");
break;
case Calendar.WEDNESDAY:
System.out.println("image 3");
break;
case Calendar.THURSDAY:
System.out.println("image 4");
break;
case Calendar.FRIDAY:
System.out.println("image 5");
break;
case Calendar.SATURDAY:
System.out.println("image 6");
break;
case Calendar.SUNDAY:
System.out.println("image 5");
break;
}
}
Create a Layout file that while show image for changing background and on it show TextView That will show Text and use below code to generate bitmap image and set it to your ImageView. Hope This will Help you
private Bitmap getCustomImage(#DrawableRes int imageId,String text) {
View customView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.your_layout_file, null);
ImageView imageView = (ImageView) customView.findViewById(R.id.imageView);
TextView textView = (TextView) customView.findViewById(R.id.textView);
textView.setText(text);
imageView.setImageResource(imageId);
customView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
customView.layout(0, 0, customMarkerView.getMeasuredWidth(), customView.getMeasuredHeight());
customView.buildDrawingCache();
Bitmap returnedBitmap = Bitmap.createBitmap(customView.getMeasuredWidth(), customView.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
Drawable drawable = customView.getBackground();
if (drawable != null)
drawable.draw(canvas);
customView.draw(canvas);
return returnedBitmap;
}

Textfield in cocos2d/kobold2d not showing color

I need to create a textfield where a player in my game can enter their name for highscore purposes. I followed this question: UITextField Example in Cocos2d , and successfuly created a textfield with the keyboard. However, the textfield's text is white and the background color is also white so I cannot see the textfield, only the keyboard.
Here is the code:
appdelegate.h
#import "KKAppDelegate.h"
#interface AppDelegate : KKAppDelegate
{
UITextField *nameTextField;
}
-(void)specifyPlayerName;
#end
appdelegate.m
#implementation AppDelegate
-(void) initializationComplete
{
#ifdef KK_ARC_ENABLED
CCLOG(#"ARC is enabled");
#else
CCLOG(#"ARC is either not available or not enabled");
#endif
}
- (void)specifyPlayerName
{
NSLog(#"called");
nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(60, 165, 200, 90)];
[nameTextField setDelegate:self];
[nameTextField setText:#""];
[nameTextField setTextColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
[nameTextField becomeFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
//Terminate editing
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField*)textField {
if (textField==nameTextField) {
[nameTextField endEditing:YES];
// here is where you should do something with the data they entered
GameData* data = [GameData sharedData];
data.playerName = nameTextField.text;
NSLog(#"entered: %#", data.playerName);
}
}
The method is being called from another class/button
[[[UIApplication sharedApplication] delegate]performSelector:#selector(specifyPlayerName)];
I tried to set the color of the textfield, but it is still showing up as all white. Any help would be appreciated.
I found out that the textfield was hidden behind the other view, so
[[[CCDirector sharedDirector] openGLView] addSubview:nameTextField];
instead of
[[[[CCDirector sharedDirector] openGLView] window] addSubview:nameTextField];
The textfield colors are default to be black on white.

How to clone X and Y axis?

I have a barChart with overplot a lineChart, two different series
barChart.getData().addAll(series1);
lineChart.getData().addAll(series2);
My question: is it possible, and how to, clone barChart axis so to get the same settings for lineChart?
What I would like to have is a perfect axis settings overlapping.
Thanks
Edit: at this link
axis clone method
I see there is a clone method Methods inherited from class java.lang.Object
How can I use this method?
Thanks all
Edit2: below is a sample class to show my problem: it plots a line chart and by clicking the Add serie button it adds a scatter chart.
As it plots yellow dots both axis overlap, but just move chart left/right or upper/dow by left mouse click and drag anywhere on the chart and axis goes out of sync.
Same problem for axis expand/compress by left mouse click and drag on X or Y axis
import java.util.Set;
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Side;
import javafx.scene.Group;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Node;
import javafx.scene.chart.*;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
public class RescalingSeries extends Application {
StackPane mainGraphStackPane = null;
Button btnAdd;
BorderPane pane;
XYChart.Series series1 = new XYChart.Series();
SimpleDoubleProperty rectinitX = new SimpleDoubleProperty();
SimpleDoubleProperty rectinitY = new SimpleDoubleProperty();
protected static Axis _duplicateAxis(Axis axis, Axis result) {
result.setAnimated(axis.animatedProperty().get());
result.setAutoRanging(axis.isAutoRanging());
result.setLabel(axis.getLabel());
result.setSide(axis.getSide());
result.setTickLabelFill(axis.getTickLabelFill());
result.setTickLabelFont(axis.getTickLabelFont());
result.setTickLabelGap(axis.getTickLabelGap());
result.setTickLength(axis.getTickLength());
return result;
}
protected static ValueAxis _duplicateValueAxis(ValueAxis axis, ValueAxis result) {
_duplicateAxis(axis, result);
result.setLowerBound(axis.getLowerBound());
result.setUpperBound(axis.getUpperBound());
result.setMinorTickCount(axis.getMinorTickCount());
result.setMinorTickLength(axis.getMinorTickLength());
result.setTickLabelFormatter(axis.getTickLabelFormatter());
return result;
}
/**
* Duplicate a number axis.
* #param axis The source axis.
* #return A {#code NumberAxis}, never {#code null}.
*/
public static NumberAxis duplicateNumberAxis(NumberAxis axis) {
NumberAxis result = new NumberAxis();
_duplicateValueAxis(axis, result);
result.setTickUnit(axis.getTickUnit());
result.setForceZeroInRange(axis.isForceZeroInRange());
return result;
}
/**
* Duplicate a category axis.
* #param axis The source axis.
* #return A {#code CategoryAxis}, never {#code null}.
*/
public static CategoryAxis duplicateCategoryAxis(CategoryAxis axis) {
CategoryAxis result = new CategoryAxis(axis.getCategories());
_duplicateAxis(axis, result);
result.setStartMargin(axis.getStartMargin());
result.setEndMargin(axis.getEndMargin());
result.setGapStartAndEnd(axis.gapStartAndEndProperty().get());
return result;
}
#Override
public void start(Stage stage) {
final NumberAxis xAxisLC = new NumberAxis(1, 12, 1);
final NumberAxis yAxisLC = new NumberAxis(0.53000, 0.53910, 0.0005);
yAxisLC.setSide(Side.RIGHT);
yAxisLC.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxisLC) {
#Override
public String toString(Number object) {
return String.format("%7.5f", object);
}
});
final LineChart<Number, Number> lineChart = new LineChart<>(xAxisLC, yAxisLC);
lineChart.setCreateSymbols(false);
lineChart.setAlternativeRowFillVisible(false);
lineChart.setAnimated(true);
lineChart.setLegendVisible(false);
series1.getData().add(new XYChart.Data(1, 0.53185));
series1.getData().add(new XYChart.Data(2, 0.532235));
series1.getData().add(new XYChart.Data(3, 0.53234));
series1.getData().add(new XYChart.Data(4, 0.538765));
series1.getData().add(new XYChart.Data(5, 0.53442));
series1.getData().add(new XYChart.Data(6, 0.534658));
series1.getData().add(new XYChart.Data(7, 0.53023));
series1.getData().add(new XYChart.Data(8, 0.53001));
series1.getData().add(new XYChart.Data(9, 0.53589));
series1.getData().add(new XYChart.Data(10, 0.53476));
series1.getData().add(new XYChart.Data(11, 0.530123));
series1.getData().add(new XYChart.Data(12, 0.531035));
pane = new BorderPane();
pane.setCenter(lineChart);
mainGraphStackPane = new StackPane();
mainGraphStackPane.getChildren().add(pane);
Scene scene = new Scene(mainGraphStackPane, 800, 600);
lineChart.getData().addAll(series1);
stage.setScene(scene);
scene.setOnMouseClicked(mouseHandler);
scene.setOnMouseDragged(mouseHandler);
scene.setOnMouseEntered(mouseHandler);
scene.setOnMouseExited(mouseHandler);
scene.setOnMouseMoved(mouseHandler);
scene.setOnMousePressed(mouseHandler);
scene.setOnMouseReleased(mouseHandler);
Group root = new Group();
btnAdd = new Button();
btnAdd.setText("Add serie");
root.getChildren().add(btnAdd);
pane.getChildren().add(root);
btnAdd.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
NumberAxis xAxisBC = duplicateNumberAxis(xAxisLC);
NumberAxis yAxisBC = duplicateNumberAxis(yAxisLC);
ScatterChart<Number, Number> scatterChart = new ScatterChart<>(xAxisBC, yAxisBC);
scatterChart.setAlternativeRowFillVisible(false);
scatterChart.setAnimated(true);
scatterChart.setLegendVisible(false);
XYChart.Series series2 = new XYChart.Series();
series2.getData().add(new XYChart.Data(1, 0.53185));
series2.getData().add(new XYChart.Data(2, 0.532235));
series2.getData().add(new XYChart.Data(3, 0.53234));
series2.getData().add(new XYChart.Data(4, 0.538765));
series2.getData().add(new XYChart.Data(5, 0.53442));
series2.getData().add(new XYChart.Data(6, 0.534658));
series2.getData().add(new XYChart.Data(7, 0.53023));
series2.getData().add(new XYChart.Data(8, 0.53001));
series2.getData().add(new XYChart.Data(9, 0.53589));
series2.getData().add(new XYChart.Data(10, 0.53476));
series2.getData().add(new XYChart.Data(11, 0.530123));
series2.getData().add(new XYChart.Data(12, 0.531035));
scatterChart.getData().addAll(series2);
Set<Node> chartNode = scatterChart.lookupAll(".chart-plot-background");
for(final Node chr : chartNode){
chr.setStyle("-fx-background-color: transparent;");
}
chartNode = lineChart.lookupAll(".chart-plot-background");
for(final Node chr : chartNode){
chr.setStyle("-fx-background-color: transparent");
}
mainGraphStackPane.getChildren().add(scatterChart);
xAxisBC.lowerBoundProperty().bind(xAxisLC.lowerBoundProperty());
yAxisBC.lowerBoundProperty().bind(yAxisLC.lowerBoundProperty());
}
});
stage.show();
}
EventHandler<MouseEvent> mouseHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent mouseEvent) {
boolean XScaling=false;
boolean YScaling=false;
if (mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED || mouseEvent.getEventType() == MouseEvent.MOUSE_MOVED ){
LineChart<Number, Number> lineChart = (LineChart<Number, Number>) pane.getCenter();
NumberAxis yAxis = (NumberAxis) lineChart.getYAxis();
NumberAxis xAxis = (NumberAxis) lineChart.getXAxis();
double Tgap = xAxis.getWidth()/(xAxis.getUpperBound() - xAxis.getLowerBound());
double newXlower=xAxis.getLowerBound(), newXupper=xAxis.getUpperBound();
double newYlower=yAxis.getLowerBound(), newYupper=yAxis.getUpperBound();
double xAxisShift = xAxis.localToScene(0, 0).getX();
double yAxisShift = yAxis.localToScene(0, 0).getY();
double yAxisStep=yAxis.getHeight()/(yAxis.getUpperBound()-yAxis.getLowerBound());
double CurrentPrice=yAxis.getUpperBound()-((mouseEvent.getY()-yAxisShift)/yAxisStep);
double Delta=0.3;
if(mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED && mouseEvent.getX()<xAxisShift+yAxis.getHeight() && mouseEvent.getY()<yAxisShift+yAxis.getHeight() && (XScaling==false || YScaling==false)){
//==================================================== X-Axis Moving ==================================
if(rectinitX.get() < mouseEvent.getX()){
newXlower=xAxis.getLowerBound()-Delta;
newXupper=xAxis.getUpperBound()-Delta;
}
else if(rectinitX.get() > mouseEvent.getX()){
newXlower=xAxis.getLowerBound()+Delta;
newXupper=xAxis.getUpperBound()+Delta;
}
xAxis.setLowerBound( newXlower );
xAxis.setUpperBound( newXupper );
//===================================================== Y-Axis Moving ====================================
if(rectinitY.get() < mouseEvent.getY()){
newYlower=yAxis.getLowerBound()+Delta/1000;
newYupper=yAxis.getUpperBound()+Delta/1000;
}
else if(rectinitY.get() > mouseEvent.getY()){
newYlower=yAxis.getLowerBound()-Delta/1000;
newYupper=yAxis.getUpperBound()-Delta/1000;
}
yAxis.setLowerBound(newYlower);
yAxis.setUpperBound(newYupper);
}
//----------------------------- Re-Scale the X-Axis when dragging below it ---------------------------------
else if(mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED && mouseEvent.getY()>yAxisShift+yAxis.getHeight() ){
if(rectinitX.get() < mouseEvent.getX()){
newXlower=xAxis.getLowerBound()+Delta;
newXupper=xAxis.getUpperBound()-Delta;
}
else if(rectinitX.get() > mouseEvent.getX()){
newXlower=xAxis.getLowerBound()-Delta;
newXupper=xAxis.getUpperBound()+Delta;
}
xAxis.setLowerBound( newXlower );
xAxis.setUpperBound( newXupper );
}
//--------------------------------- Re-Scale the Y-Axis when dragging to the left of it --------------------------
else if(mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED && mouseEvent.getX()> (xAxisShift + xAxis.getWidth())){
if(rectinitY.get() < mouseEvent.getY()){
newYlower=yAxis.getLowerBound()-Delta/1000;
newYupper=yAxis.getUpperBound()+Delta/1000;
}
else if(rectinitY.get() > mouseEvent.getY()){
newYlower=yAxis.getLowerBound()+Delta/1000;
newYupper=yAxis.getUpperBound()-Delta/1000;
}
yAxis.setLowerBound(newYlower);
yAxis.setUpperBound(newYupper);
}
rectinitX.set(mouseEvent.getX());
rectinitY.set(mouseEvent.getY());
if(mouseEvent.getEventType() == MouseEvent.MOUSE_MOVED && mouseEvent.getY()>yAxisShift && mouseEvent.getY()<yAxisShift+yAxis.getHeight() && mouseEvent.getX()>xAxisShift && mouseEvent.getX()<xAxisShift+xAxis.getWidth()){
double XX=((mouseEvent.getX() - xAxisShift) / Tgap) + xAxis.getLowerBound();
double YY=CurrentPrice;
series1.setName(String.format("%.2g%n",XX) + ", " + String.format("%.4g%n",YY));
}
}
}
};
public static void main(String[] args) {
launch(args);
}
}
The
Chart, Axis, and Series
objects are not clone-able. For example I needed to include charts in two scenes. The only means to do so was to start with the original data and create every one of those elements twice.

how to change background color of a static text control (when a button is pushed or in a timer) in mfc?

I know it can be done with OnCtlColor(), but it changes colors when the form is being loaded and the static texts are to be drawn, I want to do it after form is loaded, with a timer maybe, I searched for a solution but I didn't find a clear one, this is what I wrote:
void CTabFive::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CWnd* pWnd = this->GetDlgItem(IDC_Chromosome1);
CDC* dc = pWnd->GetDC();
dc->SetBkColor(RGB(200,0,0));
pWnd->Invalidate();
pWnd->UpdateWindow();
Invalidate();
UpdateWindow();
//flag = true;
}
No timer is needed. Here I have a bool m_coloured member of the class initialized to false, and toggled in the button press. The OnCtlColor will draw in red or in the system colour depending on the value of m_coloured. Works nicely.
HBRUSH Cmfcvs2010Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_LABEL)
{
DWORD d = GetSysColor(COLOR_BTNFACE);
COLORREF normal = RGB(GetRValue(d), GetGValue(d), GetBValue(d));
COLORREF red = RGB(255, 0, 0);
pDC->SetBkColor(m_coloured ? red : normal);
}
return hbr;
}
void Cmfcvs2010Dlg::OnBnClickedButton1()
{
m_coloured = !m_coloured;
Invalidate();
}

flash crash when loading a html with webkitgtk

I use webkitgtk to open a html page with some flash files on it. But when I load the page it crashes. My code is given below. What should I do?
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
WebKitWebView *webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview),TRUE);
GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webview));
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webview, "close-web-view", G_CALLBACK(closewebviewCb), main_window);
gtk_container_add(GTK_CONTAINER(main_window), scrolledWindow);
webkit_web_view_load_uri(webview,URI_PATH);
/******************webkitsetting************************************/
WebKitWebSettings *settings1 = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings1), "enable-plugins", FALSE, NULL);
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(webview), settings1);
g_signal_connect (webview, "notify::load-status", G_CALLBACK (loadStatusCb),NULL);
gtk_widget_grab_focus(GTK_WIDGET(webview));
gtk_widget_show_all(main_window);`

Resources