Solved

callbackhints

Posted on 1998-08-19
9
230 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
  • 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
 

Author Comment

by:ThomasLindberg
ID: 1413676
Edited text of question
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now