Hi
I'm starting out Win32API progaramming,
and my first code is a bit iffy, it doesnt have the
standard close icon on the top right hand corner,
have I forgotten a style? I'm sure it agrees exactly with
other basic code (i've checked several time already!)
and I had to typecast the line:
winClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
even though the code I was copying did not have that (HBRUSH)
in it.
Many thanks
//Sunday 3rd February
//#####INCLUDES
#include //for windows functionalilty
#include #include //#####DEFINES
#define WIN32_LEAN_AND_MEAN //instruct compiler not to include extraneous MFC info
//######FUNCTIONS
LRESULT CALLBACK WinProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam
);
//Prototype of Callback function
//main entry point for all Win prog
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MSG msg; //generic message
HWND hWnd; //handle to the window
WNDCLASSEX winClass; //empty window class
winClass.cbClsExtra = NULL;
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.cbWndExtra = NULL;
winClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); //white background
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
winClass.hInstance = hInstance;
winClass.lpfnWndProc = WinProc;
winClass.lpszClassName = "Skeleton Program";
winClass.lpszMenuName = NULL;
winClass.style = CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
if(!(RegisterClassEx(&winClass)))//Register Class-only proceed if valid
{
return(0);
}
if(!(CreateWindowEx(
NULL, //Extended Style
"Skeleton Program", //Class Name
"Skeleton Program", //Window Name
WS_OVERLAPPED|WS_VISIBLE, //Style
0, //initial x
0, //initial y
400,//initial width
400,//initial height
NULL,//handle to Parent
NULL,//handle to Menu
hInstance,//instance of application
NULL//extra creation parameters
)))
{
return(0);
}//return successful CreateWindowEx
//enter main msgLoop
//read next msg from Applications Messge queue
while(GetMessage(&msg, NULL, 0, 0)) //GetMessage() returns non-0 except for WM_QUIT
//pointer to Msg, target Window, 1st Msg in range, last Msg in range
{
TranslateMessage(&msg); //cooks the msg
DispatchMessage(&msg); //sends msg onto Win, which fwds its to WinProc
}//end while
return(msg.wParam);
} //exit program, end WinMain
LRESULT CALLBACK WinProc(HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
)
{
//Main msg handler of system
PAINTSTRUCT ps; //used in WM_PAINT
HDC hdc; //handle to a device context
//Process the msg
switch(Msg)
{
case WM_CREATE:
{
//perform initialisation
//return success
return(0);
}
case WM_PAINT:
{
//validate the window
hdc = BeginPaint(hWnd, &ps);
//all painting occurs
EndPaint(hWnd, &ps);
return(0);
}
case WM_DESTROY:
{
//Quit pgm, sends a WM_QUIT msg
//0 returned by GetMessage() in WinMain()
//program exits WinMain() msg loop
//returns to Win
PostQuitMessage(0);
//return success
return(0);
} break;
default:
//end switch
break;
}//end switch-case loop
return(DefWindowProc(hWnd, Msg, wParam, lParam));
//process anything else that was not taken care of
}//end WinProc
Comments