好的,所以我需要打開一個.txt文件,該文件將在與程序相同的文件中創建。在C中使用ShellExecute()打開.txt的正確方法是什麼
我想使用ShellExecute();做到這一點,我已經做了大量的研究,我只是無法得到正確的語法主要是因爲我不知道如何處理參數「HWND」
我看了here的答案,並得到了所有除了在HWND
放什麼這裏的信息是我需要使用的代碼:
ShellExecute(0,"open","c:\\debug.txt",NULL,NULL,1);
感謝您的幫助問,如果你不能確定什麼,我說什麼! :)
這是我使用來測試功能的程序:
#include "DAL.h"
//DAL.h added to Testing file to make compiling easier
//Created to test show_debug()
int main(void)
{
int test1,test2,final;
puts("Enter 2 numbers to add (2,2)");
scanf("%d,%d",&test1,&test2);
log_debug(test1);
log_debug(test2);
view_debug();
final= test1+test2;
printf("%d\n",final);
log_debug(final);
return(0);
}
view_debug();是包含ShellExecute的函數
void view_debug(void)//WIP
//Opens the debug.txt in notepad
{
LoadLibrary("shell32.dll");
ShellExecute(0,"open","c:\\debug.txt",NULL,NULL,1);
}
這是log_debug();
int log_debug(int test_variable)
//This function simply tests the programmers desired veriable & displays it for help in keeping track of a veriables value(integer).
//The function has support for upto 1 variable for testing
{
time_t now;
time(&now);
FILE *debug; //Creates file to write debug info
debug=fopen("debug.txt", "a+");
fprintf(debug,"DEBUG %.24s: <%d>\n", ctime(&now),test_variable);
//TODO: Allow more than one variable
fclose(debug);
return(0);
}
該文件由函數log_debug()創建;它確實有效,但必須手動打開,因爲ShellExecute不起作用。
全部來源Here.
在view_debug LoadLibrary調用多餘的,沒有必要,因爲你已經與SHELL32.LIB鏈接。 – selbie