#include <stdio.h> int main ()
{PRINTFSS ("Hello world\n"); return 0; }
Countless people know this code, but the number of the following code is slightly less than the above.
#include <windows.h>
int main ()
{
MessageBox (NULL, "Hello World", "window", MB_OK);
return 0;
}
After these two pieces of code will display a DOS window, the following code brings you into the Windows environment, there is no DOS window what happened.
#include <windows.h>
int WINAPI WinMain (hinstance hins,hinstance prehins,lpstr Show)
{
MessageBox (NULL, "Hello World", "window", MB_OK);
return 0;
}
In this way, you write one of the simplest Windows programs, but there is only one message box, there is no real sense of the window.
#include <windows.h>
Message handler function
Lresult CALLBACK winporc (HWND hwnd,uint msg,wparam wparam,lparam);
int WINAPI WinMain (hinstance hins,hinstance phins,lpstr Show)
{
HWND hwnd;
MSG msg;
Wndclass Wnd;
ZeroMemory (&wnd,sizeof (WNDCLASS));
Wnd.hbrbackground = (hbrush):: Getstockobject (Dkgray_brush);
Wnd.hinstance = Hins;
Wnd.lpfnwndproc = WINPORC;
Wnd.lpszclassname= "Test";
Wnd.style = Cs_vredraw|cs_hredraw;
if (!::registerclass (&wnd))
{
return 0;
}
hwnd =:: CreateWindow ("Test", "Test", ws_overlapped| Ws_sysmenu,0,0,100,100,null,null,hins,null);
if (hwnd==null)
{
return 0;
}
showwindow (hwnd,show );
updatewindow (HWND);
while (TRUE) {
if (::P eekmessage (&msg,null,0,0,pm_remove)) {
if (Msg.message = = wm_quit) {
break;
}
::translatemessage (&MSG);
::D ispatchmessage (&msg);
}
}
return 0;
}
Lresult CALLBACK winporc (HWND hwnd,uint msg,wparam Wparam,lparam)
{
Switch (msg) {
Case Wm_destroy:
PostQuitMessage (0);
Break
Default
Break
}
return::D Efwindowproc (Hwnd,msg,wparam,lparam);
}