WIN32SDK's Hello,world program

Source: Internet
Author: User

For the first time, write the Win32gui program with Code::Blocks, with reference to GDI + groping for half a day. The SDK is tiring to write the GUI, and later it's about QT or some other way.

Code:

/***code by Lichmama from cnblogs.com* @platfrom: code::blocks 13.12/windows XP*/#ifDefined (UNICODE) &&!defined (_UNICODE)#define_unicode#elifDefined (_UNICODE) &&!defined (UNICODE)#defineUnicode#endif#include<tchar.h>#include<windows.h>#include". \gdiplus.h"#defineBUTTON 101#defineWs_ex_layered 0x80000#defineGwl_exstyle (-20)#defineLwa_alpha 2#defineSc_dragmove 0xf012/*Declare Windows Procedure*/LRESULT CALLBACK windowprocedure (HWND, UINT, WPARAM, LPARAM); typedef BOOL (WINAPI*Pfslwa) (HWND hwnd, COLORREF CR, BYTE Balpha, DWORD dwFlags); Pfslwa setlayeredwindowattributes;/*Make the class name into a global variable*/TCHAR szclassname[]= _t ("Codeblockswindowsapp");intWINAPI WinMain (hinstance hthisinstance, hinstance hprevinstance, LPSTR lpsza Rgument,intncmdshow)               {HWND hwnd; /*The handle for our window*/MSG messages; /*Here messages to the application is saved*/Wndclassex Wincl; /*Data structure for the Windowclass*/    /*The Window structure*/wincl.hinstance=hthisinstance; Wincl.lpszclassname=Szclassname; Wincl.lpfnwndproc= Windowprocedure;/*This function was called by Windows*/Wincl.style= Cs_dblclks;/*Catch double-clicks*/wincl.cbsize=sizeof(Wndclassex); /*Use default icon and Mouse-pointer*/Wincl.hicon=LoadIcon (NULL, idi_application); WINCL.HICONSM=LoadIcon (NULL, idi_application); Wincl.hcursor=loadcursor (NULL, Idc_arrow); Wincl.lpszmenuname= NULL;/*No Menu*/Wincl.cbclsextra=0;/*No Extra bytes after the window class*/Wincl.cbwndextra=0;/*structure or the window instance*/    /*Use Windows ' s default colour as the background of the window*/Wincl.hbrbackground=(Hbrush) Color_background; /*Register the window class, and if it fails quit the program*/    if(! RegisterClassEx (&Wincl)) return 0; /*the class is registered, let's Create the program*/hwnd=CreateWindowEx (0,/*Extended possibilites for variation*/Szclassname,/*Classname*/NULL,//_t ("Code::Blocks Template Windows App"),/* Title Text */Ws_popup,//Ws_overlappedwindow,/* Default window * /            -,/*Windows decides the position*/            -,/*where the window ends up in the screen*/           770,/*The programs width*/            +,/*and height in pixels*/Hwnd_desktop,/*The window is a child-window to desktop*/NULL,/*No Menu*/Hthisinstance,/*Program Instance Handler*/NULL/*No Window Creation data*/           ); /*Make the window visible in the screen*/ulong_ptr Gdiplustoken;    Gdiplus::gdiplusstartupinput Gdiplusinput; Gdiplusstartup (&gdiplustoken, &gdiplusinput, NULL);    ShowWindow (hwnd, ncmdshow); /*Run the message loop. It'll run until GetMessage () returns 0*/     while(GetMessage (&messages, NULL,0,0))    {        /*Translate Virtual-key messages into character messages*/TranslateMessage (&messages); /*Send message to Windowprocedure*/DispatchMessage (&messages); }    /*The program Return-value was 0-the value that PostQuitMessage () gave*/Gdiplus::gdiplusshutdown (Gdiplustoken); returnMessages.wparam;}/*This function was called by the Windows function dispatchmessage ()*/LRESULT CALLBACK Windowprocedure (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {Switch(message)/*Handle the Messages*/    {         Casewm_create://SetWindowLong (hwnd, Gwl_style, GetWindowLong (hwnd, Gwl_style) & ~ws_caption); //SetWindowPos (hwnd, NULL, 0, 0, 0, 0, swp_nosize| swp_nozorder| Swp_drawframe);SetWindowRgn (hwnd, CREATEROUNDRECTRGN (0,0,770, +, the, the), TRUE); SetWindowLong (hwnd, Gwl_exstyle, GetWindowLong (hwnd, Gwl_exstyle)|ws_ex_layered);                {hmodule hmod; Hmod= (hmodule) LoadLibrary ("user32.dll"); SetLayeredWindowAttributes= (Pfslwa) GetProcAddress (Hmod,"setlayeredwindowattributes"); SetLayeredWindowAttributes (hwnd,0, -, Lwa_alpha);            CloseHandle (HMOD); }             Break;  Casewm_paint: {paintstruct ps;                Hbitmap hbmp;                BITMAP bmp;                HDC HMEMDC;                HDC hdc; BeginPaint (hwnd,&PS); HDC=GETWINDOWDC (HWND); Hbmp=(HBITMAP) LoadImage (NULL,"d:\\12.bmp", Image_bitmap,0,                    0, Lr_defaultsize|lr_loadfromfile); GetObject (hbmp,sizeof(BMP), &BMP); HMEMDC=CreateCompatibleDC (NULL);                SelectObject (HMEMDC, hbmp); BITBLT (HDC,0,0, Bmp.bmwidth, Bmp.bmheight, HMEMDC,0,0, srccopy);                DeleteObject (hbmp);                DeleteDC (HMEMDC);                ReleaseDC (hwnd, HDC); EndPaint (hwnd,&PS);                } {paintstruct ps;                HDC hdc;                UINT width;                UINT height; WCHAR file[]={l"D:\\3.png"}; BeginPaint (hwnd,&PS); HDC=GETWINDOWDC (HWND); Gdiplus::gpimage*image; Gdiplus::gpgraphics*Graphics; Gdiplus::D llexports::gdiploadimagefromfile (file,&image); Gdiplus::D LLEXPORTS::GDIPCREATEFROMHDC (HDC,&graphics); Gdiplus::D llexports::gdipgetimagewidth (Image,&width); Gdiplus::D llexports::gdipgetimageheight (Image,&height); Gdiplus::D llexports::gdipdrawimagerect (graphics, image, the,Ten, width*0.1, height*0.1);                Gdiplus::D llexports::gdipdisposeimage (image);                Gdiplus::D llexports::gdipdeletegraphics (graphics);                ReleaseDC (hwnd, HDC); EndPaint (hwnd,&PS); }             Break;  Casewm_lbuttondown: {//(700,10)-(751.61)UINT cx=LoWord (LParam); UINT Cy=HiWord (LParam); if(cx>= the&& cx<=751){                    if(cy>=Ten&& cy<= A){                        if(The MessageBox (hwnd,"do you want to quit the program?","MessageBox", mb_yesno) = =Idyes)                        DestroyWindow (HWND);  Break; }}} SendMessage (Hwnd,wm_syscommand,sc_dragmove,0);  Break;  CaseWm_destroy:postquitmessage (0);/*send a wm_quit to the message queue*/             Break; default:/*For messages so we don ' t deal with*/            returnDefWindowProc (hwnd, message, WParam, LParam); }    return 0;}

Paste a Picture:

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.