Jump to content

Help With Sysmetrics Programme

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
bodhi2016

bodhi2016

    Newbie

  • Members
  • PipPip
  • 29 posts
I am using the book by charles petzold .Since i am a c++ programmer i changed the c code of sysmetrics1 programme to c++with the help pf my online friend.Everything is working perfectly except the numbers
Instead of
SM_CXSCREEN Screen breath in pixel 640
SM_CYSCREEN Screen height in pixel 480
the output is something like this
SM_CXSCREEN Screen height in pixel |||
SM_CYSCREEN Screen height in pixel ||
.
.
.
and so on.
and sometime other kinds of symbols
here's the modified code
(underlined portion is the portion i modified)
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static int  cxChar, cxCaps, cyChar ;

     HDC         hdc ;

     int         i ;

     PAINTSTRUCT ps ;

     TCHAR       szBuffer [10] ;

     TEXTMETRIC  tm ;

     int         iLength;


     switch (message)

     {

     case WM_CREATE:

          hdc = GetDC (hwnd) ;


          GetTextMetrics (hdc, &tm) ;

          cxChar = tm.tmAveCharWidth ;

          cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;

          cyChar = tm.tmHeight + tm.tmExternalLeading ;


          ReleaseDC (hwnd, hdc) ;

          return 0 ;


     case WM_PAINT :

          hdc = BeginPaint (hwnd, &ps) ;


          for (i = 0 ; i < NUMLINES ; i++)

          {

               TextOut (hdc, 0, cyChar * i,                      

                        sysmetrics[i].szLabel,

                        lstrlen (sysmetrics[i].szLabel)) ;


               TextOut (hdc, 22 * cxCaps, cyChar * i,      

                        sysmetrics[i].szDesc,

                        lstrlen (sysmetrics[i].szDesc)) ;


               SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;

              [COLOR="Red"][U] std::stringstream stream;

               stream<<GetSystemMetrics (sysmetrics[i].iIndex);  

               std::string string=stream.str();

               iLength=string.length();                [/U][/COLOR]

TextOut (hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer,iLength);

                        //wsprintf (szBuffer, TEXT ("%5d"),

                                  //GetSystemMetrics (sysmetrics[i].iIndex))) ;


               SetTextAlign (hdc, TA_LEFT | TA_TOP) ;

          }

          EndPaint (hwnd, &ps) ;

          return 0 ;

     case WM_DESTROY :

          PostQuitMessage (0) ;

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}
can you tell where i am going wrong.
I have attached a screeshot you can take a look.
And another thing is that i am planning to learn asm language can anybody suggest me a good book .
Thank You:irritated:

Attached Files



#2
bodhi2016

bodhi2016

    Newbie

  • Members
  • PipPip
  • 29 posts
Oh yeah i forgot to tell that the new setup of codecall is really good .Its quite impressive