/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
BN_CLICKED
Fra : Poul S. Sørensen


Dato : 14-03-05 19:48

Hej NG

Jeg har en win32 application i VC6, som jeg forsøger at kode ved hjælp af
native Windows functioner. Jeg forsøger at fange BN_CLICKED message i
MainWndProc, men hvordan ved jeg hvilken knap er der blevet trykket på? I
MSDN står der at :

"The BN_CLICKED notification message is sent when the user clicks a button.
The parent window of the button receives this notification message through
the WM_COMMAND message. "

Og jeg forsøger følgende:

LRESULT APIENTRY MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{

switch (message) {


case WM_COMMAND:
switch (LOWORD(wParam)) {

case BN_CLICKED :
switch (LOWORD(wParam)) {

case 0:
MessageBox(hwnd,"Button 1 Clicked", "",0);
break;

case 1:
MessageBox(hwnd,"Button 2 Clicked", "",0);
return 0;
}
return 0;

} /* end switch */
break; /* end wm_command */




Men case 0 er konsekvensen, uanset hvilken knap jeg trykker på.. Hvordan
opstiller man dette korrekt?

--
Med Venlig Hilsen
Poul S. Sørensen



 
 
Bertel Brander (14-03-2005)
Kommentar
Fra : Bertel Brander


Dato : 14-03-05 20:29

Poul S. Sørensen wrote:
> Hej NG
>
> Jeg har en win32 application i VC6, som jeg forsøger at kode ved hjælp af
> native Windows functioner. Jeg forsøger at fange BN_CLICKED message i
> MainWndProc, men hvordan ved jeg hvilken knap er der blevet trykket på? I
> MSDN står der at :
>
> "The BN_CLICKED notification message is sent when the user clicks a button.
> The parent window of the button receives this notification message through
> the WM_COMMAND message. "
>
> Og jeg forsøger følgende:
>
> LRESULT APIENTRY MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
> lParam)
> {
>
> switch (message) {
>
>
> case WM_COMMAND:
> switch (LOWORD(wParam)) {
>
> case BN_CLICKED :
> switch (LOWORD(wParam)) {


Skal det ikke være HIWORD der skal være BN_CLICKED og LOWORD
der er ID'en ?

Hvordan er knapperne oprettet?


--
Absolutely not the best homepage on the net:
http://home20.inet.tele.dk/midgaard
But it's mine - Bertel

Poul S. Sørensen (14-03-2005)
Kommentar
Fra : Poul S. Sørensen


Dato : 14-03-05 20:44

> Hvordan er knapperne oprettet?


\**************************************************************************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
HWND hwnd;
static HWND hwndButton;
static HWND hwndButton2;

// ... vinduet oprettes her:
hwnd = CreateWindow( ... osv.

// og her - knapperne:

hwndButton = CreateWindow(
"BUTTON", // predefined class
"Connect", // button text
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
// Size and position values are given explicitly, because
// the CW_USEDEFAULT constant gives zero values for buttons.
10, // starting x position
10, // starting y position
100, // button width
40, // button height
hwnd, // parent window
NULL, // no menu
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // pointer not needed


hwndButton2 = CreateWindow(
"BUTTON", // predefined class
"Shut Down", // button text
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
// Size and position values are given explicitly, because
// the CW_USEDEFAULT constant gives zero values for buttons.
120, // starting x position
10, // starting y position
100, // button width
40, // button height
hwnd, // parent window
NULL,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // pointer not needed

Jeg går ud fra at den rækkefølge som knapperne bliver oprettet i er det som
bestemmer LOWORD(wParam).



Bertel Brander (14-03-2005)
Kommentar
Fra : Bertel Brander


Dato : 14-03-05 20:50

Poul S. Sørensen wrote:
>
> hwndButton = CreateWindow(
> "BUTTON", // predefined class
> "Connect", // button text
> WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
> // Size and position values are given explicitly, because
> // the CW_USEDEFAULT constant gives zero values for buttons.
> 10, // starting x position
> 10, // starting y position
> 100, // button width
> 40, // button height
> hwnd, // parent window
> NULL, // no menu
> (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
> NULL); // pointer not needed
>

NULL, // no menu
Skal erstattes med ID'en på knapperne:
(HMENU )123,

Ellers får de id 0.

--
Absolutely not the best homepage on the net:
http://home20.inet.tele.dk/midgaard
But it's mine - Bertel

Poul S. Sørensen (14-03-2005)
Kommentar
Fra : Poul S. Sørensen


Dato : 14-03-05 21:14


> NULL, // no menu
> Skal erstattes med ID'en på knapperne:
> (HMENU )123,
>
> Ellers får de id 0.

Ja ok, jeg troede ellers at HMENU er en handle til en menu.item..
Men tak for hjælpen!

Mvh.
Poul



Bertel Brander (14-03-2005)
Kommentar
Fra : Bertel Brander


Dato : 14-03-05 21:33

Poul S. Sørensen wrote:
>> NULL, // no menu
>>Skal erstattes med ID'en på knapperne:
>> (HMENU )123,
>>
>>Ellers får de id 0.
>
>
> Ja ok, jeg troede ellers at HMENU er en handle til en menu.item..
> Men tak for hjælpen!
>

Om HMENU parametren skriver MSDN:

"[in] Handle to a menu, or specifies a child-window identifier depending
on the window style. For an overlapped or pop-up window, hMenu
identifies the menu to be used with the window; it can be NULL if the
class menu is to be used. For a child window, hMenu specifies the
child-window identifier, an integer value used by a dialog box control
to notify its parent about events. The application determines the
child-window identifier; it must be unique for all child windows with
the same parent window."

Et godt eksempel på at parametre i mange funktions kald bliver
brugt til noget andet end det man lige tror i windows porgrammering.

--
Absolutely not the best homepage on the net:
http://home20.inet.tele.dk/midgaard
But it's mine - Bertel

Søg
Reklame
Statistik
Spørgsmål : 177438
Tips : 31962
Nyheder : 719565
Indlæg : 6408046
Brugere : 218879

Månedens bedste
Årets bedste
Sidste års bedste