Solved

callbackhints

Posted on 1998-08-19
9
227 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

19 Experts available now in Live!

Get 1:1 Help Now