Windows API - Labels in c++

  • Bozebo
  • Expert
  • Expert
  • User avatar
  • Posts: 709
  • Loc: 404

Post 3+ Months Ago

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 members list.

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

I have my window set up and working:
CPP Code: [ Select ]
//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;
}
 
  1. //prototype
  2. LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
  3.  
  4. //the window class
  5. void RegisterMyWindow(HINSTANCE hInstance){
  6.   WNDCLASSEX  wcex;                          
  7.  
  8.   wcex.cbSize = sizeof(wcex);
  9.   wcex.style = CS_HREDRAW | CS_VREDRAW;
  10.   wcex.lpfnWndProc = WndProc;
  11.   wcex.cbClsExtra = 0;
  12.   wcex.cbWndExtra = 0;
  13.   wcex.hInstance = hInstance;
  14.   wcex.hIcon = 0;
  15.   wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  16.                
  17.   wcex.hbrBackground = BLACK; //black
  18.   wcex.lpszMenuName = NULL;
  19.   wcex.lpszClassName = L"SpaceShooterClass";
  20.   wcex.hIconSm = 0;
  21.  
  22.   RegisterClassEx(&wcex);
  23. }
  24.  
  25. //create the window
  26. BOOL InitialiseMyWindow(HINSTANCE hInstance, int nCmdShow){
  27.   HWND hwnd;
  28.   hwnd = CreateWindow(L"SpaceShooterClass", L"Space Shooter", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
  29.   CW_USEDEFAULT, CW_USEDEFAULT, GAME_WIDTH, GAME_HEIGHT, NULL, NULL, hInstance, NULL);                     
  30.   if(!hwnd) return FALSE;
  31.  
  32.   ShowWindow(hwnd, nCmdShow);                
  33.   UpdateWindow(hwnd);  
  34.   ghwnd = hwnd;
  35.   return TRUE;
  36. }
  37.  


(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:
CPP Code: [ Select ]
//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;
}
 
  1. //score lable, for the HUD
  2. void makeScoreLabel(){
  3.   Label scoreLabel;
  4.   scoreLabel->BorderStyle = System::Windows::Forms::BorderStyle::None; //no border
  5.   scoreLabel->Text = L"Score:"; //content
  6.   //scoreLabel->AutoSize = true;
  7.   scoreLabel->Left = 5; //position
  8.   scoreLabel->Top = 5;
  9. }
  10.  


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

Which leads me to believe I might have it in the wrong namespace or something. Also, do I not have to set the parent 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.

If you want me to link the full solution I can.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 113 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.