I know this is a php forum, and I've posted this on a few C forums as well...but you know...since this is such a responsive community...
Anyway, I've decided to have a bash at C. I can handle CLI programs fine - it's basically the same as PHP. However, I've been trying to use the windows API to create a graphical user interface...to no avail.
Here's my code:
Code: Select all
#include <windows.h>
const char Window_Class[] = "WindowClass";
//window callback handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//switch message...
switch(msg)
{
//close window
case WM_CLOSE:
MessageBox(hwnd, "Bye", ":)", 0);
DestroyWindow(hwnd);
break;
//display window
case WM_PAINT:
RECT rcClient;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
DrawTextEx(hdc, "Hello...world?"+'\0', -1, &rcClient, DT_CENTER, NULL);
EndPaint(hwnd, &ps);
break;
//register window process
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
char *lpCmdLine, int nCmdShow)
{
//register windows classes
WNDCLASSEX window;
HWND hwnd;
MSG msg;
//register window with....windows ;)
window.cbSize = sizeof(WNDCLASSEX);
window.style = 0;
window.lpfnWndProc = WndProc;
window.cbClsExtra = 0;
window.cbWndExtra = 0;
window.hInstance = hInstance;
window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
window.hCursor = LoadCursor(NULL, IDC_ARROW);
window.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
window.lpszMenuName = NULL;
window.lpszClassName = Window_Class;
window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//...
RegisterClassEx(&window);
//create the window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
Window_Class,
"Window!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 250,
NULL, NULL, hInstance, NULL);
//run...
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//run the message loop
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Any help would be awesome,
Cheers,
Jack.