|
Hi
I was wondering if it was possible to create another window in addition to the main window that comes up. It will come up when a menuitem is clicked on the main window. I'm just wondering how I would write the int WINAPI WinMain and LRESULT CALLBACK WndProc when I already have them up because of the original window.
Thanks
Regards
Nitin
|
|
|
|
|
You can use the same WndProc (or as many as you like) for each main (WS_OVERLAPPED) window.
The only thing to be careful of is to not do PostQuitMessage () in response to a WM_DESTROY
in one of the main windows. This is one of the few times that globals come in handy.
You could have a global counter, and set it to 0 in your WinMain.
Then increment in each top level WM_CREATE, and decrement in WM_DESTROY. Just post the
quit message if the counter goes back down to 0.
Or maybe a menu item says "File | Exit All" for example...
Iain.
|
|
|
|
|
Thanks for your quick reply.
But, what would I do about this function and the accelerators?
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TRIAL, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TRIAL);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
Thanks
|
|
|
|
|
Do I just add this function ATOM MyRegisterClass to the winapi main as well? Or do I have to make another ATOM MyREgisterClass(hinst) ?
Thanks
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TRIAL);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)IDC_TRIAL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
|
|
|
|
|
You don't have to make another RegisterClass -like functions unless you need another classes for the windows you create from your application. Just multiplicate the InitInstance call:
for (int i=0; i<number_of_windows; i++)
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} and the message queue:
for (i=0; i<number_of_windows; i++)
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} Leave the PostQuitMessage call untouched; thus the windows will post WM_QUIT messages for number_of_windows times and the application will exit only when the last window will be closed.
rechi
|
|
|
|
|
Thanks rechi
But do I still create both the windows in the same function initInstance? Because I needed the button on the original window to bring up this next window...don't I need to put the create Window function under the case IDC_BUTTON ?
Regards
Nitin
|
|
|
|
|
I'm sorry, i read your first post superficially - the end of the working day is gettin' closer for me
Now, forget what i said and put
LONG lCount=1; as a global variable to keep the number of open windows. Replace the message loop as follows:
LONG lMan=0;
do
{
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
InterlockedDecrement(&lCount);
InterlockedCompareExchange((void **)&lMan, (PVOID)1,
(PVOID)lCount);
} while (!lMan);
and insert:
case IDC_BUTTON:
InitInstance(hInst, SW_SHOW);
InterlockedIncrement(&lCount);
break;
in the window procedure's code. It's best to run it step by step with a breakpoint in the position i mentioned.
Good luck, i'm melting myself towards the offline world now...
rechi
|
|
|
|
|
How do I set the default folder for the CFileDialog ? I thought "must be easy - just set the current directory", but it doesn't seem to use the folder set by ::SetCurrentDirectory()
Thanks in advance!
|
|
|
|
|
You can specify the starting directory in the OPENFILENAME member of you CFileDialog. The OPENFILENAME's member lpstrInitialDir points to the corresponding directory.
|
|
|
|
|
I thought it must be simple, and completely missed that when I looked in the docs for OPENFILENAME. Maybe I put my contact lenses in backwards this morning....
Thanks for your help!
|
|
|
|
|
Martyn Pearson wrote:
Maybe I put my contact lenses in backwards this morning.
Doesn't matter ... CP is THE replacement for your conact lenses;)
|
|
|
|
|
While automating excel in VC++, we get the excel app via an ole dispatch driver, now we open some ExcelWorkbooks using the Open Method of WorkBooks, How Can I make sure that the excel wookbook is invisible.
using the SetVisible property of excel was of no help
|
|
|
|
|
Hello,
Is it possible to create dialogs that are *always* the same size, regardless
of the user's screen DPI? I'm using subclassed dialogs in my program, as
well as other control elements, but when I tried it with large Windows fonts
everything just got screwed up (naturally). I tried using ->SetFont(...),
but that didn't solve anything.
Was anyone successful in finding a solution for this? I know its against
what MS tells us is "good coding practice", but hey, I never promised to be
good (BTW - I'm using VC++ MFC)
Thank you,
Dennis
MCP, MCSD
ASP Developer Member
|
|
|
|
|
I've got a .cpp/.h file combination that implements a particular class; the header file also contains a bool as follows
#if !defined(MYHEADER_H)
#define MYHEADER_H
#pragma once
bool g_bWorkPlease;
#endif // !defined(MYHEADER_H) The intention is that any file that includes myheader.h has access to this global bool, but I don't think I've got it right, 'cause I've got a few files that include myheader, and when I compile I get the link error 2005:
app.obj : error LNK2005: "bool g_bWorkPlease" (?g_bWorkPlease@@3_NA) already defined in ChildFrm.obj<br />
myheader.obj : error LNK2005: "bool g_bWorkPlease" (?g_bWorkPlease@@3_NA) already defined in ChildFrm.obj<br />
MainFrm.obj : error LNK2005: "bool g_bWorkPlease" (?g_bWorkPlease@@3_NA) already defined in ChildFrm.obj<br />
otherfile.obj : error LNK2005: "bool g_bWorkPlease" (?g_bWorkPlease@@3_NA) already defined in ChildFrm.obj<br />
What am I doing wrong? / What's the proper way to define a global variable?
Once this has been sorted out, the class and the bool are being moved to a DLL (MFC extention), is there anything I need to be aware of for this?
Dylan - lossing the plot with a simple global variable!
|
|
|
|
|
|
Hi everybody,
I've asked this question before, and I'M NOW WILLING TO PAY (with PayPal) for a solution that fits my needs because time is not a thing I have in abundance and I need this thing quickly!
Here's, from a user point of view, what I want the resulting solution app to do:
####
When pressing a modifier key (ctrl for example), clicking (right or left mouse) ANY text-based string in ANY application or object (folder names, titles, list items, etc) in the operating system (win95+), a small window should appear next to the clicked-on text informing the user what text he/she has clicked on.
####
Two approaches (as far as I know) are possible: Either you can go the OCR (Optical Character Recognition) way where you actually capture and analyze what the screen pixels look like. An OCR engine is hard to develop yourself and expensive to license or buy. Or you can use the MS Accessibility API to do this... (fairly undocumented but supposed to do the trick). This is an API used for developing apps that for instance can read text on the screen out loud.
Anyone with the appropriate knowledge and skills who want to take this on?
We can discuss the details more privately when a first contact has been established. Thx everybody and thx for a great forum!
/Tommy
|
|
|
|
|
Can mouse hooking, then using WindowFromPoint() and ChildWindowFromPoint() help in what you want?
|
|
|
|
|
How to Rotate the EmfFile With out using SetWorldTransform?
|
|
|
|
|
I want to use the internet explorer inside my application. This works fine:
AtlAxWinInit();
HWND hwndChild=::CreateWindow( "AtlAxWin",
"Shell.Explorer.1",
WS_CHILD|WS_VISIBLE,
0,0,0,0,
hwnd,NULL,
::GetModuleHandle(NULL),
NULL);
IUnknown *pUnk=NULL;
AtlAxGetControl(hwndChild,&pUnk);
CComPtr<IWebBrowser2> spBrowser;
pUnk->QueryInterface(IID_IWebBrowser2,(void**)&spBrowser);
if(spBrowser)
spBrowser->put_Visible(VARIANT_TRUE);
But, I want this to be more abstract. How can I use the interface IDispatch instead.
My attempt to abstract it, returned a DISP_E_UNKNOWNNAME while calling GetIDsOfNames with "Visible" (it IS a member of IWebBrowser2). It has to be something like that...
using: [VISUAL STUDIO 6.0] [WIN98/2]
|
|
|
|
|
Hello all !
I want to compare two bitmaps.I already use GetPixel() to get all pixels of bitmaps but it very very too slow (because i search bitmap in whole page).
i want to use CRC but it seems hard. you know an easy way to use CRC ?
thx in advance
|
|
|
|
|
You want to compare whether two bitmaps are the same? There are enough CRC classes out here on codeproject, and they are very easy to use.
Alternatively, you could try a memcmp on your loaded bitmaps, but I don't know whether this will work.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Gregor S. wrote:
You want to compare whether two bitmaps are the same?
yes exactly !
Gregor S. wrote:
There are enough CRC classes out here on codeproject
I have already find something but it's hard for me, I continue to seek !
thx
|
|
|
|
|
This is a way to do it using membmp() , might be usefull.
HBITMAP hbmp1 = NULL, hbmp2 = NULL;
BITMAP bmp1, bmp2;
.
.
.
.
GetObject(hbmp1, sizeof(BITMAP), &bmp1);
GetObject(hbmp2, sizeof(BITMAP), &bmp2);
if(bmp1.bmBitsPixel != bmp2.bmBitsPixel ||
bmp1.bmHeight != bmp2.bmHeight || bmp1.bmWidth != bmp2.bmWidth)
return 0;
else
{
LPBYTE data1 = (LPBYTE)bmp1.bmBits,
data2 = (LPBYTE)bmp2.bmBits;
DWORD bmWidth = bmp1.bmWidth * (bmp1.bmBitsPixel / 8);
DWORD bmWidthBytes = bmWidth + (4 - bmWidth % 4) * bool(bmWidth % 4);
DWORD bytesize = bmp1.bmHeight * bmWidthBytes;
if(memcmp(data1, data2, bytesize) == 0)
return 1;
}
I tried it with 600x600 bitmaps and worked well and with good performance.
However there is one problem, if the bitmaps are indexed and they have same bits but different color tables, they will still match as there is no comparision between the color tables here.
If you need it, it should be easy using GetDIBColorTable() function then comparing the two color tables' arrays before comparing the bits.
If you are using VC++.Net and CImage class the whole thing will be much easier.
|
|
|
|
|
ok thank you for your answer !!
i'm going to try and understand your code.
i hope it is fast, because i will compare a lot of bitmap
MAAK wrote:
However there is one problem, if the bitmaps are indexed and they have same bits but different color tables, they will still match as there is no comparision between the color tables here.
all my image will have same nbr of bit, i think i will have to use
GetDIBColorTable()
thx !
I keeps you informed
|
|
|
|
|
Just to ensure there is no confusion. The bits I mean are the values of pixels, sorry for that term, but it's used in the BITMAP structure.
What I do mean, that if you are comparing images with true colors (24-bit color depth or more) there will be no problem, but for indexed images(16-bit, 8-bit etc) the problem of color table arise.
If all pixel values match in an indexed bitmaps that does not mean their color tables match.
I just wanted to be clearer.
|
|
|
|
|