Bonjour à tous (et bonne année),

Comme écrit dans l'intitulé, j'utilise l'API win32 EXCLUSIVEMENT pour créer mon appli (pas de MFC).

Mon problème est de créer une boite de dialogue, puis d'y insérer un nouveau composant, c'est à dire un HWND qui ferait appel à une nouvelle classe WNDCLASS possédant sa propre callback.

J'ai donc deux callback, l'une pour la boite de dialogue et l'autre pour mon nouveau code. J'ai donc écrit le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "resource.h"
#include <windows.h>

HINSTANCE hinst;

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static HWND dArea = 0;
	RECT rect;
	char str[256];

	switch (uMsg)
	{
	case WM_INITDIALOG:

		dArea = CreateWindowEx(WS_EX_CLIENTEDGE,"dArea","Texte",
			WS_CHILD | WS_VISIBLE,
			0, 0, 0, 100, hwnd, NULL, hinst, NULL);
		break;
	case WM_SIZE:
		MoveWindow(dArea, 5, 5, LOWORD(lParam)-10, HIWORD(lParam)-100, TRUE);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	}
	return FALSE;
}

LRESULT CALLBACK dAreaProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_CREATE:
		break;
	case WM_PAINT:
		break;
	default:
		return TRUE;//DefWindowProc(hwnd,uMsg,wParam,lParam);
	}
	return TRUE;
	//return DefWindowProc(hwnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
	HWND hwnd;
	MSG msg;
	WNDCLASS wc,wc2;

	hinst = hinstance;

	wc2.style = 0 ;
	wc2.lpfnWndProc = dAreaProc;
	wc2.cbClsExtra = 0;
	wc2.cbWndExtra = 0;
	wc2.hInstance = hinstance;
	wc2.hIcon = NULL;
	wc2.hCursor = LoadCursor(NULL, IDC_CROSS);
	wc2.hbrBackground = (HBRUSH)(COLOR_ACTIVECAPTION);
	wc2.lpszMenuName =  NULL;
	wc2.lpszClassName = "dArea";

	if(!RegisterClass(&wc2)) return FALSE;

	hwnd = CreateDialogA(hinstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)MainWndProc);

	if (!hwnd)  return FALSE;

	ShowWindow(hwnd, nCmdShow);

	hwnd = GetWindow(hwnd,GW_CHILD);
	while(1)
	{
		const char str[256];
	}

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
avec le fichier resource "test.rc" qui va bien :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Generated by ResEdit 1.4.4.13
// Copyright (C) 2006-2008
// http://www.resedit.net

#include "resource.h"
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>


//
// Dialog resources
//
IDD_DIALOG1 DIALOG 0, 0, 275, 222
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg 2"
BEGIN
    DEFPUSHBUTTON   "OK", IDOK, 220, 203, 50, 14
    PUSHBUTTON      "Cancel", IDCANCEL, 165, 203, 50, 14
    PUSHBUTTON      "Load...", IDC_BUTTON1, 220, 184, 50, 14
    EDITTEXT        IDC_EDIT1, 5, 184, 210, 14, ES_AUTOHSCROLL
    CONTROL         "", IDC_SLIDER1, TRACKBAR_CLASS, WS_TABSTOP | TBS_BOTH | TBS_NOTICKS, 5, 133, 210, 15
END
et le header "resource.h" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDD_DIALOG1                             100
#define IDC_SLIDER1                             1000
#define IDC_BUTTON1                             1001
#define IDC_EDIT1                               1002
#define IDC_CUSTOM1                             1003
Seulement voilà, ma boite de dialogue n'affiche pas mon nouveau composant et le programme entre dans une boucle infinie, c'est très décevant...

Je pense que le problème vient de la callback de la dlg qui renvoie TRUE quand elle devrait renvoyer FALSE ou l'inverse, mais je ne suis pas bien sûr de moi... J'ai essayé différentes configuration de TRUE ou FALSE dans mon switch(uMsg), mais je n'obtiens pas de meilleurs résultats.

Voilà, donc si quelqu'un peut me dire comment je dois m'y prendre je serai très reconnaissant.

En vous remerciant.