Crazy things

So I am pretty new to the Win32 API, but this kinda thing doesn't make sense to me, I input a number for TextOut to display and it displays a random number, like say I put 100 as what I want it to say, it will say 1325808

This is the code, the rest of the code is the basic VS2013 starting junk

case WM_PAINT:
{
GetClientRect(hWnd, &rect);

horz = rect.right;
vert = rect.bottom;

output = wsprintf(buffer, TEXT("Horizontal resolution: %i. %i should be (100) %i should be (101)", horz, 100, 101));

PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);

TextOut(hdc, 250, 250, buffer, output);

EndPaint(hWnd, &ps);
}
You got the brackets wrong in your TEXT macro.
Should be like this:
output = wsprintf(buffer, TEXT("Horizontal resolution: %i. %i should be (100) %i should be (101)"), horz, 100, 101);

...basic VS2013 starting junk

Yes the VS template is far to complex, probably not meant for beginners and demos.

Here is a simple demo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <windows.h>
#include <tchar.h>
#include <crtdbg.h>

LRESULT CALLBACK WndProc (HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
  RECT rect;
  int horz, vert, output;
  TCHAR buffer[256];

  switch (msg)
  {
    case WM_CREATE:
    {
      HINSTANCE hIns = ((LPCREATESTRUCT)lParam)->hInstance;
      return 0;
    }
    case WM_PAINT:
    {
      GetClientRect(hWnd, &rect);

      horz = rect.right;
      vert = rect.bottom;

      output = wsprintf(buffer, _T("Horizontal resolution: %i. %i should be (100) %i should be (101)"), horz, 100, 101);

      PAINTSTRUCT ps;
      HDC hdc = BeginPaint(hWnd, &ps);

      TextOut(hdc, 250, 250, buffer, output);

      EndPaint(hWnd, &ps);
    }
    case WM_COMMAND:
    {
      return 0;
    }
    case WM_DESTROY:
    {
      PostQuitMessage (0);
      return 0;
    }
  }

  return (DefWindowProc (hWnd, msg, wParam, lParam));
}


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
  TCHAR szClassName[] = _T("Template");
  TCHAR szWindowName[] = _T("Template");
  WNDCLASSEX wc = { 0 };
  MSG messages;
  HWND hWnd;

  wc.lpszClassName = szClassName;
  wc.lpfnWndProc = WndProc;
  wc.cbSize = sizeof (WNDCLASSEX);
  wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
  wc.hInstance = hInstance;
  
  _ASSERTE(RegisterClassEx (&wc) !=0);
  
  hWnd = CreateWindowEx (0, szClassName, szWindowName, WS_OVERLAPPEDWINDOW, 
      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
      HWND_DESKTOP, 0, hInstance, 0);
      
  _ASSERTE(::IsWindow(hWnd));
  
  ShowWindow (hWnd, iShow);
  while (GetMessage (&messages, NULL, 0, 0))
  {
    TranslateMessage (&messages);
    DispatchMessage (&messages);
  }

  return static_cast<int>(messages.wParam);
}

Just save it as Main.cpp or so and create a new project from existing sources. Also do not use precompiled headers.


This is the code, the rest of the code is the basic VS2013 starting junk


I personally take a lot of pride in my code, trying to make it as perfect as possible. Under no circumstances would I ever leave any 'starting junk' as you put it, in my code. I know Microsoft is just trying to help with the startup code, but really, the best they could do would be a 'tough love' approach, i.e., make everybody learn to write their own code and understand it fully. Just my opinion.
Topic archived. No new replies allowed.