Click here to Skip to main content
15,881,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'd like to just click the button and have a path set \\myfile.jpg for example

How can I edit this code to get this done instead of "open file dialog" to select it.


void CSampleDlg::OnBnClickedBkopen()
{
UNICODECHAR fn[512];
OPENFILENAME ofn;
UNICODECHAR szFile[512];


ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = this->m_hWnd;
ofn.lpstrFile = szFile;
wcscpy_s(ofn.lpstrFile, 512, L"\0\0");
ofn.nMaxFile = 260;
ofn.lpstrFilter = L"Image Files (bmp,jpg,tif,png,gif,pdf)\0*.bmp;*.jpg;*.tif;*.tiff;*.png;*.gif;*.pdf\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NONETWORKBUTTON | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;// show open file dialog

if (!GetOpenFileName(&ofn)) return;


wcscpy_s(fn, 512, ofn.lpstrFile);

////////
wchar_t str[100];
if (m_cbScale.IsWindowEnabled())
{
if (m_cbScale.GetCurSel() < 1) //autoscaling
{
NsOCR->Cfg_SetOption(CfgObj, BT_DEFAULT, L"ImgAlizer/AutoScale", L"1");
NsOCR->Cfg_SetOption(CfgObj, BT_DEFAULT, L"ImgAlizer/ScaleFactor", L"1.0"); //default scale if cannot detect it automatically
}
else //fixed scaling
{
NsOCR->Cfg_SetOption(CfgObj, BT_DEFAULT, L"ImgAlizer/AutoScale", L"0");
m_cbScale.GetWindowTextW(str, 100);
NsOCR->Cfg_SetOption(CfgObj, BT_DEFAULT, L"ImgAlizer/ScaleFactor", str);
}
}

////
//note: there are other possible ways to load image to NSOCR
int res = NsOCR->Img_LoadFile(ImgObj, fn);
Posted
Comments
Richard MacCutchan 9-May-15 4:07am    
Just remove all the OpenFileDialog code and hard code the file path. Or use some alternate method of allowing the user to select it.

1 solution

Problem is I'm really new to coding and not sure how to do this any example would be much apriciated.
 
Share this answer
 
Comments
Richard MacCutchan 9-May-15 6:30am    

int res = NsOCR->Img_LoadFile(ImgObj, L"MyDirectoryPath\\MyImagFilename.img");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900