c++ windows API label, help

Associate
Joined
10 Oct 2008
Posts
353
Location
Dundee
I am trying to make a simple label that will show a string inside it. Basically I want it to sit at co-ord 5,5 on the form and be transparent.

I found the msdn page for labels, and the member list.

But I just can't figure out how to implement it.

I have my window set up and working:
Code:
//prototype
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

//the window class
void RegisterMyWindow(HINSTANCE hInstance){
  WNDCLASSEX  wcex;									

  wcex.cbSize = sizeof(wcex);
  wcex.style = CS_HREDRAW | CS_VREDRAW;
  wcex.lpfnWndProc = WndProc;
  wcex.cbClsExtra = 0;
  wcex.cbWndExtra = 0;
  wcex.hInstance = hInstance;
  wcex.hIcon = 0;
  wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  					
  wcex.hbrBackground = BLACK; //black
  wcex.lpszMenuName = NULL;
  wcex.lpszClassName = L"SpaceShooterClass";
  wcex.hIconSm = 0;

  RegisterClassEx(&wcex);
}

//create the window
BOOL InitialiseMyWindow(HINSTANCE hInstance, int nCmdShow){
  HWND hwnd;
  hwnd = CreateWindow(L"SpaceShooterClass", L"Space Shooter", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 
  CW_USEDEFAULT, CW_USEDEFAULT, GAME_WIDTH, GAME_HEIGHT, NULL,	NULL, hInstance, NULL);								
  if(!hwnd) return FALSE;

  ShowWindow(hwnd, nCmdShow);						
  UpdateWindow(hwnd);	
  ghwnd = hwnd;
  return TRUE;
}

(by the way, it is a very simple game I am making, using bitmap drawing as basic sprites). My intention is to use the label for the score.

current label code:
Code:
//score lable, for the HUD
void makeScoreLabel(){
  Label scoreLabel;
  scoreLabel->BorderStyle = System::Windows::Forms::BorderStyle::None; //no border
  scoreLabel->Text = L"Score:"; //content
  //scoreLabel->AutoSize = true;
  scoreLabel->Left = 5; //position
  scoreLabel->Top = 5;
}

I am getting errors like:
vs2008 said:
'Label' : undeclared identifier
syntax error : missing ';' before identifier 'scoreLabel'
'scoreLabel' : undeclared identifier
left of '->BorderStyle' must point to class/struct/union/generic type

Which leads me to believe I might have it in the wrong namespace or something. Also, do I not have to set the parent's handle or something?

I need a bit of help because the windows API confuses me. I normally program php or game mods so I can get a bit confused working at this lower level.
 
I'll take a proper look at this when I get to work tomorrow. Should be easy to figure out.

One thing to note; you're attempting to access scoreLabel's member functions as if you'd declared it on the heap (with the -> pointer operator). Use "scoreLabel.BorderStyle" instead. Alternatively, use the "new" keyword (although it's not something I would do).
 
Thanks, I eagerly await your response.

I wish miscosoft had better msdn support for c++, rather than "visual" c++ (which I always thought was just the ide?)

Oh, incase it matters for anything I am using visual studio 2008. Would use devc++ or something but it's easier to look at provided examples which were made in vs2008 this way.
 
Back
Top Bottom