Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

laurence900

Windows Programming

This topic is 5582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
I just whipped this up in about 3 minutes


  
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

// main window

HWND gMainWindow;
HINSTANCE gInstance;

// Terminates the program

void 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);
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!