Hi there,

I'm an old programmer trying to get back into it and vastly confused. I know or at least knew how to program in C and found it fairly easy, but Windows programming has me stymied. Basically I'm trying to figure out Win32 Api and have started to get a very small grasp of it.
What I would like to do is create a 2 text boxes and several buttons in a Windows type window (not a dos type window), find out when a button has been pressed and which one and output text to the two text boxes.
I figure I'll try a little baseball simulation as a way to relearn things. So one text box would give play by play such as Jones hits a double to past the left fielder and the other would give the game situation such as line score and balls and strikes. The buttons would be for things like swinging away, bunting, hit and run, etc...
All this seems simple in my memory in the old dos days, but I can't get so much as a line of text out now. Any help or pointing in the right direction would be appreciated.
I'm using Microsoft Visual C++ 2010 Express which doesn't have a resource editor, which likely part of my problem.

Well, a nice place to start is always here: http://www.winprog.org/tutorial/

However without the resource editor, you have a few different options, you could download a seperate resource editor, write your own resource file, or just avoid it entirely.

First thing's first, you need the code for setting up a small window, hopefully this should help refresh your memory on the topic a bit :)

#include <windows.h>

LRESULT CALLBACK WndProc(
      HWND hwnd,
      UINT msg,
      WPARAM wParam,
      LPARAM lParam)
{
  switch ( msg ) {
    case WM_CREATE:
      {
        // Make buttons here if you dont use any resources
      }
      break;
    case WM_COMMAND:
      {
        /* Button-pressed message is sent here

        switch ( LOWORD(wParam) ) {
        }

        */
      }
      break;
    case WM_CLOSE:
      {
        DestroyWindow( hwnd );
      }
      break;
    case WM_DESTROY:
      {
        PostQuitMessage( 0 );
      }
      break;
    default:
      return DefWindowProc( hwnd, msg, wParam, lParam );
  }

  return 0;
}

int WINAPI WinMain(
      HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nShowCmd)
{
  WNDCLASSEX wc;
  HWND hwnd;
  MSG msg;

  wc.cbSize = sizeof(WNDCLASSEX);
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  wc.hInstance = hInstance;
  wc.lpfnWndProc = WndProc;
  wc.lpszClassName = "myclass";
  wc.lpszMenuName = NULL;
  wc.style = 0;

  if ( !RegisterClassEx(&wc) ) {
    return 1;
  }

  hwnd = CreateWindowEx(
          WS_EX_APPWINDOW,
          "myclass",
          "Window",
          WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
          CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, // x,y,width,height
          NULL, NULL, hInstance,
          NULL );

  if ( hwnd == NULL ) {
    return 1;
  }

  ShowWindow( hwnd, SW_SHOW );
  UpdateWindow( hwnd );

  while ( GetMessage(&msg, NULL, 0, 0) > 0 ) {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
  }

  return (int) msg.wParam;
}

Edit: Don't forget to change the compiler setting to use 8-bit characters instead of unicode

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.