Jump to content
  • Advertisement
Sign in to follow this  

win32 api

This topic is 4157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was wondering if there was a way to view my varibles in the debugger in real time, as you can see in my code, i have some static counters in the WM_PAINT AND WM_SIZE, when i run debugger without any breakpoints it wont allow me to watch the counter variables, why is this ? is there any way of viewing your codes varibles while pressing f5 without breakpoints??
   HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
                 (c) Charles Petzold, 1998

#include <windows.h>


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
     static TCHAR szAppName[] =  TEXT("HelloWin") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
          MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     hwnd = CreateWindow (szAppName,                  // window class name
                          TEXT ("The Hello Program"), // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          CW_USEDEFAULT,              // initial x position
                          CW_USEDEFAULT,              // initial y position
                          CW_USEDEFAULT,              // initial x size
                          CW_USEDEFAULT,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters
     ShowWindow (hwnd, SW_SHOW) ;
     UpdateWindow (hwnd) ;
     while (GetMessage (&msg, NULL, 0, 0))
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     return msg.wParam ;

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     HDC         hdc ;
     RECT        rect ;
     switch (message)
     case WM_CREATE:
          PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
          return 0 ;
     case WM_PAINT:

		 static int  paintCount = 0;


          hdc = BeginPaint (hwnd, &ps) ;
          GetClientRect (hwnd, &rect) ;
          DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
          EndPaint (hwnd, &ps) ;
          return 0 ;

	 case WM_SIZE:
		static int sizeCount;

		  MessageBox(NULL,TEXT("Sorry, resizing is disabled !"), TEXT("ERROR"), MB_YESNOCANCEL|MB_DEFBUTTON2|MB_ICONSTOP);
		  return 0;
     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     return DefWindowProc (hwnd, message, wParam, lParam) ;

Share this post

Link to post
Share on other sites
This is something called a Watch.
Under VS 2005 while debugging press Ctrl+Alt+Q
to add a quick watch.


Share this post

Link to post
Share on other sites

i tryed ctrl alt q, and it didn't do anything, im made sure that i had pressed f5 previously to that as well, and i made sure that the visual studio window was selected.

i also looked in the debug menu, and i cant see a quick watch, just the standard watch, which when applied is greyed out and doesn't let you add anything

im using visual studio 2005 standard


Share this post

Link to post
Share on other sites
As far as I know you can't make VC continuously update watched variables while the debugee is still running.

What you can do is to have it print the value of a variable every time your program reaches a certain point. Do this by creating a normal breakpoint, right-clicking the red dot, select "When Hit...", click on "Print a message", and make sure "Continue execution" is also on.

In the message put any variables you want to print in curly braces. For example if you wanted to print the value of i you might do "i: {i}" (without the quotes).

Another alternative is to use OutputDebugString to print a message to VC's output window. This requires changing your code though.

And lastly, your question had absolutely nothing to do with "win32 api".

Share this post

Link to post
Share on other sites
i would also either use OutputDebugString or call SetWindowText to view your WM_PAINT and WM_SIZE variable updates.

+tip: preventing resizing by displaying a message box in WM_SIZE is generally frowned upon. typically what one does is respond to WM_GETMINMAXINFO or eat the WM_NCHITTEST message when the flags are HT_BORDER or HT_SIZEBOX.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!