Getting Started with Win32 (14): Using a dialog box as the main window

Source: Internet
Author: User
Tags include resource win32

We've been thinking about writing Win32 applications before:

1, Design window class. 2, register the window class. 3, create the window. ......

However, when we touch the control, we find a problem, we put the control on the window is really difficult, and the Resource dialog box has a graphics editor, it is relatively convenient to operate.

So, there's an idea: Use the dialog box as the main window, so we can make it easier to layout the controls.

In fact, this idea has been done on the Internet, but the people are compiled with Win32, of course, to make it into C + + is easier.

First, introduce the first way to create a dialog box directly by using the desktop as the parent window.

1, create a dialog box resources, the interface to play your design talent.

2, create an icon resource, both as an icon for the application (vs compile will choose the first to add to the resource icon as an EXE icon), also as a dialog box icon.

3. Create and display a dialog box in your code.

#include <Windows.h> #include "resource.h"//Open Visualization #pragma comment (linker, "\"/manifestdependency: Type= ' Win32 '/name= ' microsoft.windows.common-controls ' version= ' 6.0.0.0 ' processorarchitecture= ' * ' PublicKeyToken = ' 6595B64144CCF1DF ' language= ' * ' "") int_ptr CALLBACK Dlgproc (HWND hdlg, UINT msg, WPARAM WPARAM, LPARAM LP     
         
Aram);     
HINSTANCE Hginst;     
    int WINAPI WinMain (hinstance Hthisapp, hinstance Hprevapp, LPSTR lpcmd, int nshow) {hginst = Hthisapp;     
    HWND Hdlg = createdialog (Hthisapp, Makeintresource (idd_my), GetDesktopWindow (), (Dlgproc) dlgproc);     
    if (!HDLG) {return 0;     
    } ShowWindow (Hdlg,sw_show);     
    MSG msg;     
        while (GetMessage (&msg,null,0,0)) {translatemessage (&msg);     
    DispatchMessage (&AMP;MSG);     
return 0; INT_PTR CALLBACK Dlgproc (HWND hdlg, UINT msg, WPARAM WPARAM,LPARAM LPARAM) {switch (msg) {case WM_INITDIALOG://Setup dialog box icon S     
        Endmessage (Hdlg, Wm_seticon, Icon_small, (LPARAM) LoadIcon (Hginst, Makeintresource (Idi_app)));     
    return 0;     
        Case Wm_syscommand:if (WParam = = sc_close) {postquitmessage (0);/exit     
    return 0;     
Return (INT_PTR) FALSE; }

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.