Joshp93
February 19th, 2009, 05:26 AM
Hi i'm very new to windows programming, i'm experinced in console win32 programming but iv decided to move on. Im using bloodshevdev c++ compiler 4.9.9.2. And i'm on windows vista.
Ive started to make a new window and iv been getitng error, am i just missing something or is my syntax wrong, please in simple terms im quite new lol. thanks in advnace
// Windows Application - Hello World.
//
#define WIN32_LEAN_AND_MEAN // Speeds up compile and run.
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#define WINDOW_CLASS_NAME "WINCLASS1"
// Globals
HWND main_window_handle = NULL; //Saves the window handle.
// Functions
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps; // Used In Paint (Brushes, and pens).
HDC hdc; // Handle to a device context.
//
switch(msg)
{
case WM_CREATE:
{
return(0);
}
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
}
case WM_DESTROY:
{
PostQuitMessage(0);
return (0);
}
default:break;
}
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
// End of event handler function.
// Main Entry Point.
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;
// Window Class Create.
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor (NULL, IDI_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(Black_Brush);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
// Register..
if(!RegisterClass(&winclass))
return (0);
if(!(hwnd = CreateWindow(WINDOW_CLASS_NAME, "Hello World",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
0,0,
320,200,
NULL,
NULL,
hinstance,
NULL)))
return(0);
// Save in Global.
main_window_handle = hwnd;
// Main event loop.
while(1)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wparam);
}//end winmain.
The compiler output is:
C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
56 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp expected `;' before "hinstance"
58 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp `IDI_ARROW' undeclared (first use this function)
59 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp `Black_Brush' undeclared (first use this function)
86 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp 'struct MSG' has no member named 'wparam'
C:\Users\Josh\Documents\MyProgs\Win Apps\Makefile.win [Build Error] [NewWindow..o] Error 1
cheers.
Ive started to make a new window and iv been getitng error, am i just missing something or is my syntax wrong, please in simple terms im quite new lol. thanks in advnace
// Windows Application - Hello World.
//
#define WIN32_LEAN_AND_MEAN // Speeds up compile and run.
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#define WINDOW_CLASS_NAME "WINCLASS1"
// Globals
HWND main_window_handle = NULL; //Saves the window handle.
// Functions
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps; // Used In Paint (Brushes, and pens).
HDC hdc; // Handle to a device context.
//
switch(msg)
{
case WM_CREATE:
{
return(0);
}
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
}
case WM_DESTROY:
{
PostQuitMessage(0);
return (0);
}
default:break;
}
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
// End of event handler function.
// Main Entry Point.
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;
// Window Class Create.
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor (NULL, IDI_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(Black_Brush);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
// Register..
if(!RegisterClass(&winclass))
return (0);
if(!(hwnd = CreateWindow(WINDOW_CLASS_NAME, "Hello World",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
0,0,
320,200,
NULL,
NULL,
hinstance,
NULL)))
return(0);
// Save in Global.
main_window_handle = hwnd;
// Main event loop.
while(1)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wparam);
}//end winmain.
The compiler output is:
C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
56 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp expected `;' before "hinstance"
58 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp `IDI_ARROW' undeclared (first use this function)
59 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp `Black_Brush' undeclared (first use this function)
86 C:\Users\Josh\Documents\MyProgs\Win Apps\NewWindow..cpp 'struct MSG' has no member named 'wparam'
C:\Users\Josh\Documents\MyProgs\Win Apps\Makefile.win [Build Error] [NewWindow..o] Error 1
cheers.