Jump to content
Sign in to follow this  
n4gix

Gdi on gauges

Recommended Posts

Guest whitedragon

Hi all,i need to use GDI functions on a gauge, but i'm not able to get a valid hdc (Handle Device Context). Please someone is able to suggest me some method to get that? I'm using VC++ 6Thanks in advance,WD

Share this post


Link to post
Share on other sites

It would help if you post the relevant parts of your code, so we can see what you've tried?Did you remember to include a MAKE STATIC element creating a DIBSECTION?What is your context for creating an hdc?Here's a working example:void FSAPI PFDCallBack ( PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data ){ if(!init) { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); init = true; } switch (service_id) { case PANEL_SERVICE_PRE_DRAW: { PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list[0]->next_element[0]); if (pelement) { HDC hdc = pelement->hdc; PIXPOINT dim = pelement->image_data.final->dim; if (hdc) { Graphics graphics(hdc);


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest whitedragon

I didn't create a DIBSECTION.Following your examples, now i write this piece of code:char tmp[1024];void FSAPI test ( PGAUGEHDR pgauge, SINT32 service_id,UINT32 extra_data ){ switch (service_id) { case PANEL_SERVICE_PRE_DRAW: PELEMENT_STATIC_IMAGE pelement = NULL; strcpy(tmp, "..."); if(pgauge) { strcpy(tmp, "pgauge"); if(pgauge->elements_list[0]) { strcpy(tmp, "list[0]"); if(pgauge->elements_list[0]->next_element[0]) { strcpy(tmp, "element[0]"); PELEMENT_STATIC_IMAGE pelement = (PELEMENT_STATIC_IMAGE)(pgauge->elements_list[0]->next_element[0]); if(pelement->hdc) { strcpy(tmp, "hdc"); } } } } break; }}FLOAT64 FSAPI temperature_string_cb2( PELEMENT_STRING pelement ) { FLOAT64 val = pelement->source_var[2].var_value.n; sprintf(pelement->string, "%s", tmp); return val; }MAKE_STRING( temperature_string, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY, 0, 28, 9, 120, 60, 10, FUEL_QUANTITY_LEFT, FUEL_QUANTITY_RIGHT, TOTAL_FUEL_QUANTITY_GALLONS, RGB(255,0,0), RGB(0,0,0), RGB(92,92,92), GAUGE_FONT_DEFAULT, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL, temperature_string_cb2)MAKE_STATIC( temperature_background, BMP_TEMPERATURE_SMALL_BACKGROUND, &temperature_icon_list, NULL, IMAGE_USE_ERASE|IMAGE_USE_BRIGHT|IMAGE_CREATE_DIBSECTION, 0, 0,0)PELEMENT_HEADER temperature_icon_list[] ={ &temperature_string.header, NULL};PELEMENT_HEADER temperature_list= &temperature_background.header;The value of tmp string (used for debug purpose) is "element[0]", so it seems that pgauge->elements_list[0]->next_element[0] is setted but pelement->hdc is not. Do you have any suggestion?Also, i've done another test: i've replace the string callback functions with the following:FLOAT64 FSAPI temperature_string_cb2( PELEMENT_STRING pelement ) { FLOAT64 val = pelement->source_var[2].var_value.n; if(pelement->hdc) { sprintf(pelement->string, "OK", 5.3); TextOut(pelement->hdc, 0, 0, "TEST13); } else { sprintf(pelement->string, "NO", 5.3); } return val; }This time the output is "OK", making me think that here i've a hdc, but my TextOut output is overwrite after exit the function. If it's true, what do you think about save that hdc in a global variable and use it in the main callback function? There is something like PANEL_SERVICE_PRE_DRAW but POST at the place of PRE?Thank you for your helping,White Dragon

Share this post


Link to post
Share on other sites

Did you remember to issue a SET_OFF_SCREEN at the end of the drawing cycle? This is needed to redraw the gauge each cycle.if (pelement) { HDC hdc = pelement->hdc; PIXPOINT dim = pelement->image_data.final->dim; if (hdc) { Graphics graphics(hdc); } SET_OFF_SCREEN (pelement); } } break;Also, why use the MAKE_STRING macro? Why not simply write the string with your GDI+ code?SolidBrush whiteBrush(Color(255, 255, 255, 255));FontFamily Arial(L"Arial");Font TempTitles(&Arial, 18*dim.y, FontStyleBold, UnitPixel);PointF pointF(5.0*dim.x, 5.0*dim.y);graphics.DrawString(L"MKR", -1, &TempTitles, pointF, &whiteBrush);


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest whitedragon

>Did you remember to issue a SET_OFF_SCREEN at the end of the>drawing cycle? This is needed to redraw the gauge each>cycle.I've tried just now, but nothing has changed...>Also, why use the MAKE_STRING macro? Why not simply write the>string with your GDI+ code?>>SolidBrush whiteBrush(Color(255, 255, 255, 255));>>FontFamily Arial(L"Arial");>Font TempTitles(&Arial, 18*dim.y, FontStyleBold, UnitPixel);>PointF pointF(5.0*dim.x, 5.0*dim.y);>graphics.DrawString(L"MKR", -1, &TempTitles, pointF,>&whiteBrush);I would make it if i had a valid hdc. My real problem is that i don't have any reference to the drawing area, so i must use the MS macro :( Any soluction?

Share this post


Link to post
Share on other sites

>I would make it if i had a valid hdc. My real problem is that>i don't have any reference to the drawing area, so i must use>the MS macro :( Any soluction?Yes. Before you can proceed, you first need to get the hdc working...Write to me at n4gix@comcast.net and I will send you a working example to get you started off on the right foot... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...