Minimalist Windows programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.