Windows core Programming 03-Steps to write a window program

Source: Internet
Author: User

To write a window program:

1 Defining the WinMain function

2 defining window processing functions (processing messages)

3 Register window class

4 Creating Windows (creating windows in memory)

5 Display window (draws the window based on the data in memory)

6 message loop (extract/translate/distribute) message

7 Message Processing

#include"Windows.h"LRESULT WndProc (HWND hwnd,uint nmsg,wparam wparam,lparam LPARAM) {ReturnDefWindowProc (Hwnd,nmsg,wparam,lparam);}//Defining the WinMain functionint WinMain (hinstance hinstance,hinstance hpreinstance,lpstr lpCmdLine,IntnCmdShow) {Wndclass wc={0}; HWND hwnd =0; MSG nmsg = {0};//Defining window processing Functions Wc.style = Cs_hredraw |Cs_vredraw; Wc.lpfnwndproc =(WNDPROC) WndProc; Wc.cbclsextra =0; Wc.cbwndextra =0; Wc.hinstance =HINSTANCE; Wc.hicon =NULL; Wc.hcursor =NULL; Wc.hbrbackground = (hbrush) (Color_window +1); Wc.lpszmenuname =NULL; Wc.lpszclassname ="Main";//Registration window class RegisterClass (&WC);//Create window (created in memory) HWnd = CreateWindow ("Main","HWnd", Ws_overlappedwindow,100,100,500,500,null,null,hinstance,null); // ShowWindow ( Hwnd,sw_show); // message loop while ( GetMessage (&nmsg,null,0,0 // message Handling TranslateMessage (&nmsg); DispatchMessage (&nmsg);} return 0   

Compile link ... Cl.exe Link.exe

Use of resources

Writing a resource's file-.rc resource script file

Writing RC Files-rc.exe

Linking resources to Programs-link.exe

Actual procedure:

1, create a new hellownd.rc file, with the content: "ICON Small.ico

VC 6.0 the requirements for. ico files are high if the appropriate. ico is going to build a window program to copy the inside of the Small.ico

2, copy small.ico copy to the same directory

3, compile:rc.exe hellownd.rc Generate Hellownd.res

4, link. obj with. RES link.exe hellownd.obj hellownd.res user32.lib

5, generate an icon to change the HelloWnd.exe

NMAKE and Makefile

  Nmake

Makefile a tool for interpreting execution, compiling and linking programs according to the definitions in the makefile file, and eventually generating the target file

  Makefile (. Mak)

A script file that defines operations such as compilation and linking (writes the processing commands for the project), and generally processes the entire project.

Syntax for makefile:

HELLO: Dependent rows

cl.exe hellownd.c/c//Command line

Rc.exe hellownd.rc//Command line

Link.exe hellownd.obj hellownd.res user32.lib//Command line

There can be multiple dependent rows in the makefile file

Execution mode

NMAKE first finds the first dependent row

Check dependencies on dependent rows, and if a dependency is found, first execute the dependency command line

After all dependent commands have been executed, execute your own command line.

To perform the steps:

1. Create a. mak file Hellownd.mak write the above syntax lines

2, execute the command using NMAKE to execute NMAKE Hellownd.mak

  3, if there are multiple dependent rows you can specify which dependent row to execute nmake/f hellownd.mak Clean

4, multiple dependent rows executed once and sequentially, followed by: dependent rows

    

Hello:clean   /C   rc.exe hellownd.rc   link.exe hellownd.obj hellownd.res user32.lib clean:  del  *. obj  del   *. Res  del  *.exe

Execute the command NMAKE Hellownd.mak executes the clean dependency line before executing the Hello dependency line

  

Windows core Programming 03-Steps to write a window program

Related Article

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.