Create window under console and WinMain Portal create Windows Simple program

Source: Internet
Author: User

Console Creation window (with both console window and newly created window) (Project type: Console application)
#include "windows.h" #include "TCHAR.h" LRESULT CALLBACK WindowProc (HWND hwnd,uint umsg,wparam wparam,lparam LPARAM); int _tmain (int argc, _tchar* argv[]) {hinstance hinstance;hinstance = GetModuleHandle (NULL); Wndclass Draw;draw.cbclsextra = 0;draw.cbwndextra = 0;draw.hcursor = LoadCursor (hinstance, IDC_ARROW);;D Raw.hicon = LoadIcon (hinstance, idi_application);;D Raw.lpszmenuname = Null;draw.style = Cs_hredraw | Cs_vredraw;draw.hbrbackground = (hbrush) Color_window;draw.lpfnwndproc = Windowproc;draw.lpszclassname = _T ("DDraw") ;D raw.hinstance = hinstance; RegisterClass (&draw); HWND hwnd = CreateWindow (_t ("DDraw"),//class name registered above, to be fully consistent L "draw",//Window caption text Ws_overlappedwindow,//window appearance style 38     ,//window relative to the parent's x-coordinate 20,//window relative to the parent's y-coordinate 640,//window width 480,//window height              NULL,//no parent window, NULL NULL,//No menu, NULL HINSTANCE,//instance handle for current application null); No additional data, NULL//Display window ShowWindow(hwnd, sw_show);//Update window UpdateWindow (HWND);//message loop MSG msg;while (GetMessage (&msg, NULL, 0, 0)) {TranslateMessage (&msg);D ispatchmessage (&msg);}} Implementation of message processing functions LRESULT CALLBACK WindowProc (_in_ HWND hwnd,_in_ UINT umsg,_in_ WPARAM wparam,_in_ LPARAM LPARAM) {switch (umsg)   {Case wm_destroy:{postquitmessage (0); return 0;}} Return DefWindowProc (hwnd, umsg, WParam, LParam);}


Create window under WinMain Portal (only newly created window) (Project type: Windows application)
#include <windows.h> #include "TCHAR.h" #include <stdio.h>lresult CALLBACK WindowProc (HWND hwnd,//Handle  To Windowuint umsg,//Message Identifierwparam WParam,//First message Parameterlparam LParam//second message parameter); int WINAPI WinMain (hinstance hinstance,//handle to current instancehinstance hprevinstance,//Handle To previous INSTANCELPSTR lpCmdLine,//Command Lineint ncmdshow//show state) {Wndclass WNDCLS;WNDC Ls.cbclsextra = 0;wndcls.cbwndextra = 0;wndcls.hbrbackground = (hbrush) getstockobject (black_brush); wndcls.hCursor = LoadCursor (null, idc_cross); Wndcls.hicon = LoadIcon (null, idi_error); wndcls.hinstance = Hinstance;wndcls.lpfnwndproc = Windowproc;wndcls.lpszclassname = _t ("Hello"); wndcls.lpszmenuname = Null;wndcls.style = Cs_hredraw | Cs_vredraw; RegisterClass (&AMP;WNDCLS); HWND Hwnd;hwnd = CreateWindow (_t ("Hello"), L "World", ws_overlappedwindow,0, 0, M, n, NULL, NULL, HINSTANCE, NULL); ShowWindow (hwnd, SW_Shownormal); UpdateWindow (HWND); MSG Msg;while (GetMessage (&msg, NULL, 0, 0)) {translatemessage (&msg);D ispatchmessage (&msg);} return 0;} Implementation of the message processing function LRESULT CALLBACK WindowProc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) {switch (umsg) {case Wm_d   estroy:{postquitmessage (0); return 0;}} Return DefWindowProc (hwnd, umsg, WParam, LParam);}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Create window under console and WinMain Portal create Windows Simple program

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.