Direct basic learning (1) the simplest windows program

Source: Internet
Author: User

Today, I started to study direct3d programming carefully.

 

The direct program is also a Windows program. According to my own understanding, a Windows program is a window program and there is a window. Therefore, a direct program must have a window. In my understanding, a window is a kind of human-machine interface, which is the interface for machine-to-human communication.

Now that there is an interface, the next step will be to exchange messages. If there is a message, it will be processed. People, process messages through the brain, and then send feedback to the computer through interfaces (Windows. What about machines? We know that the window program will have a window processing function, which is the brain of the program, and the window is its eyes and hands.

 

Let's look at the msdn routine:

 

// The simplest windows program </P> <p> # define window_class "strandedgame" // window class name <br/> # define window_name "Stranded" // window name <br/> # define win_width 800 // initial window width <br/> # define win_height 600 // initial window height </P> <p> # include <windows. h> </P> <p> // window handler <br/> lresult winapi msgproc (hwnd, uint MSG, wparam, lparam ); </P> <p> int winapi winmain (hinstance, hinstance hprevinstance, <br/> lpstr lpcmdline, int ncmdshow) <br/> {<br/> // design window class <br/> wndclassex WC = {sizeof (wndclassex), cs_classdc, msgproc, 0l, 0l, <br/> getmodulehandle (null), null, null, (hbrush) (color_window + 1), null, <br/> window_class, null }; <br/> // register the window class <br/> registerclassex (& WC ); </P> <p> // create a window <br/> hwnd = createwindow (window_class, window_name, <br/> ws_overlappedwindow, 0, 0, win_width, win_height, <br/> null, null, WC. hinstance, null); </P> <p> // display window <br/> showwindow (hwnd, sw_showdefault); <br/> updatewindow (hwnd ); </P> <p> // message loop (after the message is converted, it is processed by the window processing function) <br/> MSG; <br/> while (getmessage (& MSG, null, 0, 0) <br/>{< br/> translatemessage (& MSG ); <br/> dispatchmessage (& MSG); <br/>}</P> <p> // cancel window registration <br/> unregisterclass ("d3d tutorial", WC. hinstance); <br/> return 0; <br/>}</P> <p> // Message Processing <br/> lresult winapi msgproc (hwnd, uint MSG, wparam, lparam) <br/>{< br/> // Message Processing <br/> switch (MSG) <br/>{< br/> case wm_destroy: <br/> postquitmessage (0); <br/> return 0; </P> <p >}</P> <p> return defwindowproc (hwnd, MSG, wparam, lparam); <br/>}</P> <p>

 

In this way, a simple windows window program is generated, which has eyes, mouth, and brain (window processing function)

 

While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

The window processing function is like a brain, waiting for messages.

A message loop is like a human neural system that keeps telling the brain the messages you see in your eyes.

 

The above code is compiled by vc6.0 to generate a blank windows window at the desktop (0, 0.

Its brain can only recognize one message: wm_destroy // exit

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.