Link to home
Start Free TrialLog in
Avatar of ThomasLindberg
ThomasLindberg

asked on

callbackhints

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() */

Avatar of nietod
nietod

how is hModKarta initialized?
Avatar of ThomasLindberg

ASKER

Edited text of question
Edited text of question
Edited text of question
I have mailed you the metfile i am using just in case there is a mismatch that i am not awere of.
>> 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?


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

Thank you.

ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think my question is completly answered..

Thomas