GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-May-2009, 13:59
jyc jyc is offline
New Member
 
Join Date: May 2009
Posts: 7
jyc is on a distinguished road

Finding DialogBox handle...


Hello there,

I'm new here ! Hello! I'm a student currenlty working on a project (Very rushed) in C++ (i only had JAVA and command-line C programming experience..) Excuse me if the following question sounds trivial, I really need URGENT HELP! Many thanks in advance.

The only window created in my program uses DialogBoxIndirectParam. Is there anyway I can point the WSAAsyncSelect method to send messages to the DialogBox? Following are snippets of the code:

CPP / C++ / C Code:
	DialogBoxIndirectParam (GetModuleHandle (0), &t, 0, (DLGPROC)EditorProc, (LPARAM)effect);
	WSAAsyncSelect (ListenSocket, FindWindow(NULL, "Editor") , 1000, (FD_ACCEPT | FD_CONNECT | FD_READ | FD_CLOSE));

And the CALLBACK method:

CPP / C++ / C Code:
INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)


Basically, I want EditorProc to handle both the dialog loop and the Sockets..is it possible?

Many thanks!

Jyc.
  #2  
Old 04-May-2009, 19:36
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: Finding DialogBox handle...


This is easier than it sounds. In your WM_INITDIALOG, you simply use the dwInitParam (that you're not currently using) to pass the "hwndDlg" member of the DialogProc...

CPP / C++ / C Code:
INT_PTR CALLBACK DialogProc(          HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
);

Here's the general idea. Create a static variable:

CPP / C++ / C Code:
static DWORD* hDlg = NULL;

...in your DialogBoxIndirectParam call you PASS THE PARAM (note the "Param" part of the function name?) to it.

CPP / C++ / C Code:

...(LPARAM)hDlg);


...in your WM_INITDIALOG message you:

CPP / C++ / C Code:

....case WM_INITDIALOG:
         hDlg = (DWORD)hwndDlg;
         ...
         break;


--OR--

CPP / C++ / C Code:
....case WM_INITDIALOG:
         (*(DWORD*)(lParam)) = (DWORD)hwndDlg;
         ...
         break;


And, then, when you need to use it, you cast it to the appropriate type and use it.

CPP / C++ / C Code:
HWND hwnd = (HWND)hDlg;
GetDialogItem(hDlg, ...);


...or something like that. "Qualifier" I wrote this from my MacBook without a Windows box around.


Consider this stupid simple example as an example of using casting for the types that you will likely see as opaque pointers in Win32 code.

CPP / C++ / C Code:
#include <windows.h>
#include <stdio.h>

static DWORD* hDlg = NULL;

void bogus()
{
    printf("bogus\n");
}

int main()
{
    hDlg = (DWORD*)&bogus;
    ((void (*)(void))hDlg)();
    return 0;
}


MxB
  #3  
Old 05-May-2009, 05:21
jyc jyc is offline
New Member
 
Join Date: May 2009
Posts: 7
jyc is on a distinguished road

Re: Finding DialogBox handle...


many thanks!
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Joystick handle cgillopez .NET Forum 0 23-Mar-2009 12:23
How to get a handle to a derived class? Futterama MS Visual C++ / MFC Forum 1 29-Jan-2007 10:47
ARG! Dialogbox of doom! The_Inferno C++ Forum 2 12-Mar-2006 17:44
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
What is a Handle in Device Context Janakiraman MS Visual C++ / MFC Forum 1 12-May-2005 05:09

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:51.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.