?
Solved

callbackhints

Posted on 1998-08-19
9
Medium Priority
?
239 Views
Last Modified: 2013-12-03
Okey i am an beginner.............
Why do only my rectangle show up when i also want to see my metafile??
Do my callback function miss someting or .............
The funny part if there is one is that i can see my metafile when running the application in Microsoft Developer Studio but not outside it and i dont know why??


Here is some code

/*
 * Globals (file global)
 */
static HANDLE hModKarta ;





//
// Function ModkartaWndProc
//
LRESULT CALLBACK ModkartaWndProc( HWND hWnd, UINT uMess, WPARAM wParam,
                                  LPARAM lParam ) {

   /*
    * Lokala variabler.
    */
   static HCURSOR   hArrowCursor;
   static HCURSOR   hWaitCursor;
   static HCURSOR   hCursor;
   PAINTSTRUCT      ps;
   HDC              hDC;
   INT              ix;
   HPEN             RED_PEN;

   /*
    * Behandla meddelanden.
    */
   switch( uMess ) {

      case WM_CREATE:

         /*
          * Initieringar.
          */
         hArrowCursor = LoadCursor( hMainInstance, IDC_ARROW );
         hWaitCursor  = LoadCursor( hMainInstance, IDC_WAIT );
         hCursor      = hArrowCursor;

         break;

      case WM_PAINT:

         /*
          * Börja uppdatering av klientarean.
          */
         hDC=BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );

         /*
          * Rita kartan.
          */
         SetMapMode( hDC, MM_ANISOTROPIC );
         SetViewportExtEx( hDC, 272, 272, NULL );
         PlayMetaFile( hDC, hModKarta );

         /*
          * Beräkna positionen för kartmarkören.
          */
         ModData[nScreen].maprect.left = ModData[nScreen].cursor.x -
                                         ( KARTRUTA_250X * ModData[nScreen].skala ) / 2;

         ModData[nScreen].maprect.top = ModData[nScreen].cursor.y -
                                        ( KARTRUTA_250Y * ModData[nScreen].skala ) / 2;

         ModData[nScreen].maprect.right = ModData[nScreen].maprect.left+
                                          ( KARTRUTA_250X * ModData[nScreen].skala );

         ModData[nScreen].maprect.bottom = ModData[nScreen].maprect.top+
                                           ( KARTRUTA_250Y * ModData[nScreen].skala );

         /*
          * Rita kartmarkör.
          */
         SetMapMode( hDC, MM_TEXT );

         SelectObject( hDC, GetStockObject( NULL_BRUSH ) );
   
         RED_PEN = CreatePen( PS_SOLID, 0, RGB(255,0,0));
         SelectObject( hDC, RED_PEN );

         Rectangle( hDC, ModData[nScreen].maprect.left, ModData[nScreen].maprect.top,
                         ModData[nScreen].maprect.right, ModData[nScreen].maprect.bottom );

         /*
          * Avsluta uppdatering av klientarean.
          */
         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );

         /*
          * Äterstall standardmarkör.
          */
         SetCursor( hArrowCursor );

         break;

      case WM_MOUSEMOVE:

         SetCursor( hCursor );

         break;

      case WM_LBUTTONDOWN:

         /*
          * Sätt väntelage och timglasmarkör.
          */
         SetCursor( hWaitCursor );

         ModData[nScreen].cursor.x = LOWORD( lParam );
         ModData[nScreen].cursor.y = HIWORD( lParam );

         ModData[nScreen].automod = FALSE;
         ModData[nScreen].mod = KARTAFRYS;

         /*
          * Sätt värde till rflmem.
          */
//         lpIOS->MapInfo.MapMode[nScreen] = ModData[nScreen].mod;

         /*
          * Beräkna kartrektangel.
          */
         CalcMapCenter();

         /*
          * Markera rad "KARTFRYS" i listrutan.
          */
         EnableWindow( Children[ID_MODLISTA], TRUE );
         SendMessage( Children[ID_MODLISTA], LB_SELECTSTRING, -1,
                      (LPARAM) (LPCTSTR) ( lpModLista[ModData[nScreen].mod] ) );

         /*
          * Sätt AUTO/MANUELL-knappens läge till MANUELL.
          */
         SendMessage( Children[BT_MANAUTO], WM_SETSTATE, ACTIVATE,
                      MAKELONG(TRUE, BN_R_DOWN) );

         /*
          * Om Skärm 2 så inaktivera TILS_GRID/PAR_GRID valen.
          */
         if ( nScreen == MONITOR2 ) {

            ix = SendMessage( Children[ID_MODLISTA], LB_FINDSTRING, -1,
                              (LPARAM) (LPCTSTR) ( lpModLista[TILS_GRID] ) );

            if (ix != -1 ) {

               SendMessage( Children[ID_MODLISTA], LB_DELETESTRING, (WPARAM) ix, 0 );
               SendMessage( Children[ID_MODLISTA], LB_DELETESTRING, (WPARAM) ix, 0 );

            }

         }

         /*
          * Markera att snabbval inte gäller.
          */
//       if ( lpIOS->SimType != ST_SUL ){

            if ( nScreen == MONITOR2 ) {
               
               ShowWindow( Children[ID_EDIT1], SW_HIDE );

            }
            else {

               ShowWindow( Children[ID_EDIT2], SW_HIDE );
            }

//       }

         /*
          * Begär omritning av fönstret.
          */
         InvalidateRect( hWnd, NULL, FALSE );

         /*
          * Posta meddelande till KARTA.
          */
//       if ( ModData[nScreen].mod == KARTAFRYS ) {

//          lpIOS->MapInfo.MapCenterX[nScreen] = ModData[nScreen].mapcenter.x;
//          lpIOS->MapInfo.MapCenterY[nScreen] = ModData[nScreen].mapcenter.y;

//       }

         if ( !DlgChanged ) {
           
            /*
             * Byt till gul markör.
             */
//            SetChangedCursor();
            DlgChanged = TRUE;

         }

         break;

      default:

         return( DefWindowProc( hWnd, uMess, wParam, lParam ) );

         break;
   }

return( (LONG)NULL );

}





//
// Function CreateModKartaWnd
//
HWND CreateModKartaWnd( HANDLE hInstance, HWND hParentWnd, int ID ) {

   /*
    * Lokala variabler.
    */
   WNDCLASSEX   WC;
   HWND         hWnd;

   /*
    * Läs in metafil.
    */
   hModKarta = GetMetaFile( "..\\..\\..\\data\\modmap.wmf" );


   /*
    * Modstyrning-dialogrutans klass
    */
   WC.cbSize        = sizeof(WNDCLASSEX);
   WC.style         = 0;
   WC.lpfnWndProc   = ModkartaWndProc;
   WC.cbClsExtra    = 0;
   WC.cbWndExtra    = 0;
   WC.hInstance     = hInstance;
   WC.hIcon         = NULL;
   WC.hCursor       = NULL;
   WC.hbrBackground = NULL;
   WC.lpszMenuName  = "";
   WC.lpszClassName = "MODKARTA";
   WC.hIconSm       = NULL;                

   /*
    * Registrera fönsterklass.
    */
   if ( RegisterClassEx( &WC ) ) {

      /*
       * Skapa fönster.
       */
      hWnd = CreateWindowEx(
         0,                     /* Utbyggd fönsterfunktion */
         "MODKARTA",            /* Fönster klass */
         "",                    /* Fönster titel */
         WS_CHILD | WS_VISIBLE, /* Fönstertyp */
         615,                   /* X-position */
         5,                     /* Y-position */
         272,                   /* Storlek X */
         272,                   /* Storlek Y */
         hParentWnd,            /* Förälder-fönster */
         NULL,                  /* Ingen meny */
         hInstance,             /* Instans som skapar detta fönster*/
         NULL                   /* Parametrar */
      );
     
      if ( hWnd == NULL )
         return( NULL );
               
   }
   else
      return( NULL );

return( hWnd );

}  /* CreateModKartaWnd() */

0
Comment
Question by:ThomasLindberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1413673
how is hModKarta initialized?
0
 

Author Comment

by:ThomasLindberg
ID: 1413674
Edited text of question
0
 

Author Comment

by:ThomasLindberg
ID: 1413675
Edited text of question
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:ThomasLindberg
ID: 1413676
Edited text of question
0
 

Author Comment

by:ThomasLindberg
ID: 1413677
I have mailed you the metfile i am using just in case there is a mismatch that i am not awere of.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1413678
>> The funny part if there is one is that i can see my metafile when
>> running the application in Microsoft Developer Studio but
>> not outside it and i dont know why??
That is important.  what is different between the two circumstances?

Are you running from the same path?  If not you might not find the metafile (you never check to see it is successfully opened).
When you run it outside of developer studio, are you running a debug version or a release version?  What happens when you run the other one from outside?  what happens when you run the other one from inside?


0
 

Author Comment

by:ThomasLindberg
ID: 1413679
                    Hello nietod!
I am running an debug version and it workes pefect
when i move it to the right path.

Thank you.

0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1413680
Then the real problem is the fact that you try to open a file (metafile) and don't check that you actually opened it.  That is a bad idea.  Since the file is not actually part of the program (like a stored resource) the user can delete it or move it.  You really should check that you get the file open.

Another suggestion, If there is going to multiple instances of windows that use the above window procedure, each time one of the windows is created you will load a new copy of the cursors (loosing track of the old copy which will hang around in memory).  Insteady you should do that sort of initialization in your main() or from a procedure called one time from main(), or you can do it when the statics are declared, like

static HCURSOR  hArrowCursor = LoadCursor( hMainInstance, IDC_ARROW );

This insures that they are initialized only once.
0
 

Author Comment

by:ThomasLindberg
ID: 1413681
I think my question is completly answered..

Thomas
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question