Thread: The counter

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    The counter

    Hi I am trying to create an application which would count how many icons have I drawn into a window but I still have a problem with TextOut() it does not take my INT value.

    Can you chceck the code?

    Code:
    #include <windows.h>
    #include "resource1.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
        HWND hWnd;
    	int count[10];
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       PSTR szCmdLine, int iCmdShow)
    {
        TCHAR szAppName[] = TEXT("Default window");           // Header
        MSG msg;
        WNDCLASSEX wc;
        
        wc.cbSize = sizeof(wc);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));            // Ico
        wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));          // Ico_sm
        wc.hCursor = (HCURSOR)LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);           // Background
        wc.lpszMenuName = NULL;
        wc.lpszClassName = szAppName;
        
        RegisterClassEx(&wc);
        
        hWnd = CreateWindowEx(0,szAppName,
                            szAppName,
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,                    // Margin from left
                            CW_USEDEFAULT,                    // Margin from top
                            CW_USEDEFAULT,                    // Widht
                            CW_USEDEFAULT,                    // Height
                            NULL,
                            NULL,
                            hInstance,NULL);
        ShowWindow(hWnd, iCmdShow);
        UpdateWindow(hWnd);
        
        while(GetMessage(&msg, NULL, 0, 0))
        {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    
    void Draw(WPARAM wParam, LPARAM lParam, int count[10])
    {
      POINTS ptCursor;
      ptCursor = MAKEPOINTS(lParam);
      HDC   hDC;
      hDC = GetDC(hWnd);
      if(wParam & WM_LBUTTONDOWN)
      DrawIcon(hDC, ptCursor.x, ptCursor.y,
        (HICON)(WORD)GetClassLong(hWnd, GCL_HICON));
      ReleaseDC(hWnd, hDC);
      count++;
    }
    
    void Count()
    {
    	HDC hDC;
    	PAINTSTRUCT ps;
    	hDC = BeginPaint(hWnd, &ps);
    	TextOut(hDC, 10, 10, count, 4);
    	EndPaint(hWnd, &ps);
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            switch(message)
            {
              case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
    
    		  case WM_PAINT:
    			  Count();
    			  break;
    
    		  case WM_MOUSEMOVE:
    			  Draw(wParam, lParam, count);
    			  break;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    Does the error cause something with Unicode? If yes how do I get it right?

    Thank you for your time

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > it does not take my INT value.
    Because it is up to you to take your array and turn it into a string, which you then pass to TextOut
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  3. Flowchart Question
    By dmkanz07 in forum C Programming
    Replies: 1
    Last Post: 04-08-2007, 11:33 AM
  4. Counter Heap Sort
    By Achillles in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 12:17 PM
  5. how to obtain first character of every other word
    By archie in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2002, 01:58 PM