Windows Programming

Started by
2 comments, last by laurence900 21 years, 2 months ago
Hey every one im new to this forum because i have been on so many other forums hoping there are some sane people who actually answer my question. Any way here it is. I have started windows programming a few days ago and i would like to know some source code that displays the words hello in the main window. Please only give me some really really good tutorials or web sites that do what i have asked for. thanks very much
Advertisement
I just whipped this up in about 3 minutes


  #define WIN32_LEAN_AND_MEAN#include <windows.h>// main windowHWND gMainWindow;HINSTANCE gInstance;// Terminates the programvoid ErrorExit(LPCSTR lpMessage){	MessageBox(NULL,lpMessage,"Application Error!",MB_OK | MB_ICONERROR);	ExitProcess(-1);}LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* unUsed */,LPSTR lpCmdLine,int iShowCmd){	// store some vars	gInstance = hInstance;		// register window class	WNDCLASSEX wc;	ZeroMemory(&wc,sizeof(wc));	wc.cbSize = sizeof(WNDCLASSEX);	wc.hCursor = LoadCursor(NULL,IDC_ARROW);	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);	wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);	wc.lpszClassName = "MyWindowClass";	wc.hInstance = gInstance;	wc.lpfnWndProc = WndProc;		if(!RegisterClassEx(&wc))		ErrorExit("Could not register class!");		// Create the window	gMainWindow = CreateWindowEx(		WS_EX_OVERLAPPEDWINDOW,		"MyWindowClass",		"My Application",		WS_VISIBLE | WS_OVERLAPPEDWINDOW,		CW_USEDEFAULT,		CW_USEDEFAULT,		CW_USEDEFAULT,		CW_USEDEFAULT,		NULL,		NULL,		gInstance,		NULL			);		MSG msg;	while(GetMessage(&msg,NULL,0,0))	{		TranslateMessage(&msg);		DispatchMessage(&msg);	}	return msg.wParam;}LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam){	PAINTSTRUCT ps;	HDC paintDC;	static LPCSTR lpMessageOut = "Hello";		switch(uMsg)	{	case WM_PAINT:		paintDC = BeginPaint(hWnd,&ps);		TextOut(paintDC,10,10,lpMessageOut,lstrlen(lpMessageOut));		EndPaint(hWnd,&ps);				break;	}		return DefWindowProc(hWnd,uMsg,wParam,lParam);}  
daerid@gmail.com
heres one of the more famous tutorial out there:
http://www.winprog.org/tutorial/index.html

also just search google.com for "c winapi tutorial" or "win32 tutorial" and you''ll get loads of tutorials. If your more interested in learning more of the graphic capabilities windows offer search for "wingdi" or "win gdi". However if you are interested in more advanced graphics than simple animations and static images you should search for direct x tutorials however a good understanding of windows is neccessary before even considering direct x, also great knowledge of c++ too.

good luck on your future windows programming
I am a signature virus. Please add me to your signature so that I may multiply.
thanks very much both of you

This topic is closed to new replies.

Advertisement