简体   繁体   中英

How to place a control (say, a button) in the main window mannually using .rc resource script

Firstly, I am trying to create GUI using pure C++ text. Since my application does not need complex GUI, I want to avoid Visual Studio.

So I have the following code in my .rc file:

#include "resource.h"

IDR_MYMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
    END
END

EDITTEXT IDC_BY,25,7,25,25,ES_NUMBER

IDI_MYICON ICON "one.ico"

The compiler shows syntax error at the EDITTEXT line. I have the idea that this EDITTEXT should be placed under something, such as a menu, instead of directly in the .rc file. I have read somewhere saying the only way to place a control in a window is to place the control in a dialog box which is then placed in the window. However, from my research, I got the idea that a dialog box is a "new pop-up window" rather than part of the original window. I hope I have explained it well. Thanks in advance for the help.

EDITTEXT statement should appear inside of dialog resource block, for details see Resource file reference documentation . You may want to use dialog from default win32 application as a starting point for writing your own resource file.

IDD_ABOUTBOX DIALOGEX 0, 0, 170, 62
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Win32Project2"
FONT 8, "MS Shell Dlg"
BEGIN
    ICON            IDR_MAINFRAME,IDC_STATIC,14,14,21,20
    LTEXT           "Win32Project2, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX
    LTEXT           "Copyright (C) 2017",IDC_STATIC,42,26,114,8
    DEFPUSHBUTTON   "OK",IDOK,113,41,50,14,WS_GROUP
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM