|
That's okay, it's my pleasure.
Each window receives messages from its own controls, so the parent gets WM_NOTIFY and LVN_xxxxxx messages, while the child window gets WM_COMMAND and CBN_xxxxxxx messages.
The key to the scheme is that you need to treat the child window like a custom control, and remember to pass messages from it to it's parent window. You'll need to tell the parent
when something in the child window has happened - e.g a combobox event, you may also wish to send messages from the parent to the child - e.g take this array of strings and add each one to the combobox.
In short, just think of the child window as a control and remember to pass messages between the control and it's parent whenever something needs to be done(e.g fill combo with array of strings), or whenever something has happened (e.g chosen item in combobox has changed)
|
|
|
|
|
I tried to detect which window handle is reporting to WM_CLOSE.
So I set up
if (hwnd == g_hWindow)
{
}
if (hwnd == g_hChildWindow)
{
}
However when I close the child window the message box goes smooth and I call destroy window with the g_hCildWindow passed along the function.
But then my main window gets killed along the way after it.
Even the background color of the child window is messed up.
I did setup the PAINSTRUCT like on the default main window.
But it doesn't seem to kick in. 
|
|
|
|
|
 I still can't help but get the feeling that you're using a single WindowProcedure to handle both the Parent window and the Child window.
As far as I know, you have to use _seperate_ procs for each window. With that in mind, there is no issue when it comes to finding out who generated a message - the message automatically goes to it's own parent. Perhaps I'm missing something?
Here's about the smallest, simplest (& unfortunately perhaps the nastiest) example I can think of at 4:30am
#include <windows.h>
LRESULT CALLBACK childWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK parentWndProc(HWND, UINT, WPARAM, LPARAM);
bool myRegClass(WNDPROC lpfnWndProc, char *szClassName, HINSTANCE hInst);
char *szParentClassName = "parentClass", *szChildClassName = "childClass";
HINSTANCE hThisInstance;
HWND parentWnd;
#define IDC_FROMPARENT 1000
#define IDC_FROMCHILD 1001
int WINAPI WinMain (HINSTANCE hCurInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwndParent;
MSG messages;
hThisInstance = hCurInstance;
if (myRegClass(parentWndProc, szParentClassName, hThisInstance) == false)
return 0;
if (myRegClass(childWndProc, szChildClassName, hThisInstance) == false)
return 0;
parentWnd = CreateWindowEx(
0,
szParentClassName,
"Code::Blocks Template Windows App - parent",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
bool myRegClass(WNDPROC lpfnWndProc, char *szClassName, HINSTANCE hInst)
{
WNDCLASSEX wincl;
wincl.hInstance = hInst;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = lpfnWndProc;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (RegisterClassEx (&wincl))
return true;
else
return false;
}
LRESULT CALLBACK parentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND childWnd, listBox;
switch (message)
{
case WM_CREATE:
childWnd = CreateWindowEx(
0,
szChildClassName,
"Code::Blocks Template Windows App - child",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
544/2,
375/2,
NULL,
NULL,
hThisInstance,
NULL
);
CreateWindowEx(0, "BUTTON", "Msg to Child", WS_VISIBLE | WS_CHILD | WS_TABSTOP | 0x00000001, 8, 8, 150, 23, hwnd, (HMENU)IDOK, hThisInstance, 0);
return 0;
break;
case IDC_FROMCHILD:
MessageBox(NULL, "Child window sent me a message", "Parent", MB_OK);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
PostMessage(childWnd, IDC_FROMPARENT, 0, 0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK childWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
CreateWindowEx(0, "BUTTON", "Msg to Parent", WS_VISIBLE | WS_CHILD | WS_TABSTOP | 0x00000001, 8, 8, 150, 23, hwnd, (HMENU)IDOK, hThisInstance, 0);
return 0;
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
case IDC_FROMPARENT:
MessageBox(NULL, "Parent window sent me a message", "Child", MB_OK);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
PostMessage(parentWnd, IDC_FROMCHILD, 0, 0);
break;
}
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
|
|
|
|
As I see your experienced with Win32 API, what is the effect of hInstance. I usually ignore it and pass it as NULL in CreateWindow, what problems can plague by doing so.
|
|
|
|
|
I've played with it a little over the years. I think I've got vague memories of passing NULL as well, but had forgotten about the trick. It's a perfect time you should ask what may go wrong, as I see there's a thread that asks just the same question right here[^].
|
|
|
|
|
I'm the one asking.
But I still can't understand a thing from the blog, I guess my mind is a bit clouded atm.
|
|
|
|
|
Ah crap!
Guess I should've looked a little closer. :grin:
From what I understand of the blog, this is used as a way of differentiating between different modules (dlls) that are loaded by an app.
Imagine I had an app that loaded 3 dlls, each one of them has an icon in it with the resource ID of 1000, yet each of the icons are entirely different. In order to reliably load the desired resource, you specify the hInstance of the DLL that contains it.
Well, that's my take on it anyway.
|
|
|
|
|
I've run this code in Visual Studio 2010.
I now have a deeper aspect of WS_VISIBLE, instead of having ShowWindow.
And I can understand the buttons and each message passing a message to the other.
It's a new example of Win32 communication taking place.
I'm really thankful for your help.
My program creates a main window and some time along the way I create a second window.
Hopefully that will be through the Win7 JumpList or a Shortcut Key, currently I place the code for triggering this in the message queue to trigger it. The problem was how to start another window, while the parent is running.
Please advise on how to create a new window, while the main window is running.
Although the Win32 documentation is a clear desert, MFC is just an encapsulation of that desert.
I can't figure it out yet, although I have worked with other GUI code.
Native is the way to go, but hard to walk the path if your mapless. 
|
|
|
|
|
|
i'm doing a simple program in socket programming on c i have server that can handle 2clients in a single machine i'm running ubuntu linux so i got it work but the probelm when clients send a message the server will echo it but i cant distinguish which client send the message client 1 or client 2 here is the code for the server whenever a client sent a message it will be shown in the server side as( client sent : hi)i cant know which client sent it please help
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include <arpa/inet.h><br />
#include <sys/types.h><br />
#include <sys/socket.h><br />
<br />
#define BUFFER_SIZE 1024<br />
<br />
int serverfd;<br />
int clientfd;<br />
<br />
int n;<br />
int addrSize;<br />
int serverPort;<br />
char clientIP[25];<br />
char buffer[BUFFER_SIZE];<br />
struct sockaddr_in serverAddr;<br />
struct sockaddr_in clientAddr;<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
if(argc < 2)<br />
{<br />
printf("Usage: ./server <port>\n");<br />
exit(0);<br />
}<br />
else<br />
{<br />
serverPort = atoi(argv[1]);<br />
}<br />
<br />
addrSize = sizeof(struct sockaddr);<br />
<br />
<br />
serverfd = socket(AF_INET, SOCK_STREAM, 0);<br />
<br />
if(serverfd < 0)<br />
printf("Error creating server socket");<br />
serverAddr.sin_family = AF_INET; <br />
serverAddr.sin_port = htons(serverPort); <br />
serverAddr.sin_addr.s_addr = INADDR_ANY; <br />
memset(&(serverAddr.sin_zero), '\0', 8); <br />
<br />
<br />
if(bind(serverfd, (struct sockaddr*)&serverAddr, sizeof(struct sockaddr)) == -1)<br />
printf("Could not bind()\n");<br />
<br />
<br />
if(listen(serverfd, 10) == -1)<br />
printf("Could not listen()\n");<br />
fork();
<br />
clientfd = accept(serverfd, (struct sockaddr*)&clientAddr, &addrSize);<br />
<br />
<br />
snprintf(clientIP, sizeof(clientIP), "%s", inet_ntoa(clientAddr.sin_addr));<br />
printf("Got connection from %s\n", clientIP);<br />
<br />
do<br />
{<br />
n = recv(clientfd, buffer, BUFFER_SIZE, 0); <br />
buffer[n] = '\0'; <br />
<br />
send(clientfd, buffer, BUFFER_SIZE, 0); <br />
printf("Client sent: %s\n" , buffer);<br />
}<br />
while(strncmp(buffer, "exit", 4) != 0); <br />
<br />
close(serverfd); <br />
<br />
return 0;<br />
}
here is the client.c code
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include<br />
<arpa/inet.h><br />
#include<br />
<sys/types.h><br />
#include<br />
<sys/socket.h><br />
<br />
#define<br />
BUFFER_SIZE 1024<br />
<br />
int sockfd;<br />
<br />
int n;<br />
int addrSize;<br />
int serverPort;<br />
char serverIP[25];<br />
char<br />
buffer[BUFFER_SIZE];<br />
struct sockaddr_in serverAddr;<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
if(argc < 3)<br />
{<br />
printf("Usage: ./client <server ip> <server port>\n");<br />
exit(0);<br />
}<br />
else<br />
{<br />
snprintf(serverIP, sizeof(serverIP), "%s", argv[1]);<br />
serverPort = atoi(argv[2]);<br />
}<br />
<br />
addrSize = sizeof(struct sockaddr);<br />
<br />
<br />
sockfd = socket(AF_INET, SOCK_STREAM, 0);<br />
<br />
if(sockfd < 0)<br />
printf("Error creating socket");<br />
<br />
serverAddr.sin_family = AF_INET;<br />
serverAddr.sin_port = htons(serverPort); <br />
inet_pton(AF_INET, serverIP, &serverAddr.sin_addr); <br />
memset(&(serverAddr.sin_zero), '\0', 8); <br />
<br />
<br />
if(connect(sockfd, (struct sockaddr*)&serverAddr, addrSize) != 0)<br />
{<br />
printf("Error: Could not connect to %s on port %d\n", serverIP, serverPort);<br />
exit(0);<br />
}<br />
else<br />
printf("Connected to %s on port %d\n\n", serverIP, serverPort);<br />
<br />
do<br />
{<br />
printf("> ");<br />
fgets(buffer, BUFFER_SIZE, stdin);<br />
send(sockfd, buffer, strlen(buffer), 0); <br />
<br />
n = recv(sockfd, buffer, BUFFER_SIZE, 0); <br />
buffer[n] = '\0'; <br />
printf("< %s\n", buffer);<br />
}<br />
while(strncmp(buffer, "exit", 4) != 0); <br />
<br />
close(sockfd); <br />
<br />
return 0;<br />
}
|
|
|
|
|
One thing you have wrong is in the server. You are only accepting ONE connection before entering the receive loop.
You'll never have more than one client connect because of this.
To handle multiple clients, you should spawn a thread for each client, unless you want to learn asynchrnous socket techniques.
|
|
|
|
|
|
Hi,
I know in regards to DuplicateHandle
kernel objects such as events mutex etc....
are releative to the process
But are the Source process handles and Target process handles unique
meaning the PROCESS_INFORMATION.hProcess param on The CreateProcess or hProcess from OpenProcess
can they be used in any process in a Call to DuplicateHandle
|
|
|
|
|
Hello,
for a little project of mine i need to detect the drive letters of USB devices that will be plugged in to the computer. Because i plan to run this app on a server, i write it as a standard windows service. But it seems that it is impossible to recieve the needed notification in a service application, while it works perfectly in a windowed application (see here[^] for the same problem).
Basically i register for the notifications like described in Receiving Device Event Notification in Windows Service(Detecting Hardware Insertion and/or Removal in Service)[^]. The problem is that with that registration i only get a DBT_DEVTYP_DEVICEINTERFACE data structure passed to my handler function, but i need a DBT_DEVTYP_VOLUME instead to read the drive letter from it (remember, i am writing a service application).
I haven't found a way to get the drive letter from the DBT_DEVTYP_DEVICEINTERFACE::dbcc_name like described in Detecting Hardware Insertion and/or Removal[^]
Or do you have any other approach on how to get drive letters of newly plugged in devices in services?
|
|
|
|
|
How to get the net speed of your computer and how to get the current webpage's speed?
up!Please give me some remarks?Or recommond some libraries...
I am not a genius, but shed more sweat!
|
|
|
|
|
Say what?
Perhaps you should define what it is that you want?
Do you want the inter(net) speed of the computer, or the gross/net speed of the computer?
In either case, what on earth do you mean by speed?
As for "the current webpage's speed"
What?!?
|
|
|
|
|
Hi, From the plugin for Outlook, i am sending data to a web server using IXMLHTTPRequest send method in synchronous mode.
The method crashes the application. The crash does not occur when running from the code.Please help and provide me the steps to move on this.Thanks
|
|
|
|
|
<br />
struct Node<br />
{<br />
int data;<br />
Node *next;<br />
};<br />
typedef struct Node Node;<br />
<br />
Node *Reverse(Node *head);<br />
<br />
Node *Merge(Node *head1, Node *head2)<br />
{<br />
if (head1 == NULL)<br />
return head2;<br />
if (head2 == NULL)<br />
return head1;<br />
<br />
Node *head = NULL;<br />
Node *p1 == NULL;<br />
Node *p2 == NULL;<br />
<br />
if (head1->data > head2->data)<br />
{<br />
head->next = head1;<br />
p1 = head1->next;<br />
p2 = head2;<br />
}<br />
<br />
else<br />
{<br />
head->next = head2;<br />
p1 = head1;<br />
p2 = head2 -> data;<br />
}<br />
<br />
<br />
while (p1!=NULL && p2!=NULL)<br />
{<br />
if (p1->data > p2->data)<br />
{<br />
head->next =p1;<br />
head = p1;<br />
p1 = p1->next;<br />
}<br />
else<br />
{<br />
head -next = p2;<br />
head = p2;<br />
p2 = p2->next;<br />
}<br />
}<br />
<br />
while (p1 != NULL)<br />
{<br />
head->next = p1;<br />
head = p1;<br />
p1 = p2->next;<br />
}<br />
while (p2 != NULL)<br />
{<br />
head -next = p2;<br />
head = p2;<br />
p2 = p2->next;<br />
}<br />
return head;<br />
}<br />
|
|
|
|
|
Hi,
please edit your post and add:
1. PRE tags instead of CODE tags, for better readability;
2. a textual description of your linked lists; e.g. is head supposed to contain any data, or is it only pointing to the first real node?
3. a textual description of what Merge is supposed to do (which must include preconditions: what is assumed about its parameters, and what is promissed about its return value). Without it, the only thing anyone can say is "if it compiles, it will do what it will do".
|
|
|
|
|
Hi there everyone,
So I have my DLL that needs to communicate with my app. What I want to do is have the dll send my CWinApp derived class a message, and then the CWinApp should call DoModal with the dialog. Problem is, I've never messed with the app part of mfc, only the dialog class, so I have no clue how to set up the handler for the message. As well, since there is no hWnd yet, I need to use PostThreadMessage instead of the normal SendMessage , but in my DLL I need to get the return value and then continue processing (like there would be with SendMessage /DefWindowProc ).
Any help on how to do so would be nice. ^^ 
|
|
|
|
|
Sounds like you might have the tail wagging the dog. How is your DLL getting control and "running" to be able to control the application?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
I'm using LoadLibrary/GetProcAddress in the InitInstance of my class.
|
|
|
|
|
And when you get the address of the proc in the DLL, I assume you call it? Are you trying to do some kind of plug and play system where you can have a different window depending on which DLL you load? Why not just have a call into the DLL to create the dialog and then return?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Oh, I should've said this in my first post - I'm injecting this dll into selected processes, so the event that has to trigger a dialog box in my app could or could not happen and I don't know when it will happen.
Hope that helps? 
|
|
|
|
|
Hi,
i am using ShellExecute to launch a url in the default browser, the same code has been working for a few years now.
all of a sudden one guy is complaining that URLs are not working on his 3 PCs
what happens is ShellExecute is called and "If IE8 is running it opens up the site fine but if no IE8 instance is running a new instance comes up, tries to load the page and just keeps loading and nothing happens"
this is very weird cause its tha same old boilerplate code for ShellExecute
Here is the code
HINSTANCE ret = ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWNORMAL);
any ideas are more welcome
thanks for your time
C++ where friends have access to your private members !
|
|
|
|
|