Solved

callbackhints

Posted on 1998-08-19
9
233 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

770 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