Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > SetDlgItemText() Error

Reply
Thread Tools

SetDlgItemText() Error

 
 
Xzyx987X
Guest
Posts: n/a
 
      07-24-2003
Sorry if this is off topic for this group, but I couln't find any place
better for directing question on Windows API programming. Here's the
problem, I am calling the SetDlgItemText() function to set the text of an
edit box for an about window for my program. For some weird reason though it
won't work, and the GetLastError function gives a Control ID not found
error. I am sure that the parameters are correct so I'm at a loss as to the
cause. The only reason I can think of that this would happen is that the
about window is set as a child window of the main one, but I don't see why
that would be a problem. To be honest I would rather just send the edit box
a set text message but the object is being genorated by a recource script
and I'm not sure how to get it's hWnd. If you know how then please tell me.
Another question I wanted to ask, just in case anyone knows, when using the
CreateWindowEx() function one of the parameters is a handle to the
application instance. The way I have the application set up though, it is a
command line program that makes use of windows.h (the command line is really
handy for debbuging) so I can't get this from the winmain function. Having
this parameter NULL causes no problems in WinXP, but according to MSDN it
may break compatiblility with Win98 and below. Then again they are probobly
assuming the application has a winmain, which it doesn't. Does anyone know
if this would actually be a problem, and if so how would I get the handle to
the application instance without having a winmain?

Here's the source (stripped of any sort of practical functionallity):

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

//Function declarations

BOOL MainDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);

BOOL AboutDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);

void initialize_proc(HWND hWnd);

//Global variable declarations

HWND hWstatusbar;

//Main function. Serves as entry point for MainDialogProc

bool main(void)
{
DialogBoxParam(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_MAIN),
NULL,
(DLGPROC)MainDialogProc,
0);

return FALSE;
}

BOOL MainDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{

switch(uMsg)
{

case 48: //Didn't feel like looking up the constant for this
initialize_proc(hWnd);
return TRUE;
break;

case WM_CLOSE:
EndDialog(hWnd, 0);
return TRUE;
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{

case ID_HELP_ABOUT:
DialogBoxParam(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_ABOUT),
hWnd,
(DLGPROC)AboutDialogProc,
0);
break;
case ID_FILE_EXIT:
EndDialog(hWnd, 0);
return TRUE;

}

}

return FALSE;

}

BOOL AboutDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{

switch (uMsg)
{
case 48:
SetDlgItemText(hWnd, IDC_DISCLAIMER, "About Box.");
printf("Last Error: %d \n", GetLastError());
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{

case IDOK:
EndDialog(hWnd, 0);
return TRUE;

}

}

return FALSE;

}

void initialize_proc(HWND hWnd)
{

//This code is a bit messy and inflexible but the GUI coding isn't really
the point here

//Variables for creating the status bar

INITCOMMONCONTROLSEX ControlSet;

RECT rcClient;

ControlSet.dwSize = sizeof (ControlSet);
ControlSet.dwICC = ICC_BAR_CLASSES;

InitCommonControlsEx(&ControlSet);

GetClientRect(hWnd, &rcClient);

int parts[2] = {rcClient.right / 2, rcClient.right};

//Create the status bar

hWstatusbar = CreateWindowEx(
0,
STATUSCLASSNAME,
(LPCTSTR) NULL,
WS_CHILD | WS_VISIBLE,
0,
0,
0,
0,
hWnd,
(HMENU) NULL,
(HINSTANCE) NULL, //This statement may break compatibility with Win9x (at
least according to MSDN)
NULL);

//Make sure status bar create was successful and if so, divide the status
window into 2 parts and set the message

if (!hWstatusbar){printf("Status bar create error: %d \n",
GetLastError());}

else
{

SendMessage(hWstatusbar,
SB_SETPARTS,
(WPARAM) 2,
(LPARAM) parts);
SendMessage(hWstatusbar,
WM_SETTEXT,
(WPARAM) 1,
(LPARAM) "Ready!");

}

//Set the icon for the main diolog.

SendMessage(hWnd,
WM_SETICON,
ICON_SMALL,
(LPARAM) LoadImage(NULL,
"C:\\Documents and Settings\\zyx987.ZYX987S-COMP\\My
Documents\\icon.ico",
IMAGE_ICON,
16,
16,
LR_LOADFROMFILE)
);

return;

}


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-24-2003
"Xzyx987X" <> wrote...
> Sorry if this is off topic for this group, but I couln't find any place
> better for directing question on Windows API programming. [...]


How about comp.os.ms-windows.programmer?


 
Reply With Quote
 
 
 
 
Xzyx987X
Guest
Posts: n/a
 
      07-24-2003
Ok thanks for your help. I'll repost this there.
"Victor Bazarov" <> wrote in message
news:IGGTa.132639$H17.44552@sccrnsc02...
> "Xzyx987X" <> wrote...
> > Sorry if this is off topic for this group, but I couln't find any place
> > better for directing question on Windows API programming. [...]

>
> How about comp.os.ms-windows.programmer?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments
 



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