gpt4 book ai didi

c - 使用自定义模板显示 GetOpenFileName 函数

转载 作者:行者123 更新时间:2023-11-30 17:07:22 26 4
gpt4 key购买 nike

当我尝试向“打开文件”对话框添加一些自定义控件时遇到问题。我使用了如下所示的资源文件,但它不起作用。我认为某个地方有错误,但我无法纠正它。如何在“打开文件”对话框上显示自定义控件?

程序.c

#include "resource.h"

int WINAPI WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow )
{
OPENFILENAME ofn;
CHAR szFile[50];

ZeroMemory( &ofn , sizeof(ofn));

ofn.lStructSize = sizeof ( ofn );
ofn.hwndOwner = NULL;
ofn.hInstance = hInstance;
ofn.lpstrFile = szFile ;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.txt\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir = NULL ;
ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = MAKEINTRESOURCE( MY_DIALOG );

GetOpenFileName( &ofn );

return 0;
}

对话框.rc

#include "resource.h"

MY_DIALOG DIALOG 0, 0, 260, 30
STYLE WS_CHILD | WS_CAPTION
CAPTION "My Dialog"
FONT 8, "MS Sans Serif"
{
CONTROL "", 1119, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 0, 0, 265, 10
CONTROL "Items:", 3221, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 13, 45, 9
CONTROL "", 3202, "COMBOBOX", CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 54, 11, 218, 63
CONTROL "Current index:", 3221, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 31, 45, 9
CONTROL "", 3203, "COMBOBOX", CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 54, 29, 204, 63
CONTROL "...", 3204, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 260, 29, 12, 12
}

资源.h

#ifndef RESOURCE_H
#define RESOURCE_H

#include <windows.h>
#define MY_DIALOG 120

#endif //RESOURCE_H

生成文件

build:
windres -i dialog.rc -o dialog.o
gcc -c program.c -o program.o
gcc -o program.exe dialog.o program.o -lcomdlg32 -lgdi32

最佳答案

另添加OFN_ENABLEHOOK到旗帜。请注意,这种在比 XP 更新的 Windows 版本上看起来很难看。使用CHAR szFile[MAX_PATH]; – 巴尔马克·谢米拉尼

关于c - 使用自定义模板显示 GetOpenFileName 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com