|
Hi all,
i m using SDI application,
i m using worker thread for loading records in ListControl.
here i m using a modeless dialog box ,i create and display the modeless dialog before Starting the thread and hide it at end of thread.
I m start thread at OnInitialUpdate function of Formview.
my problem is that when modelss dialog box hide now the main window lost the focus.
i m use SetFocus function but its not working.
void CFormView::OnInitialUpdate()
{
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
if(Main_View->m_pmodeless)
{
m_pmodeless->SetForegroundWindow();
m_pmodeless->ShowWindow(SW_SHOW);
pMainFrame->EnableWindow(0);
m_pmodeless->EnableWindow(0);
}
else
{
m_pmodeless = new CModeless_dlg
m_pmodeless->Create(CModeless_dlg::IDD,0);
m_pmodeless->ShowWindow(SW_SHOW);
pMainFrame->EnableWindow(0);
m_pmodeless->EnableWindow(0);
}
AfxBeginThread(Initial_Thread,NULL,THREAD_PRIORITY_HIGHEST,0,0,NULL);
}
m_pmodeless->ShowWindow(SW_HIDE);
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
pMainFrame->EnableWindow(1);
pMainFrame->SetFocus();
please tell me how can i setfocus on main window of sdi.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
"_$h@nky_" wrote: i m using worker thread for loading records in ListControl.
That's probably a bad idea to start with - you should only access windows from a UI thread, unless you're posting messages to the window from hte non-UI thread.
And that's also the basic reason why the SetFocus in the thread function isn't effective - as the documentation[^] says:
The window must be attached to the calling thread's message queue
Try posting a custom message to the main window at the end of the thread, indicating that the thread is finished. The main frame can handle that by dismissing the progress dialog and retrieving the focus.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Which is the right way to do and why?
TCHAR *gClassName = 0;
bool CreateCabinetMainWindow(const TCHAR* classname)
{
DeleteCabinetMainWindow( );
gClassName = (TCHAR*)classname;
}
OR
const TCHAR *gClassName = 0;
bool CreateCabinetMainWindow(const TCHAR* classname)
{
DeleteCabinetMainWindow( );
gClassName = classname;
}
Thanks in advance,
Nandu
|
|
|
|
|
Second option makes more sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Second one. If you're declaring gClassName as mutable, then assigning an immutable string pointer to it is a bad idea. If you try to write to gClassName, then you could easily get an access violation if you'd called CreateCabinetMainWindow like this:
if (CreateCabinetMainWindow(_T("MyClass"))) { .... };
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
I have an EXE file and i want to list all the strings from the String Table of the EXE
The exe is the compiled CPP file like the one present in the Debug folder
How do i display all the strings that are present??
|
|
|
|
|
If it's just the string table you're after, load the exe into Visual Studio - you can view its resources there.
Otherwise, a nice utility called strings[^] will show you all the strings embedded in an executable.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Actually we have to write our code which will take an EXE as input and display all the strings present in that EXE.
What are the ways to do that?
|
|
|
|
|
If it's string tables in the resources, then EnumResourceNames[^] can tell you all the string tables present in a module, FindResource[^] can get you handles for those resources, which you can then access using LoadResource[^] and LockResource[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply
The documentation of MSDN about FindResource is not that clear,so am having problem in that.
What is the parameter lpName ([in] Specifies the name of the resource) ?
|
|
|
|
|
It's what EnumResourceNames(Ex) gives you as a parameter when calling the function you specify via the ENUMRESNAMEPROC function pointer parameter.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
But ENUMRESNAMEPROC also requires lpName. what is that?
|
|
|
|
|
Noooo - when you call EnumResourceNames, it'll call the function you specify once for each name it finds. It will pass in the name it's just found, allowing you to store it somewhere or process it:
typedef std::vector<CString> Names;
BOOL CALLBACK GatherNames(
HMODULE hModule,
LPCTSTR lpszType,
LPTSTR lpszName,
LONG_PTR lParam)
{
Names* pNames = reinterpret_cast<Names*>(lParam);
pNames->push_back(CString(lpszName));
return TRUE;
}
void GetStringResourceNames(HMODULE module)
{
Names names;
EnumResourceNames(module, RT_STRING, GetherNames, reinterpret_cast<LONG_PTR>(&names));
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
This is the code we are using till now. Where are we going wrong?
#include "stdafx.h"
#include "windows.h"
#include "tchar.h"
#include "stdio.h"
#include "string.h"
BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param);
char buffer[200];
int _tmain(int argc, _TCHAR* argv[])
{DWORD S;
LPCTSTR RT_String=NULL;
LONG_PTR aux_param=NULL;
BOOL q,r;
HMODULE some_library = LoadLibrary("C:/Hi/Debug/Hi.exe");
q= MyStringCB(some_library,RT_String,buffer,aux_param);
r=EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param);
S=GetLastError();
return 0;
}
BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param)
{ DWORD startId = ((DWORD)buffer - 1) * 16;
DWORD i, endId = startId + 16;
for (i = startId ; i < endId; ++i)
{ LoadString(some_library, i,buffer,sizeof(buffer));
}
return TRUE;
}
|
|
|
|
|
Why didn't you take any notice of this answer[^] to one of your previous questions? His answer was completely accurate.
Here's what your MyStringCB should look like:
BOOL CALLBACK MyStringCB(HMODULE some_library, LPCTSTR resourceType, LPTSTR stringName, LONG_PTR aux_param)
{
_ASSERTE(resourceType == RT_STRING);
static TCHAR stringValue[2048];
UINT id;
if (IS_INTRESOURCE(stringName))
id = (UINT)stringName;
else if (_T('#') == stringName[0])
id = _tcstoul(stringName+1, 0, 10);
else
return TRUE;
DWORD startId = ((DWORD)id - 1) * 16;
DWORD i, endId = startId + 16;
for (i = startId ; i < endId; ++i)
{
std::fill_n(stringValue, 2048, (TCHAR)0);
LoadString(some_library, i, stringValue, 2048);
if (_tcslen(stringValue) > 0)
{
}
}
return TRUE;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I want to fire a non blocking message box so that it will not interupt the code below it . and I click OK on it with some message
Trioum
|
|
|
|
|
In that case, you need to make yourself a modeless dialog box[^] on which you can put your message.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hmmm, this might work.
DWORD dwID =0;
MSGBOXPARAMS msg = {0};
msg.cbSize = sizeof(MSGBOXPARAMS);
msg.hwndOwner = this->m_hWnd;
msg.hInstance = GetModuleHandle(NULL);
msg.lpszText = _T("Blocking is for bullies.");
msg.lpszCaption = _T("Non-blocking");
msg.dwStyle = MB_OK | MB_SETFOREGROUND;
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)MessageBoxIndirect,&msg,0,&dwID);
Make sure not to create the MSGBOXPARAMS on the stack you probably want it to be persistent. You might be able to check if the user has clicked the OK button by checking GetExitCodeThread Function[^] for STILL_ACTIVE.
Let me know if it works.
Best Wishes,
-David Delaune
|
|
|
|
|
How Could we make a field or fields of database primary key for that database using Dao Database?
CDaoTableDef tableDef(&m_db);
tableDef.Create(m_tableName.c_str());
tableDef.CreateField(m_field1.c_str(),dbText,1,dbFixedField);
tableDef.CreateField(m_field2.c_str(),dbText,255,dbVariableField);
tableDef.Append();
tableDef.Close();
I want to make my secound field primary key in my database.
|
|
|
|
|
I think you need to use the CreateIndex[^] method. The CDaoIndexInfo structure[^] lets you specify that an index is primary (i.e. the primary key) or foreign (foreign key).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi everyone,
I have a modal dialog box which is called by the main thread. This dialog has no parent (appears at center screen, overlapped, and shown in taskbar). When the user clicks "Save" in the dialog, the dialog procedure receives the command and displays a save file dialog (GetSaveFileName).
The problem is that the second dialog (Save Dialog) doesn't work at all. It can't be activated, and seems kind of frozen (can't be closed, buttons and scroll bars are frozen). Here's my code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
DialogBox(hInstance, MAKEINTRESOURCE(101), NULL, DialogProc);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc; PAINTSTRUCT ps;
switch (message) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDSAVE:
OPENFILENAME OFN;
OFN.hwndOwner = hWnd;
[...]
if (GetSaveFileName(&OFN)) {[...]}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return true;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_INITDIALOG:
[...]
return true;
case WM_CLOSE:
[...]
return true;
case WM_DESTROY:
[...]
return true;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return false;
}
Whatever dialog type I put at this line (print dialog, modal dialog, modeless dialog), it doesn't behave properly. What am I missing?
I tried with OFN.hwndOwner = NULL, but doesn't work.
Thanks in advance!
|
|
|
|
|
The problem may well be in the [...] stuff.
I know the OPENFILENAME struct has lots of members - some refer to hooks, and instances of replacement dialog templates, etc.
At the very least, put in a
memset(&ofn, 0, sizeof(ofn));
line! (Parameters from memory. If you do not check them, you may lose your home, etc).
Also, pretty critically, there's a lStructSize member of ofn too! I suspect this needs filling in.
Good luck,
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
No it is not! The problem does not lie within the save file dialog, but rather within the dialog procedure and/or API calls. If I replace the save file dialog part with a print dialog or even a new modal or modeless dialog, the problem still occurs. The second dialog shows itself but is unusable.
Thanks for your reply though
|
|
|
|
|
Problem solved. The problem was within the procedure. Replaced "return DefWindowProc(hWnd, message, wParam, lParam)" by "return false". return DefWindowProc is for main windows, not dialogs.
|
|
|
|
|