Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Programmazione C/C++ Problema con le finestre winapi

17 views
Skip to first unread message

Nero23

unread,
Jan 11, 2014, 5:15:51 PM1/11/14
to
Sistema operativo Windows 8 a 64 Bit Linguaggio di programmazione C/C++.

Con Codeblocks non riesco a visualizzare una finestra con le api di
windows se queste sono realizzate utilizzando il file .RC (in poche
parole, i Dialod boxes).

Nessun problema se creo la finestra utilizzando la classica funzione
CreateWindowEx...


Sapete darmi una dritta?

Grazie

nero23


Riporto il codice....




// FILE main.c
#include <windows.h>
#include "resource.h"

BOOL CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY: PostQuitMessage(0);
return TRUE;
case WM_CLOSE:
DestroyWindow (hwnd);
return TRUE;
}

return FALSE;
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *
cmdParam, int cmdShow)
{
HWND handle = 0;
handle = CreateDialog (hInst, MAKEINTRESOURCE (IDD_DIALOG1), 0,
(DLGPROC)DialogProc);

if (!handle)
{
MessageBox(NULL, "Dialog Box", "Errore!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(handle, cmdShow);
UpdateWindow(handle);

MSG message;
while(GetMessage(&message, NULL, 0, 0) > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}

return message.wParam;
}






// FILE resource.h
#define IDD_DIALOG1 101
#define IDC_BUTTON1 1007
#define IDC_BUTTON2 1008
#define IDC_BUTTON3 1009







// FILE fileRC.rc
#include "resource.h"
#include "afxres.h"


IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 100, 100

STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
BEGIN
PUSHBUTTON "Pulsante 1",IDC_BUTTON1 ,10,10,40,20
PUSHBUTTON "Pulsante 2",IDC_BUTTON2 ,10,30,40,20
PUSHBUTTON "Pulsante 3",IDC_BUTTON3 ,10,50,40,20
END

xnoise

unread,
Jan 13, 2014, 1:53:14 PM1/13/14
to
Il 11/01/2014 23:15, Nero23 ha scritto:> Con Codeblocks non riesco a
visualizzare una finestra con le api di
> windows se queste sono realizzate utilizzando il file .RC (in poche
> parole, i Dialod boxes).

Il codice mi sembra corretto. Bisognerebbe dare un'occhiata al file RC.
Hai provato a vedere se l'handle ritornato dalla CreateDialog e' valido ?

acc

unread,
Jan 13, 2014, 5:36:48 PM1/13/14
to
Il 11/01/2014 23.15, Nero23 ha scritto:

Aggiunto/tolto qualcosina, ma ci credo poco, penso piu' ad un problema
di CodeBlocks (che non ho). Con VS2008 funziona.

> // FILE main.c
> #include <windows.h>
> #include "resource.h"
>
> BOOL CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
> switch (msg) {

case WM_INITDIALOG: return TRUE;

> case WM_DESTROY: PostQuitMessage(0); return TRUE;
> case WM_CLOSE: DestroyWindow (hwnd); return TRUE;
> }
> return FALSE;
> }
>
> int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char* cmdParam, int cmdShow) {
> HWND hDlg = CreateDialog(hInst, MAKEINTRESOURCE (IDD_DIALOG1), 0, (DLGPROC)DialogProc);
>
> if (! hDlg) {
> MessageBox(NULL, "Dialog Box", "Errore!", MB_ICONEXCLAMATION | MB_OK);
> return 0;
> }
>
> ShowWindow(hDlg, cmdShow);

UpdateWindow(hDlg); // <- serve? uhm... no, toglilo.

> MSG message;
> while (GetMessage(&message, NULL, 0, 0) > 0) {

if (! IsDialogMessage(hDlg,&msg)) {

> TranslateMessage(&message);
> DispatchMessage(&message);

}

> }
>
> return message.wParam;
> }
>
>
>
>
>
>
> // FILE resource.h
> #define IDD_DIALOG1 101
> #define IDC_BUTTON1 1007
> #define IDC_BUTTON2 1008
> #define IDC_BUTTON3 1009
>
>
>
>
>
>
>
> // FILE fileRC.rc
> #include "resource.h"

#include "afxres.h" // <- sicuro che sia ok?
// prova a sostituirlo con #include <windows.h>
// dovrebbe bastare

>
>
> IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 100, 100
> STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU

// uh WS_CAPTION ?
CAPTION "E metticelo allora!"

xnoise

unread,
Jan 14, 2014, 3:37:59 AM1/14/14
to
Il 11/01/2014 23:15, Nero23 ha scritto:
>
>***** ShowWindow(handle, cmdShow);
>***** UpdateWindow(handle);
>
> IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 100, 100
>
> STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU ****|WS_VISIBLE****
> BEGIN
> PUSHBUTTON "Pulsante 1",IDC_BUTTON1 ,10,10,40,20
> PUSHBUTTON "Pulsante 2",IDC_BUTTON2 ,10,30,40,20
> PUSHBUTTON "Pulsante 3",IDC_BUTTON3 ,10,50,40,20
> END
>

Elimina le chiamate a ShowWindow e UpdateWindow ed inserisci il flag
VS_VISIBLE nello stile della finestra.
0 new messages