1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
//g++ Form1.cpp -luser32 -lkernel32 -oForm1_gcc.exe -mwindows -m64 -s -Os
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
if(msg==WM_DESTROY) // This is the Window Procedure. The concept of the
{ // Window Procedure is the most important concept to
PostQuitMessage(0); // grasp in C/C++ WinApi coding. You never call this
return 0; // function with your code; rather, Windows calls it
} // to inform code here of events occurring. The events
// are reported here as messages.
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPWSTR lpszArgument, int iShow)
{
MSG messages; // The concept of the Window Class and its associated Window Procedure are
WNDCLASS wc; // the most important concepts in Windows Programming.
wc.lpszClassName = L"Form1", wc.lpfnWndProc = fnWndProc; // The Class Name Will Be Form1 And The Symbol fnWndProc
wc.hInstance = hInstance, wc.style = 0; // Will Be Resolved At Runtime To The Virtual Address Of
wc.cbClsExtra = 0, wc.cbWndExtra = 0; // Form1's Window Procedure, Which Windows Will Call
wc.hIcon = NULL, wc.hCursor = NULL; // Through This Address Rather Than Through It's Name.
wc.lpszMenuName = NULL, wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
RegisterClass(&wc); // Register The Window Class With Windows
CreateWindow(L"Form1", L"Form1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 100, 325, 300, HWND_DESKTOP, 0, hInstance, 0);
while (GetMessage(&messages, NULL, 0, 0)) // The message pump retrieves messages from the program's
{ // message queue with GetMessage(), does some translation
TranslateMessage(&messages); // work in terms of character messages, then calls the
DispatchMessage(&messages); // Window Procedure associated with the HWND of the message
} // being processed. Note that an app can have many Window
return (int)messages.wParam;
}
|